Fix memory leak on HttpFetcher and ProxyResolver.
The current HttpFetcher and ProxyResolver code uses
google::protobuf::Closure callbacks created with NewCallback. These
callbacks will self-delete them when you call Run(), leaking the
callback if that doesn't happens.
This patch replaces all the NewCallback() calls by
NewPermanentCallback(), which won't delete the callback after running
it. It then adds a new utils::GlibDestroyClosure() function to use in
conjunction with the existing utils::GlibRunClosure() to schedule
callbacks from the glib main loop without leaking them.
Finally, this patch fixes a use-after-free on the
AbortingHttpFetcherTestDelegate class only affecting unit tests.
Other minor linting errors fixed.
BUG=chromium:378548
TEST=`FEATURES="test" USE="clang asan" emerge-link update_engine` doesn't complain about HttpFetcher.
Change-Id: Ica3265aca42f07811b7dff6131f9a43ab06269aa
Reviewed-on: https://chromium-review.googlesource.com/202062
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/utils.h b/utils.h
index e83db5c..d2a0fc2 100644
--- a/utils.h
+++ b/utils.h
@@ -318,9 +318,12 @@
// success, false otherwise.
bool SetCpuShares(CpuShares shares);
-// Assumes data points to a Closure. Runs it and returns FALSE;
+// Assumes |data| points to a Closure. Runs it and returns FALSE;
gboolean GlibRunClosure(gpointer data);
+// Destroys the Closure pointed by |data|.
+void GlibDestroyClosure(gpointer data);
+
// Converts seconds into human readable notation including days, hours, minutes
// and seconds. For example, 185 will yield 3m5s, 4300 will yield 1h11m40s, and
// 360000 will yield 4d4h0m0s. Zero padding not applied. Seconds are always