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

Unified Diff: chrome/browser/sessions/session_backend.cc

Issue 39275: Fixes possible crash in SessionBackend. I believe what's happening... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | « chrome/browser/sessions/session_backend.h ('k') | chrome/browser/sessions/session_backend_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sessions/session_backend.cc
===================================================================
--- chrome/browser/sessions/session_backend.cc (revision 11244)
+++ chrome/browser/sessions/session_backend.cc (working copy)
@@ -213,9 +213,14 @@
std::vector<SessionCommand*>* commands,
bool reset_first) {
Init();
- if ((reset_first && !empty_file_) || !current_session_file_->IsOpen())
+ // Make sure and check current_session_file_, if opening the file failed
+ // current_session_file_ will be NULL.
+ if ((reset_first && !empty_file_) || !current_session_file_.get() ||
+ !current_session_file_->IsOpen()) {
ResetFile();
- if (current_session_file_->IsOpen() &&
+ }
+ // Need to check current_session_file_ again, ResetFile may fail.
+ if (current_session_file_.get() && current_session_file_->IsOpen() &&
!AppendCommandsToFile(current_session_file_.get(), *commands)) {
current_session_file_.reset(NULL);
}
@@ -313,7 +318,16 @@
void SessionBackend::ResetFile() {
DCHECK(inited_);
- current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath()));
+ if (current_session_file_.get()) {
+ // File is already open, truncate it. We truncate instead of closing and
+ // reopening to avoid the possibility of scanners locking the file out
+ // from under us once we close it. If truncation fails, we'll try to
+ // recreate.
+ if (current_session_file_->Truncate(sizeof_header()) != sizeof_header())
+ current_session_file_.reset(NULL);
+ }
+ if (!current_session_file_.get())
+ current_session_file_.reset(OpenAndWriteHeader(GetCurrentSessionPath()));
empty_file_ = true;
}
@@ -321,7 +335,8 @@
DCHECK(!path.empty());
net::FileStream* file = new net::FileStream();
file->Open(path, base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_WRITE);
+ base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
+ base::PLATFORM_FILE_EXCLUSIVE_READ);
if (!file->IsOpen())
return NULL;
int32 header[2];
@@ -329,7 +344,7 @@
header[1] = kFileCurrentVersion;
int wrote = file->Write(reinterpret_cast<char*>(&header),
sizeof(header), NULL);
- if (wrote != sizeof(header))
+ if (wrote != sizeof_header())
return NULL;
return file;
}
« no previous file with comments | « chrome/browser/sessions/session_backend.h ('k') | chrome/browser/sessions/session_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698