From 9ebeeb40ac1a9091165a9ecd63db44b4162467d5 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:09:59 +0100 Subject: [PATCH] fix: don't do self-destroy in LibnotifyNotification::Dismiss() (#41708) Callers of Notification::Dismiss() assume that the notification instance is not deleted after the call, but this was not the case for LibnotifyNotification: - Destroy() would get `this` deleted. - notify_notification_close() in portal environment triggers LibnotifyNotification::OnNotificationClosed(), and finally calls Destroy() This patch removes all Destroy() in Dismiss(), and adds a boolean to tell whether notify_notification_close() is running, to avoid crash under portal environment. Fixes #40461. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: taoky --- shell/browser/notifications/linux/libnotify_notification.cc | 6 +++--- shell/browser/notifications/linux/libnotify_notification.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/browser/notifications/linux/libnotify_notification.cc b/shell/browser/notifications/linux/libnotify_notification.cc index e039b382e3e2..4c8452fad1a8 100644 --- a/shell/browser/notifications/linux/libnotify_notification.cc +++ b/shell/browser/notifications/linux/libnotify_notification.cc @@ -159,21 +159,21 @@ void LibnotifyNotification::Show(const NotificationOptions& options) { void LibnotifyNotification::Dismiss() { if (!notification_) { - Destroy(); return; } GError* error = nullptr; + on_dismissing_ = true; libnotify_loader_.notify_notification_close(notification_, &error); if (error) { log_and_clear_error(error, "notify_notification_close"); - Destroy(); } + on_dismissing_ = false; } void LibnotifyNotification::OnNotificationClosed( NotifyNotification* notification) { - NotificationDismissed(); + NotificationDismissed(!on_dismissing_); } void LibnotifyNotification::OnNotificationView(NotifyNotification* notification, diff --git a/shell/browser/notifications/linux/libnotify_notification.h b/shell/browser/notifications/linux/libnotify_notification.h index 8aacd0952062..315419fc5c73 100644 --- a/shell/browser/notifications/linux/libnotify_notification.h +++ b/shell/browser/notifications/linux/libnotify_notification.h @@ -33,6 +33,7 @@ class LibnotifyNotification : public Notification { RAW_PTR_EXCLUSION NotifyNotification* notification_ = nullptr; ScopedGSignal signal_; + bool on_dismissing_ = false; }; } // namespace electron