Index: storage/browser/fileapi/sandbox_origin_database.cc |
diff --git a/storage/browser/fileapi/sandbox_origin_database.cc b/storage/browser/fileapi/sandbox_origin_database.cc |
index 85424a2351c8b3f08a5db910cc71491bc3f32d43..9bdadc40fb77b546ea566eea0b996a7125e3e5a8 100644 |
--- a/storage/browser/fileapi/sandbox_origin_database.cc |
+++ b/storage/browser/fileapi/sandbox_origin_database.cc |
@@ -331,16 +331,19 @@ bool SandboxOriginDatabase::GetLastPathNumber(int* number) { |
return false; |
} |
// Verify that this is a totally new database, and initialize it. |
- scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(leveldb::ReadOptions())); |
- iter->SeekToFirst(); |
- if (iter->Valid()) { // DB was not empty, but had no last path number! |
- LOG(ERROR) << "File system origin database is corrupt!"; |
- return false; |
+ { |
+ // Scope the iterator to ensure it is deleted before database is closed. |
+ scoped_ptr<leveldb::Iterator> iter( |
+ db_->NewIterator(leveldb::ReadOptions())); |
+ iter->SeekToFirst(); |
+ if (iter->Valid()) { // DB was not empty, but had no last path number! |
+ LOG(ERROR) << "File system origin database is corrupt!"; |
+ return false; |
+ } |
} |
// This is always the first write into the database. If we ever add a |
// version number, they should go in in a single transaction. |
- status = |
- db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
+ status = db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); |
if (!status.ok()) { |
HandleError(FROM_HERE, status); |
return false; |