Closed Bug 1532636 Opened 1 year ago Closed 1 year ago

nsPrefBranch should unregister itself as observer when shutting down

Categories

(Core :: Preferences: Backend, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla67
Tracking Status
firefox67 --- fixed

People

(Reporter: baku, Assigned: baku)

Details

Attachments

(2 files)

nsPrefBranch unregisters itself as observer in the DTOR:

https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/modules/libpref/Preferences.cpp#2068-2076

But this could be too late in case the nsObserverService has been already in the shutting down phase. Here is why:

  1. nsObserverService is released on shutdown because of this:
    https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/xpcom/build/XPCOMInit.cpp#685-688

  2. nsPermissionManager is released by ClearOnShutdown, and that happens here:
    https://searchfox.org/mozilla-central/source/xpcom/build/XPCOMInit.cpp#691-695

  3. releasing nsPermissionManager we release nsPrefBranch which calls nsObserverService in its dtor. Here is the crash: https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/xpcom/ds/nsObserverService.cpp#177-181

The correct fix is to remove the observer when xpcom-shutdown is notified.
At the same time, nsObserverService should be less aggressive and allow the removeObserver() when mShuttingDown is set to true.

Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/35f5d2d519eb
nsPrefBranch should unregister itself as observer when shutting down, r=gsvelto
https://hg.mozilla.org/integration/autoland/rev/8c835f11c111
nsObserverService should allow RemoveObserver() to be called when shutting down, r=gsvelto
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
Assignee: nobody → amarchesini
You need to log in before you can comment on or make changes to this bug.