nsPrefBranch should unregister itself as observer when shutting down

RESOLVED FIXED in Firefox 67

Status

()

enhancement
RESOLVED FIXED
3 months ago
3 months ago

People

(Reporter: baku, Assigned: baku)

Tracking

Trunk
mozilla67
Points:
---

Firefox Tracking Flags

(firefox67 fixed)

Details

Attachments

(2 attachments)

Assignee

Description

3 months ago

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.

Comment 3

3 months ago
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

Comment 4

3 months ago
bugherder
Status: NEW → RESOLVED
Last Resolved: 3 months 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.