libutils: disallow extending lifetime on stack
Bug: 232557259
Test: libutils_test
Change-Id: Iacf45b9f295a48904606ced35994ba35566bfcc3
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index 79c5743..12c2c29 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -791,6 +791,8 @@
void RefBase::extendObjectLifetime(int32_t mode)
{
+ check_not_on_stack(this);
+
// Must be happens-before ordered with respect to construction or any
// operation that could destroy the object.
mRefs->mFlags.fetch_or(mode, std::memory_order_relaxed);