summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/block_files.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 21:59:03 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 21:59:03 +0000
commite819b55cf062822a23280b4da7760abfd2a86e64 (patch)
tree8da62133f794b047ccf3bb57f3bd805ae7f036b8 /net/disk_cache/block_files.cc
parentf321a984b66500ea0063549612992cf784da12b6 (diff)
downloadchromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.zip
chromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.tar.gz
chromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.tar.bz2
Disk Cache: cleanup of OpenBlockFile.
Don't add the file to the list of open files until it passes all sanity checks. BUG=18174 TEST=unittest Review URL: http://codereview.chromium.org/164336 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/block_files.cc')
-rw-r--r--net/disk_cache/block_files.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index 0e9eb04..ffb74db 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -237,24 +237,18 @@ bool BlockFiles::OpenBlockFile(int index) {
}
std::wstring name = Name(index);
- MappedFile* file = new MappedFile();
- file->AddRef();
+ scoped_refptr<MappedFile> file(new MappedFile());
if (!file->Init(name, kBlockHeaderSize)) {
- NOTREACHED();
LOG(ERROR) << "Failed to open " << name;
- file->Release();
return false;
}
if (file->GetLength() < static_cast<size_t>(kBlockHeaderSize)) {
LOG(ERROR) << "File too small " << name;
- file->Release();
return false;
}
- block_files_[index] = file;
-
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
if (kBlockMagic != header->magic || kCurrentVersion != header->version) {
LOG(ERROR) << "Invalid file version or magic";
@@ -266,6 +260,9 @@ bool BlockFiles::OpenBlockFile(int index) {
if (!FixBlockFileHeader(file))
return false;
}
+
+ DCHECK(!block_files_[index]);
+ file.swap(&block_files_[index]);
return true;
}