Remove leaked callback when CleanUp() from TimeoutCallback().
When CleanUp() is called indirectly from TimeoutCallback(), the
TimeoutCallback() itself is canceled before the new recurrent call is
scheduled. The CancelTask() call will trivially succeed because the
callback already triggered.
Before CL:281197, the g_source_destroy() call to remove the currently
running callback would prevent it from being re-scheduled even if it
returns TRUE from the callback.
This patch re-schedules the callback before calling CurlPerformOnce()
so CancelTask() would cancel the scheduled task.
Bug: chromium:535649
Test: Added unittest. Verified it fails without the change.
Change-Id: Ica742dab0eb8d9d5c5055c8afac9d775ad1e0012
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index e8a8c4b..5b6c605 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -514,9 +514,6 @@
}
void LibcurlHttpFetcher::TimeoutCallback() {
- if (transfer_in_progress_)
- CurlPerformOnce();
-
// We always re-schedule the callback, even if we don't want to be called
// anymore. We will remove the event source separately if we don't want to
// be called back.
@@ -524,6 +521,11 @@
FROM_HERE,
base::Bind(&LibcurlHttpFetcher::TimeoutCallback, base::Unretained(this)),
TimeDelta::FromSeconds(idle_seconds_));
+
+ // CurlPerformOnce() may call CleanUp(), so we need to schedule our callback
+ // first, since it could be canceled by this call.
+ if (transfer_in_progress_)
+ CurlPerformOnce();
}
void LibcurlHttpFetcher::CleanUp() {