diff options
author | Max Kellermann <max@duempel.org> | 2008-09-17 12:29:15 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-17 12:29:15 +0200 |
commit | a878dcfbfc717f817ae7f3a2ecfbef4c016ee046 (patch) | |
tree | 82ef29bb188defb95c02a3a8078e44b7bf985ebe /src | |
parent | 75348aad7cbddb9ef736a0ecca9e3ddfb8b75f8d (diff) | |
download | mpd-a878dcfbfc717f817ae7f3a2ecfbef4c016ee046.tar.gz mpd-a878dcfbfc717f817ae7f3a2ecfbef4c016ee046.tar.xz mpd-a878dcfbfc717f817ae7f3a2ecfbef4c016ee046.zip |
playlist: added playlist_remove_reuse()
playlist_remove_reuse() removes a song from the playlist, but does not
free it.
Use this function in mpdclient_cmd_delete() to fix a segmentation
fault: the song pointer was still used after it was freed, by passing
it to mpdclient_playlist_callback(). Free the song manually now.
Reorganize and simply some code in mpdclient_cmd_delete().
Diffstat (limited to 'src')
-rw-r--r-- | src/mpdclient.c | 4 | ||||
-rw-r--r-- | src/playlist.h | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/mpdclient.c b/src/mpdclient.c index f67b09133..469c794c6 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -459,7 +459,7 @@ mpdclient_cmd_delete(mpdclient_t *c, gint idx) c->playlist.id++; /* remove the song from the playlist */ - playlist_remove(&c->playlist, idx); + playlist_remove_reuse(&c->playlist, idx); /* call playlist updated callback */ mpdclient_playlist_callback(c, PLAYLIST_EVENT_DELETE, (gpointer) song); @@ -470,6 +470,8 @@ mpdclient_cmd_delete(mpdclient_t *c, gint idx) c->need_update = TRUE; } + mpd_freeSong(song); + #else c->need_update = TRUE; #endif diff --git a/src/playlist.h b/src/playlist.h index 9cd88ab27..93c034f5a 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -96,11 +96,16 @@ playlist_replace(struct mpdclient_playlist *playlist, guint idx, playlist_set(playlist, idx, song); } +static inline struct mpd_song * +playlist_remove_reuse(struct mpdclient_playlist *playlist, guint idx) +{ + return g_ptr_array_remove_index(playlist->list, idx); +} + static inline void playlist_remove(struct mpdclient_playlist *playlist, guint idx) { - mpd_Song *song = g_ptr_array_remove_index(playlist->list, idx); - mpd_freeSong(song); + mpd_freeSong(playlist_remove_reuse(playlist, idx)); } static inline void |