changeset 813:c8cf439179b8 trunk

[svn] - Fix a ton and a half of memory leaks, via the wonderful Leonardo Boshell <leonardop -at- gentoo.org>.
author nenolod
date Fri, 10 Mar 2006 08:20:15 -0800
parents f9a1ddb72432
children 0767a750cd4f
files Plugins/General/scrobbler/scrobbler.c Plugins/General/scrobbler/xmms_scrobbler.c Plugins/Input/adplug/adplug-xmms.cc Plugins/Input/adplug/core/dmo.cpp Plugins/Input/cdaudio/cdaudio.c Plugins/Input/flac/plugin.c Plugins/Input/flac/plugin_common/charset.c Plugins/Input/mpg123/mpg123.c Plugins/Input/timidity/src/xmms-timidity.c Plugins/Input/vorbis/vorbis.c Plugins/Output/OSS/OSS.c Plugins/Output/OSS/OSS.h Plugins/Output/alsa/alsa.c Plugins/Output/alsa/alsa.h Plugins/Output/alsa/init.c Plugins/Visualization/blur_scope/blur_scope.c audacious/main.c audacious/mainwin.c audacious/mainwin.h audacious/playlist_list.c audacious/skin.c audacious/util.c libaudacious/configdb_gconf.c
diffstat 23 files changed, 230 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/General/scrobbler/scrobbler.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/General/scrobbler/scrobbler.c	Fri Mar 10 08:20:15 2006 -0800
@@ -631,6 +631,7 @@
 		i++;
 	}
 	pdebug("Done loading cache.", DEBUG);
+	free(cache);
 }
 
 static void dump_queue(void)
--- a/Plugins/General/scrobbler/xmms_scrobbler.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/General/scrobbler/xmms_scrobbler.c	Fri Mar 10 08:20:15 2006 -0800
@@ -88,6 +88,9 @@
 
 static void cleanup(void)
 {
+    g_free (xmms_scrobbler.description);
+    xmms_scrobbler.description = NULL;
+
 	if (!going)
 		return;
 	pdebug("about to lock mutex", DEBUG);
--- a/Plugins/Input/adplug/adplug-xmms.cc	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/adplug/adplug-xmms.cc	Fri Mar 10 08:20:15 2006 -0800
@@ -833,6 +833,7 @@
       strcat(userdb, ADPLUGDB_FILE);
       plr.db->load(userdb);		// load user's database
       dbg_printf(" (userdb=\"%s\")", userdb);
+      free(userdb);
     }
   }
   CAdPlug::set_database(plr.db);
--- a/Plugins/Input/adplug/core/dmo.cpp	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/adplug/core/dmo.cpp	Fri Mar 10 08:20:15 2006 -0800
@@ -55,12 +55,12 @@
   binistream *f;
 
   // check header
+  if(!fp.extension(filename, ".dmo")) return false;
+  f = fp.open(filename); if(!f) return false;
+
   dmo_unpacker *unpacker = new dmo_unpacker;
   unsigned char chkhdr[16];
 
-  if(!fp.extension(filename, ".dmo")) return false;
-  f = fp.open(filename); if(!f) return false;
-
   f->readString((char *)chkhdr, 16);
 
   if (!unpacker->decrypt(chkhdr, 16))
--- a/Plugins/Input/cdaudio/cdaudio.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/cdaudio/cdaudio.c	Fri Mar 10 08:20:15 2006 -0800
@@ -28,6 +28,7 @@
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <unistd.h>
 #include <errno.h>
@@ -765,6 +766,46 @@
 static void
 cleanup(void)
 {
+    GList *node;
+    struct driveinfo *drive;
+
+    g_free(cdda_ip.description);
+    cdda_ip.description = NULL;
+
+    if (cdda_cfg.drives) {
+        for (node = g_list_first(cdda_cfg.drives); node; node = node->next) {
+            drive = (struct driveinfo *)node->data;
+            if (!drive)
+                continue;
+
+            if (drive->device)
+                free(drive->device);
+
+            if (drive->directory)
+                free(drive->directory);
+
+            free(drive);
+        }
+
+        g_list_free(cdda_cfg.drives);
+        cdda_cfg.drives = NULL;
+    }
+
+    if (cdda_cfg.name_format) {
+        free(cdda_cfg.name_format);
+        cdda_cfg.name_format = NULL;
+    }
+
+    if (cdda_cfg.cddb_server) {
+        free(cdda_cfg.cddb_server);
+        cdda_cfg.cddb_server = NULL;
+    }
+
+    if (cdda_cfg.cdin_server) {
+        free(cdda_cfg.cdin_server);
+        cdda_cfg.cdin_server = NULL;
+    }
+
     while (timeout_list) {
         struct timeout *t = timeout_list->data;
         gtk_timeout_remove(t->id);
--- a/Plugins/Input/flac/plugin.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/flac/plugin.c	Fri Mar 10 08:20:15 2006 -0800
@@ -136,7 +136,7 @@
 {
 	NULL,
 	NULL,
-	"FLAC Player v" PACKAGE_VERSION,
+	NULL,
 	FLAC_XMMS__init,
 	FLAC_XMMS__aboutbox,
 	FLAC_XMMS__configure,
@@ -220,9 +220,7 @@
 
 	is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true;
 
-	flac_cfg.title.tag_override = FALSE;
-	g_free(flac_cfg.title.tag_format);
-	flac_cfg.title.convert_char_set = FALSE;
+	memset(&flac_cfg, 0, sizeof(flac_cfg));
 
 	db = bmp_cfg_db_open();
 
@@ -417,6 +415,35 @@
 
 void FLAC_XMMS__cleanup()
 {
+    g_free(flac_ip.description);
+    flac_ip.description = NULL;
+
+    if (flac_cfg.title.tag_format) {
+        free(flac_cfg.title.tag_format);
+        flac_cfg.title.tag_format = NULL;
+    }
+
+    if (flac_cfg.title.user_char_set) {
+        free(flac_cfg.title.user_char_set);
+        flac_cfg.title.user_char_set = NULL;
+    }
+
+    if (flac_cfg.stream.proxy_host) {
+        free(flac_cfg.stream.proxy_host);
+        flac_cfg.stream.proxy_host = NULL;
+    }
+
+    if (flac_cfg.stream.proxy_user) {
+        free(flac_cfg.stream.proxy_user);
+        flac_cfg.stream.proxy_user = NULL;
+
+    }
+
+    if (flac_cfg.stream.proxy_pass) {
+        free(flac_cfg.stream.proxy_pass);
+        flac_cfg.stream.proxy_pass = NULL;
+    }
+
 	decoder_func_table_ -> safe_decoder_delete(decoder_);
 	decoder_ = 0;
 }
--- a/Plugins/Input/flac/plugin_common/charset.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/flac/plugin_common/charset.c	Fri Mar 10 08:20:15 2006 -0800
@@ -52,10 +52,11 @@
 	if (!charset)
 		charset = nl_langinfo(CODESET);
 #endif
-	if (!charset)
-		charset = "ISO-8859-1";
 
-	return charset;
+    if (charset)
+        return strdup(charset);
+
+    return strdup("ISO-8859-1");
 }
 
 
--- a/Plugins/Input/mpg123/mpg123.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/mpg123/mpg123.c	Fri Mar 10 08:20:15 2006 -0800
@@ -148,6 +148,8 @@
 
     mpg123_make_decode_tables(outscale);
 
+    memset(&mpg123_cfg, 0, sizeof(mpg123_cfg));
+
     mpg123_cfg.resolution = 16;
     mpg123_cfg.channels = 2;
     mpg123_cfg.downsample = 0;
@@ -221,6 +223,39 @@
 static void
 cleanup(void)
 {
+    g_free(mpg123_ip.description);
+    mpg123_ip.description = NULL;
+
+    if (mpg123_cfg.save_http_path) {
+        free(mpg123_cfg.save_http_path);
+        mpg123_cfg.save_http_path = NULL;
+    }
+
+    if (mpg123_cfg.proxy_host) {
+        free(mpg123_cfg.proxy_host);
+        mpg123_cfg.proxy_host = NULL;
+    }
+
+    if (mpg123_cfg.proxy_user) {
+        free(mpg123_cfg.proxy_user);
+        mpg123_cfg.proxy_user = NULL;
+    }
+
+    if (mpg123_cfg.proxy_pass) {
+        free(mpg123_cfg.proxy_pass);
+        mpg123_cfg.proxy_pass = NULL;
+    }
+
+    if (mpg123_cfg.id3_format) {
+        free(mpg123_cfg.id3_format);
+        mpg123_cfg.id3_format = NULL;
+    }
+
+    if (mpg123_cfg.title_encoding) {
+        free(mpg123_cfg.title_encoding);
+        mpg123_cfg.title_encoding = NULL;
+    }
+
     g_strfreev(mpg123_id3_encoding_list);
 }
 
--- a/Plugins/Input/timidity/src/xmms-timidity.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/timidity/src/xmms-timidity.c	Fri Mar 10 08:20:15 2006 -0800
@@ -103,7 +103,7 @@
 void xmmstimid_init(void) {
 	ConfigDb *db;
 
-	xmmstimid_cfg.config_file = g_strdup("/etc/timidity.cfg");
+	xmmstimid_cfg.config_file = NULL;
 	xmmstimid_cfg.rate = 44100;
 	xmmstimid_cfg.bits = 16;
 	xmmstimid_cfg.channels = 2;
@@ -111,7 +111,10 @@
 
 	db = bmp_cfg_db_open();
 
-	bmp_cfg_db_get_string(db, "timidity", "config_file", &xmmstimid_cfg.config_file);
+	if (! bmp_cfg_db_get_string(db, "timidity", "config_file",
+                                &xmmstimid_cfg.config_file))
+        xmmstimid_cfg.config_file = g_strdup("/etc/timidity.cfg");
+
 	bmp_cfg_db_get_int(db, "timidity", "samplerate", &xmmstimid_cfg.rate);
 	bmp_cfg_db_get_int(db, "timidity", "bits", &xmmstimid_cfg.bits);
 	bmp_cfg_db_get_int(db, "timidity", "channels", &xmmstimid_cfg.channels);
@@ -203,10 +206,6 @@
 void xmmstimid_conf_ok(GtkButton *button, gpointer user_data) {
 	ConfigDb *db;
 
-	g_free(xmmstimid_cfg.config_file);
-	xmmstimid_cfg.config_file = g_strdup(
-			gtk_entry_get_text(xmmstimid_conf_config_file));
-
 	if (gtk_toggle_button_get_active(xmmstimid_conf_rate_11000))
 		xmmstimid_cfg.rate = 11000;
 	else if (gtk_toggle_button_get_active(xmmstimid_conf_rate_22000))
@@ -224,7 +223,12 @@
 
 	db = bmp_cfg_db_open();
 
+	g_free(xmmstimid_cfg.config_file);
+	xmmstimid_cfg.config_file = g_strdup(
+        gtk_entry_get_text(xmmstimid_conf_config_file));
+
 	bmp_cfg_db_set_string(db, "timidity", "config_file", xmmstimid_cfg.config_file);
+
 	bmp_cfg_db_set_int(db, "timidity", "samplerate", xmmstimid_cfg.rate);
 	bmp_cfg_db_set_int(db, "timidity", "bits", xmmstimid_cfg.bits);
 	bmp_cfg_db_set_int(db, "timidity", "channels", xmmstimid_cfg.channels);
@@ -411,6 +415,14 @@
 }
 
 void xmmstimid_cleanup(void) {
+	g_free(xmmstimid_ip.description);
+	xmmstimid_ip.description = NULL;
+
+	if (xmmstimid_cfg.config_file) {
+		free(xmmstimid_cfg.config_file);
+		xmmstimid_cfg.config_file = NULL;
+	}
+
 	if (xmmstimid_initialized)
 		mid_exit();
 }
--- a/Plugins/Input/vorbis/vorbis.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Input/vorbis/vorbis.c	Fri Mar 10 08:20:15 2006 -0800
@@ -907,6 +907,39 @@
 static void
 vorbis_cleanup(void)
 {
+    g_free(vorbis_ip.description);
+    vorbis_ip.description = NULL;
+
+    if (vorbis_cfg.save_http_path) {
+        free(vorbis_cfg.save_http_path);
+        vorbis_cfg.save_http_path = NULL;
+    }
+
+    if (vorbis_cfg.proxy_host) {
+        free(vorbis_cfg.proxy_host);
+        vorbis_cfg.proxy_host = NULL;
+    }
+
+    if (vorbis_cfg.proxy_user) {
+        free(vorbis_cfg.proxy_user);
+        vorbis_cfg.proxy_user = NULL;
+    }
+
+    if (vorbis_cfg.proxy_pass) {
+        free(vorbis_cfg.proxy_pass);
+        vorbis_cfg.proxy_pass = NULL;
+    }
+
+    if (vorbis_cfg.tag_format) {
+        free(vorbis_cfg.tag_format);
+        vorbis_cfg.tag_format = NULL;
+    }
+
+    if (vorbis_cfg.title_encoding) {
+        free(vorbis_cfg.title_encoding);
+        vorbis_cfg.title_encoding = NULL;
+    }
+
     g_strfreev(vorbis_tag_encoding_list);
     g_mutex_free(vf_mutex);
 }
--- a/Plugins/Output/OSS/OSS.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Output/OSS/OSS.c	Fri Mar 10 08:20:15 2006 -0800
@@ -23,13 +23,14 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <stdlib.h>
 
 OutputPlugin oss_op = {
     NULL,
     NULL,
     NULL,                       /* Description */
     oss_init,
-    NULL,
+    oss_cleanup,
     oss_about,
     oss_configure,
     oss_get_volume,
@@ -52,3 +53,20 @@
     oss_op.description = g_strdup_printf(_("OSS Output Plugin"));
     return &oss_op;
 }
+
+
+void oss_cleanup(void)
+{
+    g_free(oss_op.description);
+    oss_op.description = NULL;
+
+    if (oss_cfg.alt_audio_device) {
+        free(oss_cfg.alt_audio_device);
+        oss_cfg.alt_audio_device = NULL;
+    }
+
+    if (oss_cfg.alt_mixer_device) {
+        free(oss_cfg.alt_mixer_device);
+        oss_cfg.alt_mixer_device = NULL;
+    }
+}
--- a/Plugins/Output/OSS/OSS.h	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Output/OSS/OSS.h	Fri Mar 10 08:20:15 2006 -0800
@@ -48,6 +48,7 @@
 extern OSSConfig oss_cfg;
 
 void oss_init(void);
+void oss_cleanup(void);
 void oss_about(void);
 void oss_configure(void);
 
--- a/Plugins/Output/alsa/alsa.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Output/alsa/alsa.c	Fri Mar 10 08:20:15 2006 -0800
@@ -17,6 +17,7 @@
  */
 
 #include "alsa.h"
+#include <stdlib.h>
 
 OutputPlugin alsa_op =
 {
@@ -24,7 +25,7 @@
 	NULL,
 	NULL,
 	alsa_init,
-	NULL,
+	alsa_cleanup,
 	alsa_about,
 	alsa_configure,
 	alsa_get_volume,
@@ -46,3 +47,20 @@
 	alsa_op.description = g_strdup_printf(_("ALSA %s output plugin"), VERSION);
 	return &alsa_op;
 }
+
+
+void alsa_cleanup(void)
+{
+	g_free(alsa_op.description);
+	alsa_op.description = NULL;
+
+	if (alsa_cfg.pcm_device) {
+		free(alsa_cfg.pcm_device);
+		alsa_cfg.pcm_device = NULL;
+	}
+
+	if (alsa_cfg.mixer_device) {
+		free(alsa_cfg.mixer_device);
+		alsa_cfg.mixer_device = NULL;
+	}
+}
--- a/Plugins/Output/alsa/alsa.h	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Output/alsa/alsa.h	Fri Mar 10 08:20:15 2006 -0800
@@ -62,6 +62,7 @@
 extern struct alsa_config alsa_cfg;
 
 void alsa_init(void);
+void alsa_cleanup(void);
 void alsa_about(void);
 void alsa_configure(void);
 int alsa_get_mixer(snd_mixer_t **mixer, int card);
--- a/Plugins/Output/alsa/init.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Output/alsa/init.c	Fri Mar 10 08:20:15 2006 -0800
@@ -54,7 +54,7 @@
 	alsa_cfg.thread_buffer_time = CLAMP(alsa_cfg.thread_buffer_time,
 					    THREAD_BUFFER_TIME_MIN,
 					    THREAD_BUFFER_TIME_MAX);
-	
+
 	bmp_cfg_db_get_bool(cfgfile, "ALSA", "soft_volume",
 			      &alsa_cfg.soft_volume);
 	bmp_cfg_db_get_int(cfgfile, "ALSA", "volume_left", &alsa_cfg.vol.left);
--- a/Plugins/Visualization/blur_scope/blur_scope.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/Plugins/Visualization/blur_scope/blur_scope.c	Fri Mar 10 08:20:15 2006 -0800
@@ -226,6 +226,8 @@
 static void
 bscope_cleanup(void)
 {
+    g_free(bscope_vp.description);
+    bscope_vp.description = NULL;
     if (window)
         gtk_widget_destroy(window);
     if (bg_pixmap) {
--- a/audacious/main.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/main.c	Fri Mar 10 08:20:15 2006 -0800
@@ -907,9 +907,10 @@
 {
     fprintf(stderr,error_text);
 	if (options.headless!=1) {
-        gtk_message_dialog_format_secondary_text(err,error_text);
+        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(err),
+                                                 error_text);
         gtk_dialog_run(GTK_DIALOG(err));
-        gtk_widget_hide(GTK_WIDGET(err));
+        gtk_widget_hide(err);
     }
 }
 
--- a/audacious/mainwin.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/mainwin.c	Fri Mar 10 08:20:15 2006 -0800
@@ -161,7 +161,7 @@
 
 
 GtkWidget *mainwin = NULL;
-GtkMessageDialog *err = NULL; /* an error dialog for miscellaneous error messages */
+GtkWidget *err = NULL; /* an error dialog for miscellaneous error messages */
 
 static GdkBitmap *nullmask;
 static gint balance;
@@ -1390,6 +1390,7 @@
 
     gtk_tree_model_get(model, &iter, 0, &pos_str, -1);
     pos = g_ascii_strtoull(pos_str, NULL, 10) - 1;
+    g_free(pos_str);
 
     change_song(pos);
 
@@ -1461,6 +1462,7 @@
 
     gtk_tree_model_get(model, &iter, 0, &pos_str, -1);
     pos = g_ascii_strtoull(pos_str, NULL, 10) - 1;
+    g_free(pos_str);
 
     mainwin_jump_to_file_set_queue_button_label(GTK_BUTTON(data), pos);
 }
@@ -3152,9 +3154,9 @@
 
 
     gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER);
-    gtk_label_set_line_wrap(GTK_LABEL(err->label), TRUE);
     /* Dang well better set an error message or you'll see this */
-    gtk_message_dialog_format_secondary_text(err,"Boo! Bad stuff! Booga Booga!");
+    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(err),
+                                             "Boo! Bad stuff! Booga Booga!");
 
 }
 
--- a/audacious/mainwin.h	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/mainwin.h	Fri Mar 10 08:20:15 2006 -0800
@@ -93,7 +93,7 @@
 };
 
 extern GtkWidget *mainwin;
-extern GtkMessageDialog *err;
+extern GtkWidget *err;
 extern GdkGC *mainwin_gc;
 
 extern GtkAccelGroup *mainwin_accel;
--- a/audacious/playlist_list.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/playlist_list.c	Fri Mar 10 08:20:15 2006 -0800
@@ -753,15 +753,12 @@
 
     }
 
-    playlist_rect->x = 0;
-    playlist_rect->y = 0;
-    playlist_rect->width = plw_w;
-    playlist_rect->height = plw_h;
-
     gdk_gc_set_clip_origin(gc, 0, 0);
     gdk_gc_set_clip_rectangle(gc, NULL);
 
     PLAYLIST_UNLOCK();
+    
+    g_free(playlist_rect);
 }
 
 
--- a/audacious/skin.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/skin.c	Fri Mar 10 08:20:15 2006 -0800
@@ -726,15 +726,16 @@
     if (filename && cfg.custom_cursors)	{
     	cursor_animated = gdk_pixbuf_animation_new_from_file(filename, &error);
         cursor_pixbuf = gdk_pixbuf_animation_get_static_image(cursor_animated);
-	cursor_gdk = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
+        cursor_gdk = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
                                                 cursor_pixbuf, 0, 0);
     } else {
-	cursor_gdk = gdk_cursor_new(GDK_LEFT_PTR);
+        cursor_gdk = gdk_cursor_new(GDK_LEFT_PTR);
     }
 
     gdk_window_set_cursor(mainwin->window, cursor_gdk);
     gdk_window_set_cursor(playlistwin->window, cursor_gdk);
     gdk_window_set_cursor(equalizerwin->window, cursor_gdk);
+    gdk_cursor_unref(cursor_gdk);
 }
 
 static void
--- a/audacious/util.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/audacious/util.c	Fri Mar 10 08:20:15 2006 -0800
@@ -1044,9 +1044,10 @@
 
     if (!window) {
         if (cursor) {
-            gdk_cursor_destroy(cursor);
+            gdk_cursor_unref(cursor);
             cursor = NULL;
         }
+
         return;
     }
 
--- a/libaudacious/configdb_gconf.c	Thu Mar 09 19:09:41 2006 -0800
+++ b/libaudacious/configdb_gconf.c	Fri Mar 10 08:20:15 2006 -0800
@@ -43,6 +43,7 @@
 bmp_cfg_db_close(ConfigDb * db)
 {
     g_object_unref(db->client);
+    g_free(db);
 }
 
 static gchar *