Skip to content

Commit 4b9e458

Browse files
committedMar 24, 2025
Bug 1955912 - Return early when no backend exists r=jstutte
nsXULAlerts already has ClearOnShutdown and calling nsXULAlerts::GetInstance again only makes it immediately freed with nullptr being returned. Differential Revision: https://phabricator.services.mozilla.com/D242691
1 parent 6592428 commit 4b9e458

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎toolkit/components/alerts/nsAlertsService.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ NS_IMETHODIMP nsAlertsService::Teardown() {
253253
backend = mBackend;
254254
}
255255
if (!backend) {
256-
backend = nsXULAlerts::GetInstance();
256+
// We do not try nsXULAlerts here as it already uses ClearOnShutdown.
257+
return NS_OK;
257258
}
258259
return backend->Teardown();
259260
}

‎toolkit/components/alerts/nsXULAlerts.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "nsArray.h"
99
#include "nsComponentManagerUtils.h"
1010
#include "nsCOMPtr.h"
11+
#include "mozilla/AppShutdown.h"
1112
#include "mozilla/ClearOnShutdown.h"
1213
#include "mozilla/EventForwards.h"
1314
#include "mozilla/LookAndFeel.h"
@@ -65,7 +66,8 @@ NS_IMPL_ISUPPORTS(nsXULAlerts, nsIAlertsService, nsIAlertsDoNotDisturb)
6566
already_AddRefed<nsXULAlerts> nsXULAlerts::GetInstance() {
6667
// Gecko on Android does not fully support XUL windows.
6768
#ifndef MOZ_WIDGET_ANDROID
68-
if (!gXULAlerts) {
69+
if (!gXULAlerts &&
70+
!AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
6971
gXULAlerts = new nsXULAlerts();
7072
ClearOnShutdown(&gXULAlerts);
7173
}
@@ -380,10 +382,7 @@ nsXULAlerts::CloseAlert(const nsAString& aAlertName, bool aContextClosed) {
380382
return NS_OK;
381383
}
382384

383-
NS_IMETHODIMP nsXULAlerts::Teardown() {
384-
mPendingPersistentAlerts.Clear();
385-
return NS_OK;
386-
}
385+
NS_IMETHODIMP nsXULAlerts::Teardown() { return NS_OK; }
387386

388387
NS_IMETHODIMP nsXULAlerts::PbmTeardown() {
389388
// Usually XUL alerts close after a few seconds without being listed anywhere,

0 commit comments

Comments
 (0)
Failed to load comments.