← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/dbusmenu/mem-leaks into lp:dbusmenu

 

Ted Gould has proposed merging lp:~ted/dbusmenu/mem-leaks into lp:dbusmenu.

Requested reviews:
  DBus Menu Team (dbusmenu-team)

For more details, see:
https://code.launchpad.net/~ted/dbusmenu/mem-leaks/+merge/47083

Taking the heart of a patch attached to bug 690668 by hyperair.  It didn't apply, but I think I found parts that still were issues by using it as a guide.
-- 
https://code.launchpad.net/~ted/dbusmenu/mem-leaks/+merge/47083
Your team ayatana-commits is subscribed to branch lp:dbusmenu.
=== modified file 'libdbusmenu-glib/client.c'
--- libdbusmenu-glib/client.c	2011-01-19 14:55:37 +0000
+++ libdbusmenu-glib/client.c	2011-01-21 19:38:10 +0000
@@ -517,6 +517,7 @@
 			listener->callback(NULL, error, listener->user_data);
 		}
 		g_array_free(listeners, TRUE);
+		g_error_free(error);
 		return;
 	}
 
@@ -1140,7 +1141,6 @@
 	if (error != NULL) {
 		g_warning("Error getting properties on a new menuitem: %s", error->message);
 		g_object_unref(propdata->item);
-		g_free(data);
 		return;
 	}
 
@@ -1277,6 +1277,8 @@
 		g_warning("Unable to send about_to_show: %s", error->message);
 		/* Note: we're just ensuring only the callback gets called */
 		need_update = FALSE;
+		g_error_free(error);
+		error = NULL;
 	} else {
 		g_variant_get(params, "(b)", &need_update);
 		g_variant_unref(params);
@@ -1553,6 +1555,7 @@
 
 	if (error != NULL) {
 		g_warning("Getting layout failed: %s", error->message);
+		g_error_free(error);
 		return;
 	}
 

=== modified file 'libdbusmenu-glib/menuitem.c'
--- libdbusmenu-glib/menuitem.c	2011-01-07 05:25:02 +0000
+++ libdbusmenu-glib/menuitem.c	2011-01-21 19:38:10 +0000
@@ -1204,11 +1204,17 @@
 	return g_hash_table_get_keys(priv->properties);
 }
 
+/* Copy the keys and make references to the variants that are
+   in the new table.  They'll be free'd and unref'd when the
+   Hashtable gets destroyed. */
 static void
 copy_helper (gpointer in_key, gpointer in_value, gpointer in_data)
 {
 	GHashTable * table = (GHashTable *)in_data;
-	g_hash_table_insert(table, in_key, in_value);
+	gchar * key = (gchar *)in_key;
+	GVariant * value = (GVariant *)in_value;
+	g_variant_ref(value);
+	g_hash_table_insert(table, g_strdup(key), value);
 	return;
 }
 
@@ -1229,7 +1235,7 @@
 GHashTable *
 dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi)
 {
-	GHashTable * ret = g_hash_table_new(g_str_hash, g_str_equal);
+	GHashTable * ret = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _g_variant_unref);
 
 	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), ret);
 


Follow ups