Skip to content

Commit 05ccc7b

Browse files
m3u: fix crash when saving; fix reference leak
1 parent c10d5c2 commit 05ccc7b

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

plugins/m3u/m3u.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ m3uplug_save_m3u (const char *fname, DB_playItem_t *first, DB_playItem_t *last)
543543
}
544544
fclose (fp);
545545

546+
if (it != NULL) {
547+
deadbeef->pl_item_unref (it);
548+
}
549+
546550
deadbeef->tf_free (tf);
547551
return 0;
548552
}
@@ -615,17 +619,19 @@ m3uplug_save_pls (const char *fname, DB_playItem_t *first, DB_playItem_t *last)
615619

616620
int
617621
m3uplug_save (ddb_playlist_t *plt, const char *fname, DB_playItem_t *first, DB_playItem_t *last) {
622+
int res = -1;
618623
const char *e = strrchr (fname, '.');
619624
if (!e) {
620-
return -1;
625+
return res;
621626
}
627+
622628
if (!strcasecmp (e, ".m3u") || !strcasecmp (e, ".m3u8")) {
623-
return m3uplug_save_m3u (fname, first, last);
629+
res = m3uplug_save_m3u (fname, first, last);
624630
}
625631
else if (!strcasecmp (e, ".pls")) {
626-
return m3uplug_save_pls (fname, first, last);
632+
res = m3uplug_save_pls (fname, first, last);
627633
}
628-
return -1;
634+
return res;
629635
}
630636

631637
static const char * exts[] = { "m3u", "m3u8", "pls", NULL };

src/playlist.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,11 +2271,32 @@ plt_save(
22712271
if (exts && plug[i]->save) {
22722272
for (int e = 0; exts[e]; e++) {
22732273
if (!strcasecmp (exts[e], ext + 1)) {
2274+
if (first == NULL) {
2275+
first = plt_get_first(plt, PL_MAIN);
2276+
}
2277+
else {
2278+
pl_item_ref(first);
2279+
}
2280+
if (last == NULL) {
2281+
last = plt_get_last(plt, PL_MAIN);
2282+
}
2283+
else {
2284+
pl_item_ref(last);
2285+
}
2286+
22742287
int res = plug[i]->save (
22752288
(ddb_playlist_t *)plt,
22762289
fname,
22772290
(DB_playItem_t *)first,
22782291
(DB_playItem_t *)last);
2292+
2293+
if (first != NULL) {
2294+
pl_item_unref(first);
2295+
}
2296+
if (last != NULL) {
2297+
pl_item_unref(last);
2298+
}
2299+
22792300
UNLOCK;
22802301
return res;
22812302
}

0 commit comments

Comments
 (0)