Closed
Bug 663425
Opened 14 years ago
Closed 11 years ago
Forbid using already_AddRefed<T>.get()
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 967364
People
(Reporter: jdm, Unassigned)
References
Details
It's very easy to cause leaks if you call a function that returns an already_AddRefed<T> and just do something with the raw pointer value instead of storing the result in a smart pointer. There are very few times, if any, that this is actually necessary, so we should forbid it completely.
Msg2ger points out that |*aOutParamToASuperClass = it.forget().get()| uses this in a valid way. I'd like to make the alternative |it.forget(aOutParamToASuperClass)| work instead.
Comment 1•14 years ago
|
||
> There are very few times, if any, that this is actually necessary,
Except when dealing with members that can't be made nsCOMPtr due to include hell, right?
Reporter | ||
Comment 2•14 years ago
|
||
Can you elaborate on that?
Comment 3•14 years ago
|
||
A class with inline ctor/dtor that uses an nsIFoo* member can't make it nsCOMPtr<nsIFoo> without including nsIFoo.h in the class header. And in many cases that leads to us failing to compile due to include hell because nsIFoo.h includes stuff that things that include the header including nsIFoo.h can't or don't include.
As a result, we have several places where we use raw nsIFoo* and manual refcounting to work around that whole mess... And assigning to such a member from an already_AddRefed would become ... more difficult with this change (could still be done via an nsCOMPtr intermediary).
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•