summaryrefslogtreecommitdiffstats
path: root/chrome/browser/visitedlink_master.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 23:38:42 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 23:38:42 +0000
commit1631786f88bf717d59da40603fdb882191beae8b (patch)
treebcc840ee96817944b588db07f5414c4bb10dfcae /chrome/browser/visitedlink_master.cc
parent80cc00a3acaee44c537d72c8ccd9f0ad1103df3a (diff)
downloadchromium_src-1631786f88bf717d59da40603fdb882191beae8b.zip
chromium_src-1631786f88bf717d59da40603fdb882191beae8b.tar.gz
chromium_src-1631786f88bf717d59da40603fdb882191beae8b.tar.bz2
Flush the visited link database after a write. If we crash,
we're not guaranteed that the write will make it to the kernel. BUG=8710 Review URL: http://codereview.chromium.org/42264 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11802 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/visitedlink_master.cc')
-rw-r--r--chrome/browser/visitedlink_master.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc
index 09a3bee..5d48d63 100644
--- a/chrome/browser/visitedlink_master.cc
+++ b/chrome/browser/visitedlink_master.cc
@@ -92,6 +92,13 @@ class AsyncWriter : public Task {
return false; // Don't write to an invalid part of the file.
size_t num_written = fwrite(data, 1, data_len, file);
+
+ // The write may not make it to the kernel (stdlib may buffer the write)
+ // until the next fseek/fclose call. If we crash, it's easy for our used
+ // item count to be out of sync with the number of hashes we write.
+ // Protect against this by calling fflush.
+ int ret = fflush(file);
+ DCHECK_EQ(0, ret);
return num_written == data_len;
}