Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1471)

Unified Diff: device/sensors/data_fetcher_shared_memory_base.cc

Issue 2743493003: [Device Sensors] Fix crash on shutdown (Closed)
Patch Set: Fix unittest Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | device/sensors/data_fetcher_shared_memory_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/sensors/data_fetcher_shared_memory_base.cc
diff --git a/device/sensors/data_fetcher_shared_memory_base.cc b/device/sensors/data_fetcher_shared_memory_base.cc
index 21a72f1f0977a8f9e4c7278e1ea5b8f74eb96f4c..160bddb15dc131d9358e64472400de22f2db26bd 100644
--- a/device/sensors/data_fetcher_shared_memory_base.cc
+++ b/device/sensors/data_fetcher_shared_memory_base.cc
@@ -112,9 +112,10 @@ DataFetcherSharedMemoryBase::DataFetcherSharedMemoryBase()
DataFetcherSharedMemoryBase::~DataFetcherSharedMemoryBase() {
DCHECK_EQ(0u, started_consumers_);
- // make sure polling thread stops asap.
- if (polling_thread_)
- polling_thread_->Stop();
+ // By this point the polling thread should have already been stopped (it's not
+ // safe for it to be running in this class's destructor as tasks are posted to
+ // it that call virtual methods of this class).
+ DCHECK(!polling_thread_ || !polling_thread_->IsRunning());
}
bool DataFetcherSharedMemoryBase::StartFetchingDeviceData(
@@ -174,6 +175,13 @@ void DataFetcherSharedMemoryBase::Shutdown() {
StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION);
StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION_ABSOLUTE);
StopFetchingDeviceData(CONSUMER_TYPE_LIGHT);
+
+ // Ensure that the polling thread stops before entering the destructor of the
+ // subclass, as the stopping of the polling thread causes tasks to execute
+ // that call virtual methods of this class, which can cause crashes if they
+ // execute while (or after) the subclass is being torn down.
+ if (polling_thread_)
+ polling_thread_->Stop();
}
mojo::ScopedSharedBufferHandle
« no previous file with comments | « no previous file | device/sensors/data_fetcher_shared_memory_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698