On Mon, Dec 22, 2014 at 1:12 PM, Ehsan Akhgari <[email protected]> wrote:
> On 2014-12-22 4:10 PM, Jeff Muizelaar wrote: > >> We were talking about this problem and it was a bunch of work to figure >> out the conclusion so I decided to write a summary: >> >> Replacing already_AddRefed with nsRefPtr causes allows two new things: >> >> nsRefPtr<T> getT(); >> >> 1. T* p = getT(); // this is unsafe because the destructor runs >> immediately and p is left dangling >> 2. foo(getT()); // this is safe >> >> Possible solutions would be to: >> - remove implicit conversions to T* >> > > Perhaps we should consider doing this. +1 There are plenty of other ways to get in trouble with implicit conversion. E.g., nsRefPtr<T> t(new T()); delete t; However, in the interest of full disclosure, here's a Bugzilla thread where this was aired a while back without resolution: https://bugzilla.mozilla.org/show_bug.cgi?id=767178 -Ekr > > - add operator T* explicit and operator T* && = delete // this will be >> available in GCC 4.8.1 and MSVC 2014 Nov CTP >> >> -Jeff >> >> On Aug 14, 2014, at 10:21 AM, Ehsan Akhgari <[email protected]> >> wrote: >> >> On Thu, Aug 14, 2014 at 10:02 AM, Aryeh Gregor <[email protected]> wrote: >>> >>> On Thu, Aug 14, 2014 at 12:00 PM, Neil <[email protected]> wrote: >>>> >>>>> Well there's your problem: GetWSBoundingParent doesn't need to own the >>>>> >>>> nodes >>>> >>>>> it works on. >>>>> >>>> >>>> Editing code is ancient, poorly maintained, and not >>>> performance-sensitive, so personally, I don't ever use raw pointers as >>>> local variables in editor/. Better to not have to rely on manual >>>> review to prevent use-after-free bugs. I am aware of at least one >>>> sec-critical bug in editor that resulted from non-use of nsCOMPtr that >>>> slipped through review when someone was rewriting editing code. >>>> >>>> In this case, I seem to remember I wanted to change it to return a raw >>>> pointer instead of already_AddRefed, but IIRC, Ehsan said not to >>>> (although I can't find that anywhere, so maybe I made it up). >>>> >>>> >>> I don't remember either! >>> >>> -- >>> Ehsan >>> _______________________________________________ >>> dev-platform mailing list >>> [email protected] >>> https://lists.mozilla.org/listinfo/dev-platform >>> >> >> > _______________________________________________ > dev-platform mailing list > [email protected] > https://lists.mozilla.org/listinfo/dev-platform > _______________________________________________ dev-platform mailing list [email protected] https://lists.mozilla.org/listinfo/dev-platform

