summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-11-06 18:50:30 +0100
committerRichard Hughes <richard@hughsie.com>2014-11-26 11:56:08 +0000
commit8988f069862a588d4c48afc703f500037cb0c50a (patch)
treee3062a56bb27d082e1c3ca9585c49833b3168496
parentf3dfc1ea8337aa3ff12e9df71013b315e206efc5 (diff)
downloadupower-8988f069862a588d4c48afc703f500037cb0c50a.tar.gz
daemon: fix memleaks in GetStatistics and GetHistory
dbus_g_method_return[_error] does not claim the passed parameters, the caller must free it theirselves. complex is filled with an GValueArray pointer (see UP_DBUS_STRUCT_DOUBLE_DOUBLE) but its contents are not freed (memleak!). This patch introduces a deprecation warning due to the use g_value_array_free, but since UP_DBUS_STRUCT_DOUBLE_DOUBLE is a GValueArray, this is unavoidable. https://bugs.freedesktop.org/show_bug.cgi?id=82659
-rw-r--r--src/up-device.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/up-device.c b/src/up-device.c
index caccb3a..685be80 100644
--- a/src/up-device.c
+++ b/src/up-device.c
@@ -743,7 +743,7 @@ up_device_register_display_device (UpDevice *device,
gboolean
up_device_get_statistics (UpDevice *device, const gchar *type, DBusGMethodInvocation *context)
{
- GError *error;
+ GError *error = NULL;
GPtrArray *array = NULL;
GPtrArray *complex;
UpStatsItem *item;
@@ -781,7 +781,7 @@ up_device_get_statistics (UpDevice *device, const gchar *type, DBusGMethodInvoca
}
/* copy data to dbus struct */
- complex = g_ptr_array_sized_new (array->len);
+ complex = g_ptr_array_new_full (array->len, (GDestroyNotify) g_value_array_free);
for (i=0; i<array->len; i++) {
item = (UpStatsItem *) g_ptr_array_index (array, i);
value = g_new0 (GValue, 1);
@@ -789,15 +789,19 @@ up_device_get_statistics (UpDevice *device, const gchar *type, DBusGMethodInvoca
g_value_take_boxed (value, dbus_g_type_specialized_construct (UP_DBUS_STRUCT_DOUBLE_DOUBLE));
dbus_g_type_struct_set (value,
0, up_stats_item_get_value (item),
- 1, up_stats_item_get_accuracy (item), -1);
+ 1, up_stats_item_get_accuracy (item),
+ G_MAXUINT);
g_ptr_array_add (complex, g_value_get_boxed (value));
g_free (value);
}
dbus_g_method_return (context, complex);
+ g_ptr_array_unref (complex);
out:
if (array != NULL)
g_ptr_array_unref (array);
+ if (error != NULL)
+ g_error_free (error);
return TRUE;
}
@@ -807,7 +811,7 @@ out:
gboolean
up_device_get_history (UpDevice *device, const gchar *type_string, guint timespan, guint resolution, DBusGMethodInvocation *context)
{
- GError *error;
+ GError *error = NULL;
GPtrArray *array = NULL;
GPtrArray *complex;
UpHistoryItem *item;
@@ -847,7 +851,7 @@ up_device_get_history (UpDevice *device, const gchar *type_string, guint timespa
}
/* copy data to dbus struct */
- complex = g_ptr_array_sized_new (array->len);
+ complex = g_ptr_array_new_full (array->len, (GDestroyNotify) g_value_array_free);
for (i=0; i<array->len; i++) {
item = (UpHistoryItem *) g_ptr_array_index (array, i);
value = g_new0 (GValue, 1);
@@ -856,15 +860,19 @@ up_device_get_history (UpDevice *device, const gchar *type_string, guint timespa
dbus_g_type_struct_set (value,
0, up_history_item_get_time (item),
1, up_history_item_get_value (item),
- 2, up_history_item_get_state (item), -1);
+ 2, up_history_item_get_state (item),
+ G_MAXUINT);
g_ptr_array_add (complex, g_value_get_boxed (value));
g_free (value);
}
dbus_g_method_return (context, complex);
+ g_ptr_array_unref (complex);
out:
if (array != NULL)
g_ptr_array_unref (array);
+ if (error != NULL)
+ g_error_free (error);
return TRUE;
}