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

Unified Diff: components/copresence/timed_map.h

Issue 453203002: Fixing memory leak in TimedMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
Index: components/copresence/timed_map.h
diff --git a/components/copresence/timed_map.h b/components/copresence/timed_map.h
index 909775201ce7c5e4619cda89ab3dd02824efa8fe..e89afa1620d9205341ba3787d2261b2389d730bd 100644
--- a/components/copresence/timed_map.h
+++ b/components/copresence/timed_map.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_COPRESENCE_TIMED_MAP_
-#define COMPONENTS_COPRESENCE_TIMED_MAP_
+#ifndef COMPONENTS_COPRESENCE_TIMED_MAP_H_
+#define COMPONENTS_COPRESENCE_TIMED_MAP_H_
#include <map>
#include <queue>
@@ -31,7 +31,9 @@ class TimedMap {
timer_.Start(FROM_HERE, lifetime_, this, &TimedMap::ClearExpiredTokens);
}
- ~TimedMap() {}
+ ~TimedMap() {
+ delete clock_;
rkc 2014/08/09 06:41:42 No reason for this clock to not be a scoped_ptr. L
Charlie 2014/08/09 07:10:40 Done.
+ }
void Add(const KeyType& key, const ValueType& value) {
map_[key] = value;
@@ -51,7 +53,12 @@ class TimedMap {
return elt == map_.end() ? kEmptyValue : elt->second;
}
- void set_clock_for_testing(base::TickClock* clock) { clock_ = clock; }
+ // TimedMap takes ownership of this clock.
+ void set_clock_for_testing(base::TickClock* clock) {
rkc 2014/08/09 06:41:41 Change the clock to a scoped_ptr, pass in a scoped
Charlie 2014/08/09 06:48:23 That's what I wrote first. But then how do you cal
rkc 2014/08/09 06:53:57 Retain a bare pointer in the test. It is the clean
Charlie 2014/08/09 07:10:40 Done.
+ DCHECK(clock);
+ delete clock_;
+ clock_ = clock;
+ }
private:
void ClearExpiredTokens() {
@@ -94,4 +101,4 @@ class TimedMap {
} // namespace copresence
-#endif // COMPONENTS_COPRESENCE_TIMED_MAP_
+#endif // COMPONENTS_COPRESENCE_TIMED_MAP_H_
« no previous file with comments | « components/copresence/handlers/audio/audio_directive_list_unittest.cc ('k') | components/copresence/timed_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698