Open Bug 1142831 Opened 5 years ago Updated 2 years ago

Many potential leaks if |NS_DispatchToMain| fails

Categories

(Core :: XPCOM, defect)

x86_64
Linux
defect
Not set

Tracking

()

People

(Reporter: erahm, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: [MemShrink:P2][CID 1286725][CID 1285940][CID 1285967][CID 1285977][CID 1286098][CID 1286118][CID 1286131][CID 1286158][CID 1286193][CID 1286214][CID 1286251][CID 1286254][CID 1286283][CID 1286288][CID 1286326][CID 1286392][CID 1286465][CID 1286484][CID 12…)

Coverity indicates there are 72 potential leaks in calls to |NS_DispatchToMainThread|. A quick grep of the codebase indicates there are probably at least 158.

Previously |NS_DispatchToCurrentThread| was fixed to use a deathGrip on the passed in runnable, but |NS_DispatchToMainThread| was left as-is, due to:

> // In the case of failure with a newly allocated runnable with a
> // refcount of zero, we intentionally leak the runnable, because it is
> // likely that the runnable is being dispatched to the main thread
> // because it owns main thread only objects, so it is not safe to
> // release them here.

AFAICT the majority of code does not behave in this way, but a more thorough survey should be performed. Most often the runnable passed in is a simple struct that calls a function in the main thread context.

Possible options:
- Add a deathGrip to |NS_DispatchToMainThread|
- Update all callers to hold an nsComPtr/nsRefPtr to the passed in runnable
- Do something to make coverity ignore this function
See Also: → 1142799
Whiteboard: [MemShrink][CID 1286725][CID 1285940][CID 1285967][CID 1285977][CID 1286098][CID 1286118][CID 1286131][CID 1286158][CID 1286193][CID 1286214][CID 1286251][CID 1286254][CID 1286283][CID 1286288][CID 1286326][CID 1286392][CID 1286465][CID 1286484][CID → [MemShrink:P2][CID 1286725][CID 1285940][CID 1285967][CID 1285977][CID 1286098][CID 1286118][CID 1286131][CID 1286158][CID 1286193][CID 1286214][CID 1286251][CID 1286254][CID 1286283][CID 1286288][CID 1286326][CID 1286392][CID 1286465][CID 1286484][CID
Everyone agreed making NS_DispatchToMain infallible is the best path forward here.
Whiteboard: 1286343][CID 1286503][CID 1286514][CID 1286527][CID 1286604][CID 1286635][CID 1286645][CID 1286671][CID 1286674][CID 1286716][CID 1286767][CID 1286582][CID 1286080][CID 1286255][CID 1286545][CID 1286636] → 1286343][CID 1286503][CID 1286514][CID 1286527][CID 1286604][CID 1286635][CID 1286645][CID 1286671][CID 1286674][CID 1286716][CID 1286767][CID 1286582][CID 1286080][CID 1286255][CID 1286545][CID 1286636][CID 1296138][CID 1296137][CID 1294772][CID 1294771…
Whiteboard: 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316] → 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316][CID 1297908][CID 1297907]
Whiteboard: 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316][CID 1297908][CID 1297907] → 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316][CID 1297908][CID 1297907][CID 1299534][CID 1299533][CID 1299532][CID 1299531]
Depends on: 1142799
Whiteboard: 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316][CID 1297908][CID 1297907][CID 1299534][CID 1299533][CID 1299532][CID 1299531] → 1294771][CID 1294770][CID 1293114][CID 1293111][CID 1293110][CID 1287316][CID 1297908][CID 1297907][CID 1299534][CID 1299533][CID 1299532][CID 1299531][CIDD 1287316][CID 1297908][CID 1297907][CID 1299534][CID 1299533][CID 1299532][CID 1299531][CID 130838…
Whiteboard: 1308388][CID 1308386][CID1307881][CID1307880][CID 1307879][CID 1304701] → 1308388][CID 1308386][CID1307881][CID1307880][CID 1307879][CID 1304701][CID 1309916][CID 1309906]
You need to log in before you can comment on or make changes to this bug.