Bug 1157848 - Fix leak in OwningNonNull constructor from already_AddRefed; r=bz
authorAryeh Gregor <ayg@aryeh.name>
Fri, 24 Apr 2015 14:27:34 +0300
changeset 259335 889f95f88740618239b8d4c83de090b8a69656e8
parent 259334 8c56a1c8e458cd175784a940d85ae368ac82c2df
child 259336 b927da3c4832c1efc0b2a372081199889c1ddc7d
push id1728
push usermartin.thomson@gmail.com
push dateFri, 24 Apr 2015 18:56:35 +0000
reviewersbz
bugs1157848
milestone40.0a1
Bug 1157848 - Fix leak in OwningNonNull constructor from already_AddRefed; r=bz
dom/bindings/OwningNonNull.h
--- a/dom/bindings/OwningNonNull.h
+++ b/dom/bindings/OwningNonNull.h
@@ -24,17 +24,17 @@ public:
   MOZ_IMPLICIT OwningNonNull(T& aValue)
   {
     init(&aValue);
   }
 
   template<class U>
   MOZ_IMPLICIT OwningNonNull(already_AddRefed<U>&& aValue)
   {
-    init(aValue.take());
+    init(aValue);
   }
 
   // This is no worse than get() in terms of const handling.
   operator T&() const
   {
     MOZ_ASSERT(mInited);
     MOZ_ASSERT(mPtr, "OwningNonNull<T> was set to null");
     return *mPtr;
@@ -101,17 +101,17 @@ public:
   template<typename U>
   void swap(U& aOther)
   {
     mPtr.swap(aOther);
   }
 
 protected:
   template<typename U>
-  void init(U aValue)
+  void init(U&& aValue)
   {
     mPtr = aValue;
     MOZ_ASSERT(mPtr);
 #ifdef DEBUG
     mInited = true;
 #endif
   }