aboutsummaryrefslogtreecommitdiff
path: root/src/service.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-11-08 11:23:15 -0600
committerCharles Kerr <charles.kerr@canonical.com>2013-11-08 11:23:15 -0600
commit32c637b3417fc20da97e1de63a966480eb71f904 (patch)
tree6298fe9e2bb41cab74695c32737e7ba4bf6a831d /src/service.c
parentbde1f5daec555e59080ef2c3aeeb84f2fe3cd6b5 (diff)
downloadayatana-indicator-power-32c637b3417fc20da97e1de63a966480eb71f904.tar.gz
ayatana-indicator-power-32c637b3417fc20da97e1de63a966480eb71f904.tar.bz2
ayatana-indicator-power-32c637b3417fc20da97e1de63a966480eb71f904.zip
fix a minor memory leak that was caused by treating the variant returned by g_icon_serialize() as floating.
Diffstat (limited to 'src/service.c')
-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);
}
}