Skip to content

Commit

Permalink
chore: avoid crash while notification removal (#43061)
Browse files Browse the repository at this point in the history
* avoid crash of operation on an invalid entry while erase set iterator.

Co-authored-by: bill.shen <[email protected]>

* fix notification removal crash due to the nullptr presenter

Co-authored-by: bill.shen <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: bill.shen <[email protected]>
  • Loading branch information
trop[bot] and cucbin committed Jul 26, 2024
1 parent 871136b commit b6e19c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shell/browser/notifications/notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void Notification::NotificationFailed(const std::string& error) {
void Notification::Remove() {}

void Notification::Destroy() {
presenter()->RemoveNotification(this);
if (presenter()) {
presenter()->RemoveNotification(this);
}
}

} // namespace electron
5 changes: 5 additions & 0 deletions shell/browser/notifications/notification_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ base::WeakPtr<Notification> NotificationPresenter::CreateNotification(
}

void NotificationPresenter::RemoveNotification(Notification* notification) {
auto it = notifications_.find(notification);
if (it == notifications_.end()) {
return;
}

notifications_.erase(notification);
delete notification;
}
Expand Down

0 comments on commit b6e19c5

Please sign in to comment.