[PATCH 08/10] daemon: fix various reference leaks

Peter Wu peter at lekensteyn.nl
Wed Nov 26 03:21:15 PST 2014


up_daemon_get_daemon takes a reference on UpDaemon, so it must be
properly dereferenced. Similar for up_daemon_get_devices_list which
references an UpDeviceList.

The display device was allocated in init, but never released either.

https://bugs.freedesktop.org/show_bug.cgi?id=82659
---
 src/linux/up-device-supply.c |  5 ++++-
 src/up-daemon.c              | 11 +++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index ad86ede..94bc615 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -511,6 +511,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
 	gboolean ac_online = FALSE;
 	gboolean has_ac = FALSE;
 	gboolean online;
+	UpDeviceList *devices_list;
 	GPtrArray *devices;
 	guint i;
 
@@ -699,7 +700,8 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
 
 		/* If we have any online AC, assume charging, otherwise
 		 * discharging */
-		devices = up_device_list_get_array (up_daemon_get_device_list (daemon));
+		devices_list = up_daemon_get_device_list (daemon);
+		devices = up_device_list_get_array (devices_list);
 		for (i=0; i < devices->len; i++) {
 			if (up_device_get_online ((UpDevice *) g_ptr_array_index (devices, i), &online)) {
 			       has_ac = TRUE;
@@ -710,6 +712,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
 			}
 		}
 		g_ptr_array_unref (devices);
+		g_object_unref (devices_list);
 
 		if (has_ac) {
 			if (ac_online) {
diff --git a/src/up-daemon.c b/src/up-daemon.c
index d6420fc..c795c93 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -897,6 +897,7 @@ change_idle_timeout (UpDevice   *device,
 
 	up_daemon_stop_poll (G_OBJECT (device));
 	up_daemon_start_poll (G_OBJECT (device), callback);
+	g_object_unref (daemon);
 }
 
 static void
@@ -930,6 +931,7 @@ fire_timeout_callback (gpointer user_data)
 
 	/* Fire the actual callback */
 	(data->callback) (device);
+	g_object_unref (daemon);
 
 	return G_SOURCE_CONTINUE;
 }
@@ -962,7 +964,7 @@ up_daemon_start_poll (GObject     *object,
 	if (g_hash_table_lookup (daemon->priv->poll_timeouts, device) != NULL) {
 		g_warning ("Poll already started for device '%s'",
 			   up_device_get_object_path (device));
-		return;
+		goto out;
 	}
 
 	data = g_new0 (TimeoutData, 1);
@@ -987,6 +989,8 @@ up_daemon_start_poll (GObject     *object,
 
 	g_debug ("Setup poll for '%s' every %u seconds",
 		 up_device_get_object_path (device), timeout);
+out:
+	g_object_unref (daemon);
 }
 
 void
@@ -1011,11 +1015,13 @@ up_daemon_stop_poll (GObject *object)
 
 	data = g_hash_table_lookup (daemon->priv->poll_timeouts, device);
 	if (data == NULL)
-		return;
+		goto out;
 
 	g_source_remove (data->id);
 	g_object_weak_unref (object, device_destroyed, daemon);
 	g_hash_table_remove (daemon->priv->poll_timeouts, device);
+out:
+	g_object_unref (daemon);
 }
 
 /**
@@ -1304,6 +1310,7 @@ up_daemon_finalize (GObject *object)
 	if (priv->connection != NULL)
 		dbus_g_connection_unref (priv->connection);
 	g_object_unref (priv->power_devices);
+	g_object_unref (priv->display_device);
 	g_object_unref (priv->config);
 	g_object_unref (priv->backend);
 
-- 
2.1.3



More information about the devkit-devel mailing list