From 401cca51de36c668cd81cb44161e52fb7db50266 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Bogler Date: Fri, 6 Mar 2015 18:23:29 +0100 Subject: Fixed leaks from "g_variant_get_child_value" calls Fixed memory leaks. The children returned by "g_variant_get_child_value" were not freed. Instead of "g_variant_get_child_value", "g_variant_get_child" now is used at most places in nhm_systemd.c Change-Id: Ic2a0c06ca743b7c7b26c958ed90d56d30a90c839 --- ChangeLog | 5 +++++ NEWS | 4 ++++ configure.ac | 2 +- src/nhm-systemd.c | 22 +++++++--------------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 094c1f4..738b201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +19th Nov 2013 Jean-Pierre Bogler + * Fixed memory leaks. The children returned by "g_variant_get_child_value" were + not freed. Instead of "g_variant_get_child_value", "g_variant_get_child" now + is used at most places in nhm_systemd.c + 23rd Oct 2013 Jean-Pierre Bogler * Bugfix for crash at startup. If a service failed before dbus connection was obtained, a sgementation fault occured in "nhm_main_register_app_status". diff --git a/NEWS b/NEWS index 46b6119..99221fd 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.3.4 +===== +* Bugfix for memory leak in systemd observation + 1.3.3 ===== * Two bugfixes for start up and error cases diff --git a/configure.ac b/configure.ac index ee8facf..1fe13c3 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ ################################################################################ # Initialize autoconf -AC_INIT([node-health-monitor], [1.3.3]) +AC_INIT([node-health-monitor], [1.3.4]) AC_PREREQ([2.50]) AC_COPYRIGHT([Copyright (c) 2013 Continental Automotive GmbH]) diff --git a/src/nhm-systemd.c b/src/nhm-systemd.c index 1170631..2510c8b 100644 --- a/src/nhm-systemd.c +++ b/src/nhm-systemd.c @@ -411,7 +411,6 @@ nhm_systemd_unit_get_active_state(NhmSystemdUnit *unit) { GError *error = NULL; GVariant *propval = NULL; - GVariant *child = NULL; const gchar *state = NULL; NhmActiveState retval = NHM_ACTIVE_STATE_UNKNOWN; @@ -431,8 +430,7 @@ nhm_systemd_unit_get_active_state(NhmSystemdUnit *unit) if(error == NULL) { - child = g_variant_get_child_value(propval, 0); - state = g_variant_get_string(child, NULL); + g_variant_get_child(propval, 0, "&s", &state); retval = nhm_systemd_active_state_string_to_enum(state); g_variant_unref(propval); } @@ -476,7 +474,6 @@ nhm_systemd_unit_added(GDBusConnection *connection, { NhmSystemdUnit *unit = NULL; const gchar *param_type = NULL; - GVariant *child = NULL; NhmSystemdUnit search_unit; GSList *list_item = NULL; @@ -484,8 +481,7 @@ nhm_systemd_unit_added(GDBusConnection *connection, if(g_strcmp0(param_type, "(so)") == 0) { - child = g_variant_get_child_value(parameters, 0); - search_unit.name = (gchar*) g_variant_get_string(child, NULL); + g_variant_get_child(parameters, 0, "&s", &search_unit.name); if(g_str_has_suffix(search_unit.name, ".service") == TRUE) { @@ -497,8 +493,7 @@ nhm_systemd_unit_added(GDBusConnection *connection, unit = g_new(NhmSystemdUnit, 1); unit->name = g_strdup(search_unit.name); - child = g_variant_get_child_value(parameters, 1); - unit->path = g_variant_dup_string(child, NULL); + g_variant_get_child(parameters, 1, "s", &unit->path); unit->active_state = nhm_systemd_unit_get_active_state(unit); unit->sig_sub_id = nhm_systemd_subscribe_properties_changed(unit); @@ -548,15 +543,13 @@ nhm_systemd_unit_removed(GDBusConnection *connection, { GSList *list_item = NULL; const gchar *param_type = NULL; - GVariant *child = NULL; NhmSystemdUnit search_unit; param_type = g_variant_get_type_string(parameters); if(g_strcmp0(param_type, "(so)") == 0) { - child = g_variant_get_child_value(parameters, 0); - search_unit.name = (gchar*) g_variant_get_string(child, NULL); + g_variant_get_child(parameters, 0, "&s", &search_unit.name); if(g_str_has_suffix(search_unit.name, ".service") == TRUE) { @@ -620,8 +613,7 @@ nhm_systemd_unit_properties_changed(GDBusConnection *connection, if(g_strcmp0(param_type, "(sa{sv}as)") == 0) { - inv_props = g_variant_get_strv(g_variant_get_child_value(parameters, 2), - NULL); + g_variant_get_child(parameters, 2, "^a&s", &inv_props); if(nhm_helper_str_in_strv("ActiveState", (gchar**) inv_props) == TRUE) { @@ -810,8 +802,7 @@ nhm_systemd_connect(NhmSystemdAppStatusCb app_status_cb) new_unit = g_new(NhmSystemdUnit, 1); new_unit->name = unit_name; - active_state = - g_variant_get_string(g_variant_get_child_value(unit, 3), NULL); + g_variant_get_child(unit, 3, "&s", &active_state); new_unit->active_state = nhm_systemd_active_state_string_to_enum(active_state); @@ -830,6 +821,7 @@ nhm_systemd_connect(NhmSystemdAppStatusCb app_status_cb) } } + g_variant_unref(unit_array); g_variant_unref(manager_return); } else -- cgit v1.2.1