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