From af643a8e40de6f622263af11609fe8901c85d39f Mon Sep 17 00:00:00 2001 From: "hashimoto@chromium.org" Date: Thu, 30 Aug 2012 09:53:40 +0000 Subject: Reland 153920 - drive: Fix possible leak in DriveFileSystem::AddUploadedFile Fix possible leak which can occur when the callback not getting called. BUG=None TEST=unit_tests --gtest_filter="DriveFileSystemTest.*" Review URL: https://chromiumcodereview.appspot.com/10896043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154107 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/gdata/drive_file_system.cc | 20 ++++++++++++-------- chrome/browser/chromeos/gdata/drive_file_system.h | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/chrome/browser/chromeos/gdata/drive_file_system.cc b/chrome/browser/chromeos/gdata/drive_file_system.cc index a244217..7f779bc 100644 --- a/chrome/browser/chromeos/gdata/drive_file_system.cc +++ b/chrome/browser/chromeos/gdata/drive_file_system.cc @@ -2731,17 +2731,17 @@ void DriveFileSystem::AddUploadedFileOnUIThread( DCHECK(doc_entry.get()); const std::string& resource_id = doc_entry->resource_id(); - AddUploadedFileParams* params = + scoped_ptr params( new AddUploadedFileParams(upload_mode, directory_path, doc_entry.Pass(), file_content_path, cache_operation, - callback); + callback)); const FileMoveCallback file_move_callback = base::Bind(&DriveFileSystem::ContinueAddUploadedFile, - ui_weak_ptr_, params); + ui_weak_ptr_, base::Passed(¶ms)); if (upload_mode == UPLOAD_EXISTING_FILE) { // Remove the existing entry. @@ -2752,7 +2752,7 @@ void DriveFileSystem::AddUploadedFileOnUIThread( } void DriveFileSystem::ContinueAddUploadedFile( - AddUploadedFileParams* params, + scoped_ptr params, DriveFileError error, const FilePath& /* file_path */) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -2764,16 +2764,20 @@ void DriveFileSystem::ContinueAddUploadedFile( DCHECK(!params->resource_id.empty()); DCHECK(!params->md5.empty()); + // Get parameters before base::Passed() invalidates |params|. + const FilePath& directory_path = params->directory_path; + scoped_ptr doc_entry(params->doc_entry.Pass()); + resource_metadata_->AddEntryToDirectory( - params->directory_path, - params->doc_entry.Pass(), + directory_path, + doc_entry.Pass(), base::Bind(&DriveFileSystem::AddUploadedFileToCache, ui_weak_ptr_, - base::Owned(params))); + base::Passed(¶ms))); } void DriveFileSystem::AddUploadedFileToCache( - AddUploadedFileParams* params, + scoped_ptr params, DriveFileError error, const FilePath& file_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/chrome/browser/chromeos/gdata/drive_file_system.h b/chrome/browser/chromeos/gdata/drive_file_system.h index e6acaf6..e14133b 100644 --- a/chrome/browser/chromeos/gdata/drive_file_system.h +++ b/chrome/browser/chromeos/gdata/drive_file_system.h @@ -558,12 +558,12 @@ class DriveFileSystem : public DriveFileSystemInterface, const FilePath& directory_path); // Continues to add an uploaded file after existing entry has been deleted. - void ContinueAddUploadedFile(AddUploadedFileParams* params, + void ContinueAddUploadedFile(scoped_ptr params, DriveFileError error, const FilePath& file_path); // Adds the uploaded file to the cache. - void AddUploadedFileToCache(AddUploadedFileParams* params, + void AddUploadedFileToCache(scoped_ptr params, DriveFileError error, const FilePath& file_path); -- cgit v1.1