Skip to content

Commit

Permalink
m3u: fix crash when saving; fix reference leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Nov 16, 2024
1 parent c10d5c2 commit 05ccc7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugins/m3u/m3u.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 };
Expand Down
21 changes: 21 additions & 0 deletions src/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 05ccc7b

Please sign in to comment.