aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-11-08 19:33:03 +0000
committerTarmac <Unknown>2013-11-08 19:33:03 +0000
commitc608bd8e8c0a80372189eaf2dc1a21224baf731e (patch)
tree6298fe9e2bb41cab74695c32737e7ba4bf6a831d
parentbde1f5daec555e59080ef2c3aeeb84f2fe3cd6b5 (diff)
parent32c637b3417fc20da97e1de63a966480eb71f904 (diff)
downloadayatana-indicator-power-c608bd8e8c0a80372189eaf2dc1a21224baf731e.tar.gz
ayatana-indicator-power-c608bd8e8c0a80372189eaf2dc1a21224baf731e.tar.bz2
ayatana-indicator-power-c608bd8e8c0a80372189eaf2dc1a21224baf731e.zip
fix a minor memory leak that was caused by treating the variant returned by g_icon_serialize() as floating.
Approved by Ted Gould, PS Jenkins bot.
-rw-r--r--src/service.c36
1 files 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);
}
}