summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-02 18:45:49 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-02 18:45:49 +0200
commit91e6c9743f449c64351fff801e2abd528ebdcd4b (patch)
tree3c430727d2b6ae8bee9bf6cff70da306da7deb3c
parentab9f5abcf64ed36193f270d621c06c4b8fd5e82d (diff)
fixed ton of memleaks and memory-related crashes
-rw-r--r--cdumb.c1
-rw-r--r--cgme.c1
-rw-r--r--junklib.c6
-rw-r--r--playlist.c23
-rw-r--r--plugins/adplug/adplug-db.cpp1
-rw-r--r--plugins/cdda/cdda.c18
-rw-r--r--plugins/ffap/ffap.c7
-rw-r--r--plugins/ffmpeg/ffmpeg.c1
-rw-r--r--plugins/flac/flac.c1
-rw-r--r--plugins/gtkui/ddblistview.c12
-rw-r--r--plugins/gtkui/fileman.c3
-rw-r--r--plugins/mpgmad/mpgmad.c6
-rw-r--r--plugins/sid/csid.cpp1
-rw-r--r--plugins/sndfile/sndfile.c1
-rw-r--r--plugins/vorbis/vorbis.c2
-rw-r--r--plugins/vtx/vtx.c1
-rw-r--r--plugins/wavpack/wavpack.c1
17 files changed, 61 insertions, 25 deletions
diff --git a/cdumb.c b/cdumb.c
index e66761fa..289d2fb5 100644
--- a/cdumb.c
+++ b/cdumb.c
@@ -787,6 +787,7 @@ cdumb_insert (DB_playItem_t *after, const char *fname) {
it->filetype = ftype;
// printf ("duration: %f\n", _info->duration);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
unload_duh (duh);
return after;
diff --git a/cgme.c b/cgme.c
index c953f39d..2bed740c 100644
--- a/cgme.c
+++ b/cgme.c
@@ -163,6 +163,7 @@ cgme_insert (DB_playItem_t *after, const char *fname) {
}
}
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
}
else {
printf ("gme error: %s\n", ret);
diff --git a/junklib.c b/junklib.c
index b3bf0a0b..d4eb1278 100644
--- a/junklib.c
+++ b/junklib.c
@@ -31,16 +31,14 @@
#include "config.h"
#endif
-#pragma GCC optimize("O0")
-
#define MAX_TEXT_FRAME_SIZE 1024
#define MAX_APEV2_FRAME_SIZE 100000
#define MAX_ID3V2_FRAME_SIZE 100000
#define UTF8 "utf-8"
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
diff --git a/playlist.c b/playlist.c
index f59f0d81..f0c93344 100644
--- a/playlist.c
+++ b/playlist.c
@@ -378,6 +378,13 @@ plt_free (void) {
PLT_LOCK;
plt_loading = 1;
while (playlists_head) {
+
+ for (playItem_t *it = playlists_head->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ if (it->_refc > 1) {
+ fprintf (stderr, "\033[0;31mWARNING: playitem %p %s has refc=%d at delete time\033[37;0m\n", it, it->fname, it->_refc);
+ }
+ }
+
plt_remove (0);
}
plt_loading = 0;
@@ -595,7 +602,6 @@ pl_process_cue_track (playItem_t *after, const char *fname, playItem_t **prev, c
it->startsample = index01[0] ? f_index01 * samplerate : 0;
it->endsample = -1; // will be filled by next read, or by decoder
it->filetype = ftype;
- after = pl_insert_item (after, it);
if (performer[0]) {
pl_add_meta (it, "artist", performer);
}
@@ -614,6 +620,7 @@ pl_process_cue_track (playItem_t *after, const char *fname, playItem_t **prev, c
if (date[0]) {
pl_add_meta (it, "year", date);
}
+ after = pl_insert_item (after, it);
pl_item_unref (it);
*prev = it;
return it;
@@ -809,8 +816,10 @@ pl_insert_m3u (playItem_t *after, const char *fname, int *pabort, int (*cb)(play
nm[n] = 0;
trace ("adding file %s\n", nm);
playItem_t *it = pl_insert_file (after, nm, pabort, cb, user_data);
- if (it) {
+ if (after) {
pl_item_unref (after);
+ }
+ if (it) {
after = it;
}
if (pabort && *pabort) {
@@ -1060,7 +1069,9 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla
it->filetype = "content";
it->_duration = -1;
pl_add_meta (it, "title", NULL);
- return pl_insert_item (after, it);
+ after = pl_insert_item (after, it);
+ pl_item_unref (it);
+ return after;
}
}
else {
@@ -1080,7 +1091,6 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla
if (cb && cb (inserted, user_data) < 0) {
*pabort = 1;
}
- pl_item_ref (inserted);
return inserted;
}
}
@@ -1144,7 +1154,7 @@ pl_add_file (const char *fname, int (*cb)(playItem_t *it, void *data), void *use
int abort = 0;
playItem_t *it = pl_insert_file (playlist->tail[PL_MAIN], fname, &abort, cb, user_data);
if (it) {
- pl_item_unref (it);
+ // pl_insert_file doesn't hold reference, don't unref here
return 0;
}
return -1;
@@ -1155,7 +1165,7 @@ pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *us
int abort = 0;
playItem_t *it = pl_insert_dir (playlist->tail[PL_MAIN], dirname, &abort, cb, user_data);
if (it) {
- pl_item_unref (it);
+ // pl_insert_file doesn't hold reference, don't unref here
return 0;
}
return -1;
@@ -1389,6 +1399,7 @@ pl_item_unref (playItem_t *it) {
trace ("\033[0;31mplaylist: bad refcount on item %p\033[37;0m\n", it);
}
if (it->_refc <= 0) {
+ //printf ("\033[0;31mdeleted %s\033[37;0m\n", it->fname);
pl_item_free (it);
}
UNLOCK;
diff --git a/plugins/adplug/adplug-db.cpp b/plugins/adplug/adplug-db.cpp
index b97a42da..c0c9699b 100644
--- a/plugins/adplug/adplug-db.cpp
+++ b/plugins/adplug/adplug-db.cpp
@@ -262,6 +262,7 @@ adplug_insert (DB_playItem_t *after, const char *fname) {
}
// insert
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
}
// free decoder
diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c
index b7bc2598..4632be3f 100644
--- a/plugins/cdda/cdda.c
+++ b/plugins/cdda/cdda.c
@@ -342,6 +342,7 @@ cddb_thread (void *items_i)
snprintf (tmp, sizeof (tmp), "%02d", trk);
deadbeef->pl_add_meta (items[i], "track", tmp);
deadbeef->sendmessage (M_TRACKCHANGED, 0, idx, 0);
+ deadbeef->pl_item_unref (items[i]);
}
cddb_disc_destroy (disc);
deadbeef->mutex_unlock (mutex);
@@ -394,13 +395,23 @@ cda_insert (DB_playItem_t *after, const char *fname) {
struct cddb_thread_params *p = malloc (sizeof (struct cddb_thread_params));
memset (p, 0, sizeof (struct cddb_thread_params));
p->cdio = cdio;
+
+ int enable_cddb = deadbeef->conf_get_int ("cdda.freedb.enable", DEFAULT_USE_CDDB);
+
for (i = 0; i < tracks; i++)
{
res = insert_single_track (cdio, res, is_image ? fname : NULL, i+first_track);
- p->items[i] = res;
+ if (res) {
+ if (enable_cddb) {
+ p->items[i] = res;
+ }
+ else {
+ deadbeef->pl_item_unref (res);
+ }
+ }
}
trace ("cdda: querying freedb...\n");
- if (deadbeef->conf_get_int ("cdda.freedb.enable", DEFAULT_USE_CDDB)) {
+ if (enable_cddb) {
if (cddb_tid) {
deadbeef->thread_join (cddb_tid);
}
@@ -411,6 +422,9 @@ cda_insert (DB_playItem_t *after, const char *fname) {
{
track_nr = atoi (shortname);
res = insert_single_track (cdio, after, NULL, track_nr);
+ if (res) {
+ deadbeef->pl_item_unref (res);
+ }
cdio_destroy (cdio);
}
return res;
diff --git a/plugins/ffap/ffap.c b/plugins/ffap/ffap.c
index f1ffdca6..4f496ec5 100644
--- a/plugins/ffap/ffap.c
+++ b/plugins/ffap/ffap.c
@@ -37,10 +37,10 @@
#include <assert.h>
#include "../../deadbeef.h"
-#define ENABLE_DEBUG 1
+#define ENABLE_DEBUG 0
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
@@ -1750,6 +1750,7 @@ ffap_insert (DB_playItem_t *after, const char *fname) {
deadbeef->pl_add_meta (it, "title", NULL);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/ffmpeg/ffmpeg.c b/plugins/ffmpeg/ffmpeg.c
index ee723238..e157fd45 100644
--- a/plugins/ffmpeg/ffmpeg.c
+++ b/plugins/ffmpeg/ffmpeg.c
@@ -508,6 +508,7 @@ ffmpeg_insert (DB_playItem_t *after, const char *fname) {
}
// now the track is ready, insert into playlist
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c
index 0c6d232f..9281b62e 100644
--- a/plugins/flac/flac.c
+++ b/plugins/flac/flac.c
@@ -704,6 +704,7 @@ cflac_insert (DB_playItem_t *after, const char *fname) {
goto cflac_insert_fail;
}
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
if (info.file) {
deadbeef->fclose (info.file);
}
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 7d30e464..845758a0 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -51,7 +51,7 @@
#define PL_NEXT(it) (ps->binding->next (it))
#define PL_PREV(it) (ps->binding->prev (it))
-#define REF(it) {if (it) ps->binding->ref (it);}
+//#define REF(it) {if (it) ps->binding->ref (it);}
#define UNREF(it) {if (it) ps->binding->unref(it);}
// HACK!!
@@ -88,6 +88,8 @@ static void ddb_listview_init(DdbListview *listview);
static void ddb_listview_destroy(GtkObject *object);
// fwd decls
+void
+ddb_listview_free_groups (DdbListview *listview);
static inline void
draw_drawable (GdkDrawable *window, GdkGC *gc, GdkDrawable *drawable, int x1, int y1, int x2, int y2, int w, int h);
@@ -449,6 +451,9 @@ ddb_listview_destroy(GtkObject *object)
g_return_if_fail(DDB_IS_LISTVIEW(object));
listview = DDB_LISTVIEW(object);
+
+ ddb_listview_free_groups (listview);
+
while (listview->columns) {
DdbListviewColumn *next = listview->columns->next;
ddb_listview_column_free (listview, listview->columns);
@@ -621,11 +626,11 @@ ddb_listview_list_render (DdbListview *listview, int x, int y, int w, int h) {
while (grp && grp_y < y + h + listview->scrollpos) {
// render title
DdbListviewIter it = grp->head;
- listview->binding->ref (it);
int grpheight = grp->height;
if (grp_y >= y + h + listview->scrollpos) {
break;
}
+ listview->binding->ref (it);
if (grp_y + listview->grouptitle_height >= y + listview->scrollpos && grp_y < y + h + listview->scrollpos) {
ddb_listview_list_render_row_background (listview, NULL, idx & 1, 0, -listview->hscrollpos, grp_y - listview->scrollpos, listview->totalwidth, listview->grouptitle_height);
if (listview->binding->draw_group_title && listview->grouptitle_height > 0) {
@@ -858,7 +863,6 @@ ddb_listview_list_drag_data_received (GtkWidget *widget,
return;
}
int sel = ddb_listview_dragdrop_get_row_from_coord (ps, y);
- printf ("sel=%d\n", sel);
DdbListviewIter it = NULL;
if (sel == -1) {
if (ps->binding->count () != 0) {
@@ -892,7 +896,6 @@ ddb_listview_list_drag_data_received (GtkWidget *widget,
}
ps->binding->drag_n_drop (drop_before, d, length);
}
- printf ("gtk_drag_finish\n");
gtk_drag_finish (drag_context, TRUE, FALSE, time);
}
@@ -2673,7 +2676,6 @@ ddb_listview_build_groups (DdbListview *listview) {
listview->groups = grp;
memset (grp, 0, sizeof (DdbListviewGroup));
grp->head = it;
- listview->binding->ref (it);
grp->num_items = listview->binding->count ();
listview->grouptitle_height = 0;
grp->height = listview->grouptitle_height + grp->num_items * listview->rowheight;
diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c
index c2a0745e..b1fa28af 100644
--- a/plugins/gtkui/fileman.c
+++ b/plugins/gtkui/fileman.c
@@ -207,9 +207,6 @@ gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) {
}
free (ptr);
- if (after) {
- deadbeef->pl_item_unref (after);
- }
g_idle_add (progress_hide_idle, NULL);
g_idle_add (set_dnd_cursor_idle, first);
}
diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c
index 8adbf7a9..98b20e85 100644
--- a/plugins/mpgmad/mpgmad.c
+++ b/plugins/mpgmad/mpgmad.c
@@ -24,8 +24,8 @@
#include <unistd.h>
#include "../../deadbeef.h"
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
@@ -1088,6 +1088,7 @@ cmp3_insert (DB_playItem_t *after, const char *fname) {
deadbeef->pl_set_item_duration (it, -1);
it->filetype = NULL;//filetypes[0];
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
buffer_t buffer;
@@ -1167,6 +1168,7 @@ cmp3_insert (DB_playItem_t *after, const char *fname) {
}
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/sid/csid.cpp b/plugins/sid/csid.cpp
index 9a21c1eb..09c1d3ec 100644
--- a/plugins/sid/csid.cpp
+++ b/plugins/sid/csid.cpp
@@ -545,6 +545,7 @@ csid_insert (DB_playItem_t *after, const char *fname) {
it->filetype = "SID";
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
}
}
delete tune;
diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c
index d44b8e16..09469206 100644
--- a/plugins/sndfile/sndfile.c
+++ b/plugins/sndfile/sndfile.c
@@ -240,6 +240,7 @@ sndfile_insert (DB_playItem_t *after, const char *fname) {
deadbeef->pl_add_meta (it, "title", NULL);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c
index 11a93dc2..4532eef9 100644
--- a/plugins/vorbis/vorbis.c
+++ b/plugins/vorbis/vorbis.c
@@ -374,6 +374,7 @@ cvorbis_insert (DB_playItem_t *after, const char *fname) {
deadbeef->pl_set_item_duration (it, -1);
deadbeef->pl_add_meta (it, "title", NULL);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
ov_callbacks ovcb = {
@@ -426,6 +427,7 @@ cvorbis_insert (DB_playItem_t *after, const char *fname) {
}
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/vtx/vtx.c b/plugins/vtx/vtx.c
index 8d0291f2..e05870c9 100644
--- a/plugins/vtx/vtx.c
+++ b/plugins/vtx/vtx.c
@@ -271,6 +271,7 @@ vtx_insert (DB_playItem_t *after, const char *fname) {
ayemu_vtx_free (hdr);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}
diff --git a/plugins/wavpack/wavpack.c b/plugins/wavpack/wavpack.c
index ace9300a..931a9430 100644
--- a/plugins/wavpack/wavpack.c
+++ b/plugins/wavpack/wavpack.c
@@ -271,6 +271,7 @@ wv_insert (DB_playItem_t *after, const char *fname) {
deadbeef->pl_add_meta (it, "title", NULL);
after = deadbeef->pl_insert_item (after, it);
+ deadbeef->pl_item_unref (it);
return after;
}