changeset 4108:dfe5d686749e

Fixes memory leak in mpris_emit_track_change() (Bugzilla #37)
author Jussi Judin <jjudin+audacious@iki.fi>
date Tue, 25 Dec 2007 00:46:07 -0600
parents db3f9b548226
children 2d6fd3f630f0
files src/audacious/dbus.c
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/dbus.c	Tue Dec 25 00:36:51 2007 -0600
+++ b/src/audacious/dbus.c	Tue Dec 25 00:46:07 2007 -0600
@@ -193,9 +193,7 @@
 
         val = g_new0(GValue, 1);
         g_value_init(val, G_TYPE_STRING);
-        g_value_set_string(val, result);
-
-        g_free(result);
+        g_value_take_string(val, result);
         return val;
     } else if (type == TUPLE_INT) {
         val = g_new0(GValue, 1);
@@ -206,6 +204,13 @@
     return NULL;
 }
 
+static void
+remove_metadata_value(gpointer value)
+{
+    g_value_unset((GValue*)value);
+    g_free((GValue*)value);
+}
+
 GHashTable *mpris_metadata_from_tuple(Tuple *tuple) {
     GHashTable *md = NULL;
     GValue *value;
@@ -213,7 +218,8 @@
     if (tuple == NULL)
         return NULL;
 
-    md = g_hash_table_new(g_str_hash, g_str_equal);
+    md = g_hash_table_new_full(g_str_hash, g_str_equal,
+                               NULL, remove_metadata_value);
 
     value = tuple_value_to_gvalue(tuple, "length");
     if (value != NULL) {
@@ -332,7 +338,7 @@
     // Song URI
     value = g_new0(GValue, 1);
     g_value_init(value, G_TYPE_STRING);
-    g_value_set_string(value, playlist_get_filename(active, pos));
+    g_value_take_string(value, playlist_get_filename(active, pos));
 
     g_hash_table_insert(md, "URI", value);
 
@@ -414,16 +420,18 @@
     metadata = mpris_metadata_from_tuple(tuple);
 
     if (!metadata)
-        metadata = g_hash_table_new(g_str_hash, g_str_equal);
+        metadata = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                         NULL, remove_metadata_value);
 
     // Song URI
     value = g_new0(GValue, 1);
     g_value_init(value, G_TYPE_STRING);
-    g_value_set_string(value, playlist_get_filename(active, pos));
+    g_value_take_string(value, playlist_get_filename(active, pos));
 
     g_hash_table_insert(metadata, "URI", value);
 
     g_signal_emit(obj, signals[TRACK_CHANGE_SIG], 0, metadata);
+    g_hash_table_destroy(metadata);
     return TRUE;
 }
 
@@ -453,7 +461,7 @@
     // Song URI
     value = g_new0(GValue, 1);
     g_value_init(value, G_TYPE_STRING);
-    g_value_set_string(value, playlist_get_filename(active, pos));
+    g_value_take_string(value, playlist_get_filename(active, pos));
 
     g_hash_table_insert(md, "URI", value);