diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 10:14:27 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-19 10:14:27 +0000 |
commit | 4c19b042ea31bd393d2265656f94339d1c3d82ff (patch) | |
tree | 7b03fe8adcd4fceae6fe507c0207c786e38f8093 | |
parent | c62e602ce28c6224b6849cadc4a998928de60fc7 (diff) | |
download | chromium_src-4c19b042ea31bd393d2265656f94339d1c3d82ff.zip chromium_src-4c19b042ea31bd393d2265656f94339d1c3d82ff.tar.gz chromium_src-4c19b042ea31bd393d2265656f94339d1c3d82ff.tar.bz2 |
Fix a small leak in FileUtilProxy
BUG=none
TEST=green mem bots
Review URL: http://codereview.chromium.org/7669046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97451 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/file_util_proxy.cc | 8 | ||||
-rw-r--r-- | base/file_util_proxy.h | 3 | ||||
-rw-r--r-- | chrome/browser/nacl_host/nacl_process_host.cc | 1 |
3 files changed, 9 insertions, 3 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc index 0e4badf..7757c42 100644 --- a/base/file_util_proxy.cc +++ b/base/file_util_proxy.cc @@ -854,8 +854,10 @@ bool FileUtilProxy::Read( int64 offset, int bytes_to_read, ReadCallback* callback) { - if (bytes_to_read < 0) + if (bytes_to_read < 0) { + delete callback; return false; + } return Start(FROM_HERE, message_loop_proxy, new RelayRead(file, offset, bytes_to_read, callback)); } @@ -868,8 +870,10 @@ bool FileUtilProxy::Write( const char* buffer, int bytes_to_write, WriteCallback* callback) { - if (bytes_to_write <= 0) + if (bytes_to_write <= 0) { + delete callback; return false; + } return Start(FROM_HERE, message_loop_proxy, new RelayWrite(file, offset, buffer, bytes_to_write, callback)); } diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h index 872da44..30f051b 100644 --- a/base/file_util_proxy.h +++ b/base/file_util_proxy.h @@ -34,6 +34,8 @@ class BASE_EXPORT FileUtilProxy { // This callback is used by methods that report only an error code. It is // valid to pass NULL as the callback parameter to any function that takes a // StatusCallback, in which case the operation will complete silently. + // The ownership of |callback| is taken by the function and will always be + // deleted by the function even on failure. typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback; typedef Callback3<PlatformFileError /* error code */, @@ -60,6 +62,7 @@ class BASE_EXPORT FileUtilProxy { // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create // a new file at the given |file_path| and calls back with // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. + // Takes ownership of |callback| and will delete it even on failure. static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& file_path, int file_flags, diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc index 2db830d2..6922128 100644 --- a/chrome/browser/nacl_host/nacl_process_host.cc +++ b/chrome/browser/nacl_host/nacl_process_host.cc @@ -242,7 +242,6 @@ void NaClProcessHost::OnProcessLaunched() { irt_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, callback)) { - delete callback; delete this; } } |