From 05ccc7b19737e79b3e96778e5984e288b91562dc Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Sat, 16 Nov 2024 12:37:24 +0100 Subject: [PATCH] m3u: fix crash when saving; fix reference leak --- plugins/m3u/m3u.c | 14 ++++++++++---- src/playlist.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index 95ff9ffd52..f1d68d2b70 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -543,6 +543,10 @@ m3uplug_save_m3u (const char *fname, DB_playItem_t *first, DB_playItem_t *last) } fclose (fp); + if (it != NULL) { + deadbeef->pl_item_unref (it); + } + deadbeef->tf_free (tf); return 0; } @@ -615,17 +619,19 @@ m3uplug_save_pls (const char *fname, DB_playItem_t *first, DB_playItem_t *last) int m3uplug_save (ddb_playlist_t *plt, const char *fname, DB_playItem_t *first, DB_playItem_t *last) { + int res = -1; const char *e = strrchr (fname, '.'); if (!e) { - return -1; + return res; } + if (!strcasecmp (e, ".m3u") || !strcasecmp (e, ".m3u8")) { - return m3uplug_save_m3u (fname, first, last); + res = m3uplug_save_m3u (fname, first, last); } else if (!strcasecmp (e, ".pls")) { - return m3uplug_save_pls (fname, first, last); + res = m3uplug_save_pls (fname, first, last); } - return -1; + return res; } static const char * exts[] = { "m3u", "m3u8", "pls", NULL }; diff --git a/src/playlist.c b/src/playlist.c index e54bab463a..2b3d331291 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -2271,11 +2271,32 @@ plt_save( if (exts && plug[i]->save) { for (int e = 0; exts[e]; e++) { if (!strcasecmp (exts[e], ext + 1)) { + if (first == NULL) { + first = plt_get_first(plt, PL_MAIN); + } + else { + pl_item_ref(first); + } + if (last == NULL) { + last = plt_get_last(plt, PL_MAIN); + } + else { + pl_item_ref(last); + } + int res = plug[i]->save ( (ddb_playlist_t *)plt, fname, (DB_playItem_t *)first, (DB_playItem_t *)last); + + if (first != NULL) { + pl_item_unref(first); + } + if (last != NULL) { + pl_item_unref(last); + } + UNLOCK; return res; }