Skip to content

Commit

Permalink
fix: don't do self-destroy in LibnotifyNotification::Dismiss()
Browse files Browse the repository at this point in the history
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: taoky <me@taoky.moe>
  • Loading branch information
trop[bot] and taoky committed Mar 27, 2024
1 parent 3b025ec commit d090851
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions shell/browser/notifications/linux/libnotify_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions shell/browser/notifications/linux/libnotify_notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LibnotifyNotification : public Notification {
RAW_PTR_EXCLUSION NotifyNotification* notification_ = nullptr;

ScopedGSignal signal_;
bool on_dismissing_ = false;
};

} // namespace electron
Expand Down

0 comments on commit d090851

Please sign in to comment.