Skip to content
Snippets Groups Projects
Commit f4f76205 authored by Hans Boehm's avatar Hans Boehm
Browse files

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
parent 6a581b7b
No related branches found
No related tags found
No related merge requests found
...@@ -228,8 +228,10 @@ void sp<T>::force_set(T* other) { ...@@ -228,8 +228,10 @@ void sp<T>::force_set(T* other) {
template<typename T> template<typename T>
void sp<T>::clear() { void sp<T>::clear() {
if (m_ptr) { T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
m_ptr->decStrong(this); if (oldPtr) {
oldPtr->decStrong(this);
if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
m_ptr = nullptr; m_ptr = nullptr;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment