OSDN Git Service

libutils: Fix an improper const-cast in RefBase
[android-x86/frameworks-base.git] / libs / utils / RefBase.cpp
index 7de2633..2034486 100644 (file)
@@ -345,10 +345,6 @@ void RefBase::incStrong(const void* id) const
     const_cast<RefBase*>(this)->onFirstRef();
 }
 
-void RefBase::destroy() const {
-    delete this;
-}
-
 void RefBase::decStrong(const void* id) const
 {
     weakref_impl* const refs = mRefs;
@@ -361,7 +357,7 @@ void RefBase::decStrong(const void* id) const
     if (c == 1) {
         const_cast<RefBase*>(this)->onLastStrongRef(id);
         if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
-            destroy();
+            delete this;
         }
     }
     refs->decWeak(id);
@@ -419,8 +415,7 @@ void RefBase::weakref_type::decWeak(const void* id)
     
     if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
         if (impl->mStrong == INITIAL_STRONG_VALUE)
-            if (impl->mBase)
-                impl->mBase->destroy();
+            delete impl->mBase;
         else {
             // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
             delete impl;
@@ -428,8 +423,7 @@ void RefBase::weakref_type::decWeak(const void* id)
     } else {
         impl->mBase->onLastWeakRef(id);
         if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
-            if (impl->mBase)
-                impl->mBase->destroy();
+            delete impl->mBase;
         }
     }
 }
@@ -530,7 +524,7 @@ void RefBase::weakref_type::printRefs() const
 
 void RefBase::weakref_type::trackMe(bool enable, bool retain)
 {
-    static_cast<const weakref_impl*>(this)->trackMe(enable, retain);
+    static_cast<weakref_impl*>(this)->trackMe(enable, retain);
 }
 
 RefBase::weakref_type* RefBase::createWeak(const void* id) const