From 8df9747bff840d1a63b9fe1309b18e5fb21e8340 Mon Sep 17 00:00:00 2001 From: "adamk@chromium.org" Date: Tue, 15 Mar 2011 02:04:25 +0000 Subject: Fix memory leak in FileWriterDelegate by passing FileStream::Write a callback owned by the delegate. Remove the suppression of this memory leak. R=ericu@chromium.org BUG=75741 TEST=none Review URL: http://codereview.chromium.org/6685056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78148 0039d316-1c4b-4281-b951-d872f2087c98 --- tools/valgrind/memcheck/suppressions_mac.txt | 10 ---------- webkit/fileapi/file_writer_delegate.cc | 12 ++++++------ webkit/fileapi/file_writer_delegate.h | 5 ++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/valgrind/memcheck/suppressions_mac.txt b/tools/valgrind/memcheck/suppressions_mac.txt index f1283ca..c1c895a 100644 --- a/tools/valgrind/memcheck/suppressions_mac.txt +++ b/tools/valgrind/memcheck/suppressions_mac.txt @@ -1441,13 +1441,3 @@ fun:-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] fun:-[NSInFlightAnimation advanceToTime:] } -{ - bug_75741 - Memcheck:Leak - fun:_Znw* - fun:_ZN4base21ScopedCallbackFactoryIN7fileapi18FileWriterDelegateEE11NewCallbackIiEEPN9Callback1IT_E4TypeEMS2_FvS6_E - fun:_ZN7fileapi18FileWriterDelegate5WriteEv - fun:_ZN7fileapi18FileWriterDelegate14OnDataReceivedEi - fun:_Z16DispatchToMethodIN7fileapi18FileWriterDelegateEMS1_FviEiEvPT_T0_RK6Tuple1IT1_E - fun:_ZN27ScopedRunnableMethodFactoryIN7fileapi18FileWriterDelegateEE14RunnableMethodIMS1_FviE6Tuple1IiEE3RunEv -} diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc index 49a4ecd..c0574fca 100644 --- a/webkit/fileapi/file_writer_delegate.cc +++ b/webkit/fileapi/file_writer_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,7 +23,8 @@ FileWriterDelegate::FileWriterDelegate( bytes_written_(0), bytes_read_(0), io_buffer_(new net::IOBufferWithSize(kReadBufSize)), - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + io_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), + &FileWriterDelegate::OnDataWritten), method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -119,10 +120,9 @@ void FileWriterDelegate::OnDataReceived(int bytes_read) { } void FileWriterDelegate::Write() { - int write_response = file_stream_->Write( - io_buffer_->data() + bytes_written_, - bytes_read_ - bytes_written_, - callback_factory_.NewCallback(&FileWriterDelegate::OnDataWritten)); + int write_response = file_stream_->Write(io_buffer_->data() + bytes_written_, + bytes_read_ - bytes_written_, + &io_callback_); if (write_response > 0) MessageLoop::current()->PostTask( FROM_HERE, diff --git a/webkit/fileapi/file_writer_delegate.h b/webkit/fileapi/file_writer_delegate.h index 8e90a23..f5de184 100644 --- a/webkit/fileapi/file_writer_delegate.h +++ b/webkit/fileapi/file_writer_delegate.h @@ -8,10 +8,10 @@ #include "base/file_path.h" #include "base/platform_file.h" #include "base/ref_counted.h" -#include "base/scoped_callback_factory.h" #include "base/scoped_ptr.h" #include "base/task.h" #include "base/time.h" +#include "net/base/completion_callback.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/url_request/url_request.h" @@ -61,11 +61,10 @@ class FileWriterDelegate : public net::URLRequest::Delegate { scoped_refptr io_buffer_; scoped_ptr file_stream_; net::URLRequest* request_; - base::ScopedCallbackFactory callback_factory_; + net::CompletionCallbackImpl io_callback_; ScopedRunnableMethodFactory method_factory_; }; } // namespace fileapi #endif // WEBKIT_FILEAPI_FILE_WRITER_DELEGATE_H_ - -- cgit v1.1