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

Unified Diff: net/disk_cache/simple/simple_index_file.cc

Issue 17265007: Unlink corrupt SimpleCache index files immediately after load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rdsmith remediation Created 7 years, 6 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
« no previous file with comments | « net/disk_cache/simple/simple_index_file.h ('k') | net/disk_cache/simple/simple_index_file_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_file.cc
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc
index 529faf15a1ed1c71ecb6a616f3c5480134dfc2b6..c6bc6eaf891dc1a55cc3bd0c3517792324bace1c 100644
--- a/net/disk_cache/simple/simple_index_file.cc
+++ b/net/disk_cache/simple/simple_index_file.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include <base/bind_helpers.h>
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
#include "base/hash.h"
@@ -175,13 +176,23 @@ bool SimpleIndexFile::IsIndexFileStale(const base::FilePath& index_filename) {
// static
scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk(
const base::FilePath& index_filename) {
+ base::ScopedClosureRunner
+ scoped_index_deleter(base::Bind(base::IgnoreResult(&file_util::Delete),
+ index_filename, false));
+
std::string contents;
if (!file_util::ReadFileToString(index_filename, &contents)) {
LOG(WARNING) << "Could not read Simple Index file.";
return scoped_ptr<SimpleIndex::EntrySet>();
}
- return SimpleIndexFile::Deserialize(contents.data(), contents.size());
+ scoped_ptr<SimpleIndex::EntrySet> entries =
+ SimpleIndexFile::Deserialize(contents.data(), contents.size());
+ if (!entries)
+ return scoped_ptr<SimpleIndex::EntrySet>();
+
+ scoped_index_deleter.Release();
pasko 2013/06/20 13:52:22 I don't like using automatic closure runner in thi
gavinp 2013/06/20 20:18:18 Done. I was only trying to show off that I knew ab
+ return entries.Pass();
}
// static
« no previous file with comments | « net/disk_cache/simple/simple_index_file.h ('k') | net/disk_cache/simple/simple_index_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698