]> khamidou — GitHub mirrors - electron.git/commitdiff
Clear pending_buffer_ at correct time
authorCheng Zhao <zcbenz@gmail.com>
Wed, 17 Jun 2015 03:04:15 +0000 (11:04 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 17 Jun 2015 03:04:15 +0000 (11:04 +0800)
atom/browser/net/url_request_fetch_job.cc

index ad5f2aed62b72b9b1652a09dc89bedc637e4b630..7781f957cc1a994dd4842304db61d2abf2cfca45 100644 (file)
@@ -104,6 +104,12 @@ int URLRequestFetchJob::DataAvailable(net::IOBuffer* buffer, int num_bytes) {
 
   int bytes_read = std::min(num_bytes, pending_buffer_size_);
   memcpy(pending_buffer_->data(), buffer->data(), bytes_read);
+
+  // Clear the buffers before notifying the read is complete, so that it is
+  // safe for the observer to read.
+  pending_buffer_ = nullptr;
+  pending_buffer_size_ = 0;
+
   NotifyReadComplete(bytes_read);
   return bytes_read;
 }
@@ -146,6 +152,8 @@ int URLRequestFetchJob::GetResponseCode() const {
 }
 
 void URLRequestFetchJob::OnURLFetchComplete(const net::URLFetcher* source) {
+  pending_buffer_ = nullptr;
+  pending_buffer_size_ = 0;
   NotifyDone(fetcher_->GetStatus());
   if (fetcher_->GetStatus().is_success())
     NotifyReadComplete(0);