Use MakeAndAddRef instead of new when allocating arg for nsContentUtils::AddScriptRunner
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
| 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).
| Assignee | ||
Comment 1•3 days ago
|
||
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).
Updated•3 days ago
|
Comment 3•3 days ago
|
||
| bugherder | ||
Description
•