Closed Bug 663425 Opened 10 years ago Closed 8 years ago
Forbid using already
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.
> 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?
Can you elaborate on that?
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: 8 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 967364
You need to log in before you can comment on or make changes to this bug.