Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1317)

Unified Diff: webkit/glue/resource_fetcher.cc

Issue 6325012: Fix a potential crash by clearing callback_ before running it.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/resource_fetcher.h ('k') | webkit/glue/resource_fetcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/resource_fetcher.cc
===================================================================
--- webkit/glue/resource_fetcher.cc (revision 71961)
+++ webkit/glue/resource_fetcher.cc (working copy)
@@ -53,6 +53,18 @@
loader_->loadAsynchronously(request, this);
}
+void ResourceFetcher::RunCallback(const WebURLResponse& response,
+ const std::string& data) {
+ if (!callback_.get())
+ return;
+
+ // Take care to clear callback_ before running the callback as it may lead to
+ // our destruction.
+ scoped_ptr<Callback> callback;
+ callback.swap(callback_);
+ callback->Run(response, data);
+}
+
/////////////////////////////////////////////////////////////////////////////
// WebURLLoaderClient methods
@@ -93,10 +105,7 @@
DCHECK(!completed_);
completed_ = true;
- if (callback_.get()) {
- callback_->Run(response_, data_);
- callback_.reset();
- }
+ RunCallback(response_, data_);
}
void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) {
@@ -104,10 +113,7 @@
completed_ = true;
// Go ahead and tell our delegate that we're done.
- if (callback_.get()) {
- callback_->Run(WebURLResponse(), std::string());
- callback_.reset();
- }
+ RunCallback(WebURLResponse(), std::string());
}
/////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « webkit/glue/resource_fetcher.h ('k') | webkit/glue/resource_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698