summaryrefslogtreecommitdiffstats
path: root/include/utils/RefBase.h
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2011-08-10 21:07:02 -0700
committerMathias Agopian <mathias@google.com>2011-08-11 22:33:02 -0700
commitcbe527884acf0f8f8c550c54f99b4dd864ac1e70 (patch)
tree1843deb50499d11ac8999210a4476cf322dd9a96 /include/utils/RefBase.h
parent47d0812977b7acc4fed6a823203770a57f7a6b78 (diff)
downloadframeworks_native-cbe527884acf0f8f8c550c54f99b4dd864ac1e70.zip
frameworks_native-cbe527884acf0f8f8c550c54f99b4dd864ac1e70.tar.gz
frameworks_native-cbe527884acf0f8f8c550c54f99b4dd864ac1e70.tar.bz2
fix a memory leak and memory corruption in RefBase
we would leak a weakref_impl if a RefBase was never incWeak()'ed. there was also a dangling pointer that would cause memory corruption and double-delete when a custom destroyer was used to delay the execution of ~RefBase. it turns out that the custom destroyer feature caused most of the problems, so it's now gone. The only client was SurfaceFlinger who now handles things on its own. RefBase is essentially back its "gingerbread" state, but the code was slightly cleaned-up. Bug: 5151207, 5084978 Change-Id: Id6ef1d707f96d96366f75068f77b30e0ce2722a5
Diffstat (limited to 'include/utils/RefBase.h')
-rw-r--r--include/utils/RefBase.h24
1 files changed, 7 insertions, 17 deletions
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index ca17082..c7a9b78 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -80,9 +80,12 @@ public:
void incWeak(const void* id);
void decWeak(const void* id);
+ // acquires a strong reference if there is already one.
bool attemptIncStrong(const void* id);
- //! This is only safe if you have set OBJECT_LIFETIME_FOREVER.
+ // acquires a weak reference if there is already one.
+ // This is not always safe. see ProcessState.cpp and BpBinder.cpp
+ // for proper use.
bool attemptIncWeak(const void* id);
//! DEBUGGING ONLY: Get current weak ref count.
@@ -116,28 +119,15 @@ public:
typedef RefBase basetype;
- // used to override the RefBase destruction.
- class Destroyer {
- friend class RefBase;
- friend class weakref_type;
- public:
- virtual ~Destroyer();
- private:
- virtual void destroy(RefBase const* base) = 0;
- };
-
- // Make sure to never acquire a strong reference from this function. The
- // same restrictions than for destructors apply.
- void setDestroyer(Destroyer* destroyer);
-
protected:
RefBase();
virtual ~RefBase();
//! Flags for extendObjectLifetime()
enum {
+ OBJECT_LIFETIME_STRONG = 0x0000,
OBJECT_LIFETIME_WEAK = 0x0001,
- OBJECT_LIFETIME_FOREVER = 0x0003
+ OBJECT_LIFETIME_MASK = 0x0001
};
void extendObjectLifetime(int32_t mode);
@@ -163,7 +153,7 @@ private:
RefBase(const RefBase& o);
RefBase& operator=(const RefBase& o);
-
+
weakref_impl* const mRefs;
};