From fb5aa4660be229a2add8430b367cdb8f05cb1304 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:40:34 -0500 Subject: [PATCH] chore: avoid crash while notification removal (#43059) * avoid crash of operation on an invalid entry while erase set iterator. Co-authored-by: bill.shen * fix notification removal crash due to the nullptr presenter Co-authored-by: bill.shen --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: bill.shen --- shell/browser/notifications/notification.cc | 4 +++- shell/browser/notifications/notification_presenter.cc | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/shell/browser/notifications/notification.cc b/shell/browser/notifications/notification.cc index 40b5f846fda0..9dae5fc56b52 100644 --- a/shell/browser/notifications/notification.cc +++ b/shell/browser/notifications/notification.cc @@ -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 diff --git a/shell/browser/notifications/notification_presenter.cc b/shell/browser/notifications/notification_presenter.cc index 4aef716a72a8..0bfb5c049c60 100644 --- a/shell/browser/notifications/notification_presenter.cc +++ b/shell/browser/notifications/notification_presenter.cc @@ -27,6 +27,11 @@ base::WeakPtr NotificationPresenter::CreateNotification( } void NotificationPresenter::RemoveNotification(Notification* notification) { + auto it = notifications_.find(notification); + if (it == notifications_.end()) { + return; + } + notifications_.erase(notification); delete notification; }