From f4f76205fef6df93b2a0c3334fd88d2233bb2b26 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Fri, 17 Aug 2018 11:40:39 -0700 Subject: [PATCH] Check sp<>::clear() for data races sp<>::clear() presents the same risks of heap corruption in the presence of data races as does assignment. Add the same data race check. Bug: 112651574 Test: Build and boot AOSP Change-Id: I75d4eedd756d521920e61ff9187509f9145d4235 --- libutils/include/utils/StrongPointer.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libutils/include/utils/StrongPointer.h b/libutils/include/utils/StrongPointer.h index 360fce509..3abce1705 100644 --- a/libutils/include/utils/StrongPointer.h +++ b/libutils/include/utils/StrongPointer.h @@ -228,8 +228,10 @@ void sp::force_set(T* other) { template void sp::clear() { - if (m_ptr) { - m_ptr->decStrong(this); + T* oldPtr(*const_cast(&m_ptr)); + if (oldPtr) { + oldPtr->decStrong(this); + if (oldPtr != *const_cast(&m_ptr)) sp_report_race(); m_ptr = nullptr; } }