From 32c637b3417fc20da97e1de63a966480eb71f904 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 8 Nov 2013 11:23:15 -0600 Subject: fix a minor memory leak that was caused by treating the variant returned by g_icon_serialize() as floating. --- src/service.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/service.c b/src/service.c index a0c7fd1..488105f 100644 --- a/src/service.c +++ b/src/service.c @@ -342,7 +342,13 @@ create_header_state (IndicatorPowerService * self) if (icon != NULL) { - g_variant_builder_add (&b, "{sv}", "icon", g_icon_serialize (icon)); + GVariant * v; + + if ((v = g_icon_serialize (icon))) + { + g_variant_builder_add (&b, "{sv}", "icon", v); + g_variant_unref (v); + } g_object_unref (icon); } @@ -367,24 +373,28 @@ append_device_to_menu (GMenu * menu, const IndicatorPowerDevice * device) if (kind != UP_DEVICE_KIND_LINE_POWER) { - GIcon * icon; char * label; - GMenuItem * menu_item; + GMenuItem * item; + GIcon * icon; - icon = indicator_power_device_get_gicon (device); label = indicator_power_device_get_label (device); - menu_item = g_menu_item_new (label, "indicator.activate-statistics"); + item = g_menu_item_new (label, "indicator.activate-statistics"); + g_free (label); - if (icon != NULL) - g_menu_item_set_attribute_value (menu_item, - G_MENU_ATTRIBUTE_ICON, - g_icon_serialize (icon)); + if ((icon = indicator_power_device_get_gicon (device))) + { + GVariant * v; + if ((v = g_icon_serialize (icon))) + { + g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, v); + g_variant_unref (v); + } - g_menu_append_item (menu, menu_item); - g_object_unref (menu_item); + g_object_unref (icon); + } - g_clear_object (&icon); - g_free (label); + g_menu_append_item (menu, item); + g_object_unref (item); } } -- cgit v1.2.3