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

Side by Side Diff: components/leveldb/leveldb_database_impl.cc

Issue 2722293002: Fix lifetime of leveldb::MojoEnv instances. (Closed)
Patch Set: annotate leaks Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/leveldb/leveldb_database_impl.h" 5 #include "components/leveldb/leveldb_database_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 16 matching lines...) Expand all
27 for (; it->Valid(); it->Next()) { 27 for (; it->Valid(); it->Next()) {
28 if (!it->key().starts_with(key_prefix)) 28 if (!it->key().starts_with(key_prefix))
29 break; 29 break;
30 function(it->key(), it->value()); 30 function(it->key(), it->value());
31 } 31 }
32 return it->status(); 32 return it->status();
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 LevelDBDatabaseImpl::LevelDBDatabaseImpl(std::unique_ptr<Env> owned_environment,
38 std::unique_ptr<DB> db)
39 : owned_environment_(std::move(owned_environment)), db_(std::move(db)) {}
40
37 LevelDBDatabaseImpl::LevelDBDatabaseImpl( 41 LevelDBDatabaseImpl::LevelDBDatabaseImpl(
38 std::unique_ptr<leveldb::Env> environment, 42 std::unique_ptr<MojoEnv::Directory> directory,
39 std::unique_ptr<leveldb::DB> db) 43 std::unique_ptr<leveldb::DB> db)
40 : environment_(std::move(environment)), db_(std::move(db)) {} 44 : directory_(std::move(directory)), db_(std::move(db)) {}
41 45
42 LevelDBDatabaseImpl::~LevelDBDatabaseImpl() { 46 LevelDBDatabaseImpl::~LevelDBDatabaseImpl() {
43 for (auto& p : iterator_map_) 47 for (auto& p : iterator_map_)
44 delete p.second; 48 delete p.second;
45 for (auto& p : snapshot_map_) 49 for (auto& p : snapshot_map_)
46 db_->ReleaseSnapshot(p.second); 50 db_->ReleaseSnapshot(p.second);
47 } 51 }
48 52
49 void LevelDBDatabaseImpl::Put(const std::vector<uint8_t>& key, 53 void LevelDBDatabaseImpl::Put(const std::vector<uint8_t>& key,
50 const std::vector<uint8_t>& value, 54 const std::vector<uint8_t>& value,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 const leveldb::Slice& key_prefix, 290 const leveldb::Slice& key_prefix,
287 leveldb::WriteBatch* batch) { 291 leveldb::WriteBatch* batch) {
288 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, 292 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix,
289 [batch](const leveldb::Slice& key, const leveldb::Slice& value) { 293 [batch](const leveldb::Slice& key, const leveldb::Slice& value) {
290 batch->Delete(key); 294 batch->Delete(key);
291 }); 295 });
292 return status; 296 return status;
293 } 297 }
294 298
295 } // namespace leveldb 299 } // namespace leveldb
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698