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

Unified Diff: chrome/browser/metrics/thread_watcher.cc

Issue 2296793003: ThreadWatcher: fix use-after-delete bug. (Closed)
Patch Set: Created 4 years, 4 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 | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/thread_watcher.cc
diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc
index 84a00ae4e45f32c74fe06ff11da31ca4f7e64500..b7215ae52e2862521a4affb475f9481770df1fb5 100644
--- a/chrome/browser/metrics/thread_watcher.cc
+++ b/chrome/browser/metrics/thread_watcher.cc
@@ -886,25 +886,30 @@ void StartupTimeBomb::Arm(const base::TimeDelta& duration) {
void StartupTimeBomb::Disarm() {
DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
if (startup_watchdog_) {
- startup_watchdog_->Disarm();
- startup_watchdog_->Cleanup();
- DeleteStartupWatchdog();
+ base::Watchdog* startup_watchdog = startup_watchdog_;
+ startup_watchdog_ = nullptr;
+
+ startup_watchdog->Disarm();
+ startup_watchdog->Cleanup();
+ DeleteStartupWatchdog(thread_id_, startup_watchdog);
}
}
-void StartupTimeBomb::DeleteStartupWatchdog() {
- DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
- if (startup_watchdog_->IsJoinable()) {
+// static
+void StartupTimeBomb::DeleteStartupWatchdog(
+ const base::PlatformThreadId thread_id,
wzhong 2016/08/30 23:08:39 Nit: const is not needed.
+ base::Watchdog* startup_watchdog) {
+ DCHECK_EQ(thread_id, base::PlatformThread::CurrentId());
+ if (startup_watchdog->IsJoinable()) {
// Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns
// very fast.
base::ThreadRestrictions::ScopedAllowIO allow_io;
- delete startup_watchdog_;
- startup_watchdog_ = nullptr;
+ delete startup_watchdog;
return;
}
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, base::Bind(&StartupTimeBomb::DeleteStartupWatchdog,
- base::Unretained(this)),
+ FROM_HERE, base::Bind(&StartupTimeBomb::DeleteStartupWatchdog, thread_id,
+ base::Unretained(startup_watchdog)),
base::TimeDelta::FromSeconds(10));
}
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698