From d086fe51092b6302cf2fc5a460e63393726468e5 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 26 Jul 2022 22:11:13 +0000 Subject: [PATCH] libutils: disallow extending lifetime on stack Bug: 232557259 Test: libutils_test Change-Id: Iacf45b9f295a48904606ced35994ba35566bfcc3 --- libutils/RefBase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index 79c57434f..12c2c29e8 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -791,6 +791,8 @@ RefBase::~RefBase() 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);