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/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 2c3fd4d..be5df41 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -16,9 +16,9 @@
 #include "update_engine/real_dbus_wrapper.h"
 #include "update_engine/utils.h"
 
-using google::protobuf::NewCallback;
-using std::max;
+using google::protobuf::NewPermanentCallback;
 using std::make_pair;
+using std::max;
 using std::string;
 
 // This is a concrete implementation of HttpFetcher that uses libcurl to do the
@@ -251,7 +251,7 @@
   url_ = url;
   if (!ResolveProxiesForUrl(
           url_,
-          NewCallback(this, &LibcurlHttpFetcher::ProxiesResolved))) {
+          NewPermanentCallback(this, &LibcurlHttpFetcher::ProxiesResolved))) {
     LOG(ERROR) << "Couldn't resolve proxies";
     if (delegate_)
       delegate_->TransferComplete(this, false);