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

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