Closed Bug 1679873 Opened 2 years ago Closed 2 years ago

Do not pass already_AddRefed<nsIFile> to IOUtils::RunOnBackgroundThread

Categories

(Toolkit :: OS.File, defect, P3)

defect

Tracking

()

RESOLVED FIXED
85 Branch
Tracking Status
firefox-esr78 --- unaffected
firefox83 --- unaffected
firefox84 --- wontfix
firefox85 --- fixed

People

(Reporter: barret, Assigned: barret)

Details

Attachments

(1 file)

IOUtils::RunOnBackgroundThread will exit early if we cannot get an event target (e.g., during shutdown) and will then cause a crash when we drop the already_AddRefed<nsIFile> during exit, we crash in debug builds (https://searchfox.org/mozilla-central/source/mfbt/AlreadyAddRefed.h#129). We should pass nsCOMPtr<nsIFile>&& instead which also elides the addref/release pair and will have the same perf characteristics.

Severity: -- → S3
Priority: -- → P3

Passing in a callable and its arguments to RunOnBackgroundThread was fine
before we started passing in already_AddRefed<nsIFile>. However, if we fail to
get an event target, then we drop all our arguments and in debug builds
already_AddRefed<T> asserts that it was moved out of.

Now we require callers of RunOnBackgroundThread to pass in a closure that
contains all the bindings they require, which has the added bonus of making
lifetimes more explicit. As part of this refactor, all the ReadSync etc
methods now take raw nsIFil* pointers since they are called in a scope that has
them refcounted.

Assignee: nobody → brennie
Status: NEW → ASSIGNED
Pushed by brennie@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6c71b9a049a3
Pass closures to IOUtils::RunOnBackgroundThread r=nika
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 85 Branch
You need to log in before you can comment on or make changes to this bug.