From: Mathias Agopian Date: Wed, 8 Jun 2011 23:05:30 +0000 (-0700) Subject: Fix a leak in RefBase (DO NOT MERGE) X-Git-Tag: android-x86-4.4-r1~4337^2~5 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9a03cecf8b63810ba3f451bd139d3b473cb67c81;p=android-x86%2Fframeworks-native.git Fix a leak in RefBase (DO NOT MERGE) this bug was introduced recently. it caused RefBase's weakref_impl structure to be leaked for every RefBase object (about 20 bytes). Change-Id: Ia9b155fbfa643ef72cfb8129e96260a3b806a78c --- diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp index c68e32a0df..1c870cf783 100644 --- a/libs/utils/RefBase.cpp +++ b/libs/utils/RefBase.cpp @@ -373,18 +373,20 @@ void RefBase::weakref_type::decWeak(const void* id) if (c != 1) return; if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) { - if (impl->mStrong == INITIAL_STRONG_VALUE) - if (impl->mBase) + if (impl->mStrong == INITIAL_STRONG_VALUE) { + if (impl->mBase) { impl->mBase->destroy(); - else { -// LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase); + } + } else { + // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase); delete impl; } } else { impl->mBase->onLastWeakRef(id); if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) { - if (impl->mBase) + if (impl->mBase) { impl->mBase->destroy(); + } } } } @@ -508,10 +510,10 @@ RefBase::RefBase() RefBase::~RefBase() { -// LOGV("Destroying RefBase %p (refs %p)\n", this, mRefs); - if (mRefs->mWeak == 0) { -// LOGV("Freeing refs %p of old RefBase %p\n", mRefs, this); - delete mRefs; + if ((mRefs->mFlags & OBJECT_LIFETIME_WEAK) == OBJECT_LIFETIME_WEAK) { + if (mRefs->mWeak == 0) { + delete mRefs; + } } }