Blame SOURCES/0228-Fix-memory-leaks-in-abrt-dbus.patch

06486d
From 1902735613a3cc4a1c87e8cbae83a7452bfd8327 Mon Sep 17 00:00:00 2001
06486d
From: Jakub Filak <jfilak@redhat.com>
06486d
Date: Sun, 1 May 2016 07:13:56 +0200
06486d
Subject: [PATCH] Fix memory leaks in abrt-dbus
06486d
06486d
Fix several repeated leaks that were causing abrt-dbus to waste system
06486d
memory.
06486d
06486d
I used this valgrind command:
06486d
    valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all \
06486d
             --track-origins=yes --suppressions=glib.supp \
06486d
             --log-file=/tmp/leaks-$(date +%s).txt abrt-dbus -vvv -t 10
06486d
06486d
With suppressions from libsecret and NetworkManager:
06486d
  * https://raw.githubusercontent.com/GNOME/libsecret/master/build/glib.supp
06486d
  * https://raw.githubusercontent.com/NetworkManager/NetworkManager/master/valgrind.suppressions
06486d
06486d
The suppressions were needed because Glib allocates a lot of static
06486d
stuff and does not free it at exit because it is useless.
06486d
06486d
Resolves: #1319704
06486d
06486d
Signed-off-by: Jakub Filak <jfilak@redhat.com>
06486d
---
06486d
 src/dbus/abrt-dbus.c   | 39 ++++++++++++++++++++++-----------------
06486d
 src/dbus/abrt-polkit.c |  3 +++
06486d
 src/lib/abrt_conf.c    |  3 +++
06486d
 src/lib/abrt_glib.c    |  7 +++----
06486d
 src/lib/problem_api.c  |  1 +
06486d
 5 files changed, 32 insertions(+), 21 deletions(-)
06486d
06486d
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
06486d
index 173cec4..0a459cd 100644
06486d
--- a/src/dbus/abrt-dbus.c
06486d
+++ b/src/dbus/abrt-dbus.c
06486d
@@ -97,22 +97,21 @@ static uid_t get_caller_uid(GDBusConnection *connection, GDBusMethodInvocation *
06486d
     GError *error = NULL;
06486d
     guint caller_uid;
06486d
 
06486d
-    GDBusProxy * proxy = g_dbus_proxy_new_sync(connection,
06486d
-                                     G_DBUS_PROXY_FLAGS_NONE,
06486d
-                                     NULL,
06486d
-                                     "org.freedesktop.DBus",
06486d
-                                     "/org/freedesktop/DBus",
06486d
-                                     "org.freedesktop.DBus",
06486d
-                                     NULL,
06486d
-                                     &error);
06486d
-
06486d
-    GVariant *result = g_dbus_proxy_call_sync(proxy,
06486d
-                                     "GetConnectionUnixUser",
06486d
-                                     g_variant_new ("(s)", caller),
06486d
-                                     G_DBUS_CALL_FLAGS_NONE,
06486d
-                                     -1,
06486d
-                                     NULL,
06486d
-                                     &error);
06486d
+    /* Proxy isn't necessary if only need to call a single method.  By default
06486d
+     * GDBusProxy connects to signals and downloads property values. It
06486d
+     * suppressed by passing flags argument, but not-creating proxy at all is
06486d
+     * much faster and safer. */
06486d
+    GVariant *result = g_dbus_connection_call_sync(connection,
06486d
+                                                   "org.freedesktop.DBus",
06486d
+                                                   "/org/freedesktop/DBus",
06486d
+                                                   "org.freedesktop.DBus",
06486d
+                                                   "GetConnectionUnixUser",
06486d
+                                                   g_variant_new ("(s)", caller),
06486d
+                                                   /* reply_type */  NULL,
06486d
+                                                   G_DBUS_CALL_FLAGS_NONE,
06486d
+                                                   /* timeout */     -1,
06486d
+                                                   /* cancellable */ NULL,
06486d
+                                                   &error);
06486d
 
06486d
     if (result == NULL)
06486d
     {
06486d
@@ -940,7 +939,11 @@ static void handle_method_call(GDBusConnection *connection,
06486d
 static gboolean on_timeout_cb(gpointer user_data)
06486d
 {
06486d
     g_main_loop_quit(loop);
06486d
-    return TRUE;
06486d
+
06486d
+    /* FALSE -> remove and destroy this source. Without it, the timeout source
06486d
+     * will be leaked at exit - that isn't a problem but it makes valgrind out
06486d
+     * less readable. */
06486d
+    return FALSE;
06486d
 }
06486d
 
06486d
 static const GDBusInterfaceVTable interface_vtable =
06486d
@@ -1059,6 +1062,8 @@ int main(int argc, char *argv[])
06486d
 
06486d
     g_dbus_node_info_unref(introspection_data);
06486d
 
06486d
+    g_main_loop_unref(loop);
06486d
+
06486d
     free_abrt_conf_data();
06486d
 
06486d
     return 0;
06486d
diff --git a/src/dbus/abrt-polkit.c b/src/dbus/abrt-polkit.c
06486d
index 39880e5..34af8a4 100644
06486d
--- a/src/dbus/abrt-polkit.c
06486d
+++ b/src/dbus/abrt-polkit.c
06486d
@@ -59,8 +59,11 @@ static PolkitResult do_check(PolkitSubject *subject, const char *action_id)
06486d
                 POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
06486d
                 cancellable,
06486d
                 &error);
06486d
+
06486d
+    g_object_unref(cancellable);
06486d
     g_object_unref(authority);
06486d
     g_source_remove(cancel_timeout);
06486d
+    g_object_unref(subject);
06486d
     if (error)
06486d
     {
06486d
         g_error_free(error);
06486d
diff --git a/src/lib/abrt_conf.c b/src/lib/abrt_conf.c
06486d
index 4a49032..5ae64c5 100644
06486d
--- a/src/lib/abrt_conf.c
06486d
+++ b/src/lib/abrt_conf.c
06486d
@@ -37,6 +37,9 @@ void free_abrt_conf_data()
06486d
 
06486d
     free(g_settings_dump_location);
06486d
     g_settings_dump_location = NULL;
06486d
+
06486d
+    free(g_settings_autoreporting_event);
06486d
+    g_settings_autoreporting_event = NULL;
06486d
 }
06486d
 
06486d
 static void ParseCommon(map_string_t *settings, const char *conf_filename)
06486d
diff --git a/src/lib/abrt_glib.c b/src/lib/abrt_glib.c
06486d
index f7c128e..60e104f 100644
06486d
--- a/src/lib/abrt_glib.c
06486d
+++ b/src/lib/abrt_glib.c
06486d
@@ -22,15 +22,14 @@
06486d
 GList *string_list_from_variant(GVariant *variant)
06486d
 {
06486d
     GList *list = NULL;
06486d
-    GVariantIter *iter;
06486d
+    GVariantIter iter;
06486d
+    g_variant_iter_init(&iter, variant);
06486d
     gchar *str;
06486d
-    g_variant_get(variant, "as", &iter);
06486d
-    while (g_variant_iter_loop(iter, "s", &str))
06486d
+    while (g_variant_iter_loop(&iter, "s", &str))
06486d
     {
06486d
         log_notice("adding: %s", str);
06486d
         list = g_list_prepend(list, xstrdup(str));
06486d
     }
06486d
-    g_variant_unref(variant);
06486d
 
06486d
     /* we were prepending items, so we should reverse the list to not confuse people
06486d
      * by returning items in reversed order than it's in the variant
06486d
diff --git a/src/lib/problem_api.c b/src/lib/problem_api.c
06486d
index b343882..9fedb3d 100644
06486d
--- a/src/lib/problem_api.c
06486d
+++ b/src/lib/problem_api.c
06486d
@@ -51,6 +51,7 @@ int for_each_problem_in_dir(const char *path,
06486d
         if (dir_fd < 0)
06486d
         {
06486d
             VERB2 perror_msg("can't open problem directory '%s'", full_name);
06486d
+            free(full_name);
06486d
             continue;
06486d
         }
06486d
 
06486d
-- 
06486d
1.8.3.1
06486d