changeset 4109:2d6fd3f630f0

Adds playback_free() function to fix memory leak in playback_stop(). (Bugzilla #42)
author Jussi Judin <jjudin+audacious@iki.fi>
date Tue, 25 Dec 2007 00:53:33 -0600
parents dfe5d686749e
children d5d4590cb7d2
files src/audacious/playback.c src/audacious/playback.h src/audacious/plugin.h
diffstat 3 files changed, 25 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playback.c	Tue Dec 25 00:46:07 2007 -0600
+++ b/src/audacious/playback.c	Tue Dec 25 00:53:33 2007 -0600
@@ -311,13 +311,7 @@
         free_vis_data();
         ip_data.paused = FALSE;
 
-        if (playback->pb_ready_mutex)
-            g_mutex_free(playback->pb_ready_mutex);
-        if (playback->pb_ready_cond)
-            g_cond_free(playback->pb_ready_cond);
-
-        g_free(playback->filename);
-        g_slice_free(InputPlayback, playback);
+        playback_free(playback);
         set_current_input_playback(NULL);
 #ifdef USE_DBUS
         mpris_emit_status_change(mpris, MPRIS_STATUS_STOP);
@@ -396,6 +390,27 @@
     return playback;
 }
 
+/**
+ * Destroys InputPlayback.
+ *
+ * Playback comes from playback_new() function but there can be also
+ * other sources for allocated playback data (like filename and title)
+ * and this tries to deallocate all that data.
+ */
+void playback_free(InputPlayback *playback)
+{
+    g_free(playback->filename);
+    g_free(playback->title);
+
+    g_mutex_free(playback->pb_ready_mutex);
+    g_cond_free(playback->pb_ready_cond);
+
+    g_mutex_free(playback->pb_change_mutex);
+    g_cond_free(playback->pb_change_cond);
+
+    g_slice_free(InputPlayback, playback);
+}
+
 void
 playback_run(InputPlayback *playback)
 {
--- a/src/audacious/playback.h	Tue Dec 25 00:46:07 2007 -0600
+++ b/src/audacious/playback.h	Tue Dec 25 00:53:33 2007 -0600
@@ -41,6 +41,7 @@
 void playback_eof(void);
 void playback_error(void);
 InputPlayback *playback_new(void);
+void playback_free(InputPlayback *);
 void playback_run(InputPlayback *);
 
 #endif
--- a/src/audacious/plugin.h	Tue Dec 25 00:46:07 2007 -0600
+++ b/src/audacious/plugin.h	Tue Dec 25 00:53:33 2007 -0600
@@ -565,6 +565,7 @@
 
     /* InputPlayback */
     InputPlayback *(*playback_new)(void);
+    void (*playback_free)(InputPlayback *);
     void (*playback_run)(InputPlayback *);
 
     /* Flows */
@@ -911,7 +912,7 @@
 
 #define aud_playback_new			_audvt->playback_new
 #define aud_playback_run			_audvt->playback_run
-#define aud_playback_free(x)			g_slice_free(InputPlayback, (x))
+#define aud_playback_free(x)			_audvt->playback_free
 
 #define aud_flow_execute			_audvt->flow_execute
 #define aud_flow_new				_audvt->flow_new