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.cc b/utils.cc
index b32a369..2664f9c 100644
--- a/utils.cc
+++ b/utils.cc
@@ -5,17 +5,17 @@
 #include "update_engine/utils.h"
 
 #include <attr/xattr.h>
-#include <sys/mount.h>
-#include <sys/resource.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/mount.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 
 #include <algorithm>
@@ -850,6 +850,10 @@
   return FALSE;
 }
 
+void GlibDestroyClosure(gpointer data) {
+  delete reinterpret_cast<google::protobuf::Closure*>(data);
+}
+
 string FormatSecs(unsigned secs) {
   return FormatTimeDelta(TimeDelta::FromSeconds(secs));
 }