Bug 1177887 - Deref *after* changing the value held by RefPtr. - r=waldo
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 16 Jul 2015 17:15:44 -0700
changeset 286730 27c84bc564e9049e6219a66de001360082c4cf54
parent 286729 c281b91bf5f854499806f45c38ca03b6baf126e8
child 286731 f266de469f27eee5f1307e676b9a59e6b64c3238
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1177887
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1177887 - Deref *after* changing the value held by RefPtr. - r=waldo
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -280,18 +280,19 @@ public:
   T* get() const { return mPtr; }
   operator T*() const { return mPtr; }
   T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN { return mPtr; }
   T& operator*() const { return *mPtr; }
 
 private:
   void assign(T* aVal)
   {
-    unref(mPtr);
+    T* tmp = mPtr;
     mPtr = aVal;
+    unref(tmp);
   }
 
   T* MOZ_OWNING_REF mPtr;
 
   static MOZ_ALWAYS_INLINE T* ref(T* aVal)
   {
     if (aVal) {
       aVal->AddRef();