From c493bec0898b2cdc3ae20b2d41b19cdf3041f599 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Dec 2015 11:36:29 +0800 Subject: [PATCH] Make sure temp file will be cleaned up when base::Move fails --- atom/common/asar/scoped_temporary_file.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/atom/common/asar/scoped_temporary_file.cc b/atom/common/asar/scoped_temporary_file.cc index 14f2ba8ef9dd..6dd12782d8ee 100644 --- a/atom/common/asar/scoped_temporary_file.cc +++ b/atom/common/asar/scoped_temporary_file.cc @@ -33,17 +33,20 @@ bool ScopedTemporaryFile::Init(const base::FilePath::StringType& ext) { return true; base::ThreadRestrictions::ScopedAllowIO allow_io; - - base::FilePath temp_path; - if (!base::CreateTemporaryFile(&temp_path)) + if (!base::CreateTemporaryFile(&path_)) return false; - if (ext.empty()) - return true; - +#if defined(OS_WIN) // Keep the original extension. - path_ = temp_path.AddExtension(ext); - return base::Move(temp_path, path_); + if (!ext.empty()) { + base::FilePath new_path = path_.AddExtension(ext); + if (!base::Move(path_, new_path)) + return false; + path_ = new_path; + } +#endif + + return true; } bool ScopedTemporaryFile::InitFromFile(base::File* src,