Closed Bug 2037754 Opened 3 days ago Closed 3 days ago

Use MakeAndAddRef instead of new when allocating arg for nsContentUtils::AddScriptRunner

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

nsContentUtils::AddScriptRunner has a version that takes a raw pointer to a refcounted object, but this is a bit dangerous to use, because (as far as the caller knows) nsContentUtils::AddScriptRunner might not take ownership of the refcounted object, causing it to be leaked; or, it might call a function that takes temporary ownership (by instantiating a temporary RefPtr) which would delete the object out from under nsContentUtils::AddScriptRunner

Let's avoid this potential problem (and reduce our audit surface for manual new allocation) by changing callsites to use MakeAndAddRef, which then makes them call the variant that takes already_AddRefed<nsIRunnable> (where the compiler gives us guarantees that the object will be properly claimed).

MakeAndAddRef ensures that the freshly-allocated object immediately gets a
refcount of 1, and it also makes the ownership-transfer semantics more clear
(via the already_AddRefed type).

Assignee: nobody → dholbert
Attachment #9584003 - Attachment description: WIP: Bug 2037754: Use MakeAndAddRef instead of new when allocating arg for nsContentUtils::AddScriptRunner. r?#dom-core → Bug 2037754: Use 'MakeAndAddRef' instead of 'new' when allocating runnable for nsContentUtils::AddScriptRunner. r?#dom-core
Status: NEW → ASSIGNED
Blocks: 1270687
Pushed by dholbert@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/10725540f638 https://hg.mozilla.org/integration/autoland/rev/21c1da0d83c2 Use 'MakeAndAddRef' instead of 'new' when allocating runnable for nsContentUtils::AddScriptRunner. r=dom-core,smaug
Status: ASSIGNED → RESOLVED
Closed: 3 days ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: