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

Side by Side Diff: net/disk_cache/blockfile/rankings.cc

Issue 583293002: Do not leak when iterator outlives disk cache backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cacheenums-again
Patch Set: cleaner ownership Created 6 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
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 "net/disk_cache/blockfile/rankings.h" 5 #include "net/disk_cache/blockfile/rankings.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "net/disk_cache/blockfile/backend_impl.h" 8 #include "net/disk_cache/blockfile/backend_impl.h"
9 #include "net/disk_cache/blockfile/disk_format.h" 9 #include "net/disk_cache/blockfile/disk_format.h"
10 #include "net/disk_cache/blockfile/entry_impl.h" 10 #include "net/disk_cache/blockfile/entry_impl.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {} 196 Rankings::ScopedRankingsBlock::ScopedRankingsBlock() : rankings_(NULL) {}
197 197
198 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings) 198 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(Rankings* rankings)
199 : rankings_(rankings) {} 199 : rankings_(rankings) {}
200 200
201 Rankings::ScopedRankingsBlock::ScopedRankingsBlock( 201 Rankings::ScopedRankingsBlock::ScopedRankingsBlock(
202 Rankings* rankings, CacheRankingsBlock* node) 202 Rankings* rankings, CacheRankingsBlock* node)
203 : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {} 203 : scoped_ptr<CacheRankingsBlock>(node), rankings_(rankings) {}
204 204
205 Rankings::Iterator::Iterator(Rankings* rankings) { 205 Rankings::Iterator::Iterator() {
206 memset(this, 0, sizeof(Iterator)); 206 memset(this, 0, sizeof(Iterator));
207 my_rankings = rankings;
208 } 207 }
209 208
210 Rankings::Iterator::~Iterator() { 209 void Rankings::Iterator::Reset() {
211 for (int i = 0; i < 3; i++) 210 if (my_rankings) {
212 ScopedRankingsBlock(my_rankings, nodes[i]); 211 for (int i = 0; i < 3; i++)
212 ScopedRankingsBlock(my_rankings, nodes[i]);
213 }
214 memset(this, 0, sizeof(Iterator));
213 } 215 }
214 216
215 Rankings::Rankings() : init_(false) {} 217 Rankings::Rankings() : init_(false) {}
216 218
217 Rankings::~Rankings() {} 219 Rankings::~Rankings() {}
218 220
219 bool Rankings::Init(BackendImpl* backend, bool count_lists) { 221 bool Rankings::Init(BackendImpl* backend, bool count_lists) {
220 DCHECK(!init_); 222 DCHECK(!init_);
221 if (init_) 223 if (init_)
222 return false; 224 return false;
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 void Rankings::DecrementCounter(List list) { 918 void Rankings::DecrementCounter(List list) {
917 if (!count_lists_) 919 if (!count_lists_)
918 return; 920 return;
919 921
920 DCHECK(control_data_->sizes[list] > 0); 922 DCHECK(control_data_->sizes[list] > 0);
921 if (control_data_->sizes[list] > 0) 923 if (control_data_->sizes[list] > 0)
922 control_data_->sizes[list]--; 924 control_data_->sizes[list]--;
923 } 925 }
924 926
925 } // namespace disk_cache 927 } // namespace disk_cache
OLDNEW
« net/disk_cache/blockfile/backend_impl.cc ('K') | « net/disk_cache/blockfile/rankings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698