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

Side by Side Diff: chrome/browser/metrics/thread_watcher.cc

Issue 2295983002: Fix memory leak in ThreadWatcher. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/thread_watcher.h" 5 #include "chrome/browser/metrics/thread_watcher.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); 79 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
80 80
81 // Create a new thread watcher object for the given thread and activate it. 81 // Create a new thread watcher object for the given thread and activate it.
82 ThreadWatcher* watcher = new ThreadWatcher(params); 82 ThreadWatcher* watcher = new ThreadWatcher(params);
83 83
84 DCHECK(watcher); 84 DCHECK(watcher);
85 // If we couldn't register the thread watcher object, we are shutting down, 85 // If we couldn't register the thread watcher object, we are shutting down,
86 // then don't activate thread watching. 86 // then don't activate thread watching.
87 if (!ThreadWatcherList::IsRegistered(params.thread_id)) 87 if (!ThreadWatcherList::IsRegistered(params.thread_id)) {
88 delete watcher;
Ilya Sherman 2016/08/30 23:51:57 Could you instead modify |watcher| to be a unique_
88 return; 89 return;
90 }
89 watcher->ActivateThreadWatching(); 91 watcher->ActivateThreadWatching();
alokp 2016/08/30 22:32:34 Is this leaked?
ramant (doing other things) 2016/08/30 22:45:12 watcher is stored in g_thread_watcher_list_. It is
alokp 2016/08/30 22:47:21 Thanks for the explanation. I think a comment abou
90 } 92 }
91 93
92 void ThreadWatcher::ActivateThreadWatching() { 94 void ThreadWatcher::ActivateThreadWatching() {
93 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); 95 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
94 if (active_) return; 96 if (active_) return;
95 active_ = true; 97 active_ = true;
96 ping_count_ = unresponsive_threshold_; 98 ping_count_ = unresponsive_threshold_;
97 ResetHangCounters(); 99 ResetHangCounters();
98 base::ThreadTaskRunnerHandle::Get()->PostTask( 100 base::ThreadTaskRunnerHandle::Get()->PostTask(
99 FROM_HERE, base::Bind(&ThreadWatcher::PostPingMessage, 101 FROM_HERE, base::Bind(&ThreadWatcher::PostPingMessage,
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 1001
1000 #if defined(OS_WIN) 1002 #if defined(OS_WIN)
1001 // On Windows XP, give twice the time for shutdown. 1003 // On Windows XP, give twice the time for shutdown.
1002 if (base::win::GetVersion() <= base::win::VERSION_XP) 1004 if (base::win::GetVersion() <= base::win::VERSION_XP)
1003 actual_duration *= 2; 1005 actual_duration *= 2;
1004 #endif 1006 #endif
1005 1007
1006 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); 1008 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration);
1007 shutdown_watchdog_->Arm(); 1009 shutdown_watchdog_->Arm();
1008 } 1010 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698