From fb116ef0ad73c9e3c0b7ebc99fef03d98580a99b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 18 Sep 2009 11:30:49 +0200 Subject: [PATCH] screen_lyrics, screen_song: duplicate "next_song" The screen_X_switch() function calls screen_switch. As a side effect of the previous screen being closed, the next_song pointer may become invalid, which causes memory corruption. Let's duplicate the song when assigning it to next_song. --- src/screen_lyrics.c | 6 ++++-- src/screen_song.c | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index a1556ae..8f7c23d 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -35,7 +35,7 @@ static struct screen_text text; -static const struct mpd_song *next_song; +static struct mpd_song *next_song; static bool follow = false; static struct { @@ -210,6 +210,8 @@ lyrics_open(mpdclient_t *c) strcmp(next_song->file, current.song->file) != 0)) screen_lyrics_load(next_song); + if (next_song != c->song) + mpd_freeSong(next_song); next_song = NULL; } @@ -327,6 +329,6 @@ screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song, bool f) assert(song != NULL); follow = f; - next_song = song; + next_song = mpd_songDup(song); screen_switch(&screen_lyrics, c); } diff --git a/src/screen_song.c b/src/screen_song.c index 6d27e56..a7d6f8e 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -28,7 +28,7 @@ static list_window_t *lw; -static const struct mpd_song *next_song; +static struct mpd_song *next_song; static struct { struct mpd_song *selected_song; @@ -315,7 +315,7 @@ screen_song_update(mpdclient_t *c) /* If a song was selected before the song screen was opened */ if (next_song != NULL) { assert(current.selected_song == NULL); - current.selected_song = mpd_songDup(next_song); + current.selected_song = next_song; next_song = NULL; } @@ -426,6 +426,6 @@ screen_song_switch(mpdclient_t *c, const struct mpd_song *song) assert(current.selected_song == NULL); assert(current.played_song == NULL); - next_song = song; + next_song = mpd_songDup(song); screen_switch(&screen_song, c); } -- 2.30.2