From 363bed34acf37c315ba29cbefe817f12eb981086 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 23 Mar 2009 23:42:59 +0100 Subject: [PATCH] fix temporary printing of "(null)" for mpd vars To minimise the chance of printing variables in an undefined state, call free() as late as possible (i.e., right before strdup()'ing the new value). --- src/mpd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mpd.c b/src/mpd.c index 06a02bd1..59fe5c1d 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -132,8 +132,6 @@ static void *update_mpd_thread(void *arg) const char *emptystr = ""; while (1) { - clear_mpd(); - if (!conn) conn = mpd_newConnection(mpd_host, mpd_port, 10); @@ -248,7 +246,13 @@ static void *update_mpd_thread(void *arg) mpd_freeInfoEntity(entity); continue; } -#define SONGSET(x) if(song->x) mpd_info.x = strmdup(song->x); else mpd_info.x = strmdup(emptystr) +#define SONGSET(x) { \ + free(mpd_info.x); \ + if(song->x) \ + mpd_info.x = strmdup(song->x); \ + else \ + mpd_info.x = strmdup(emptystr); \ +} SONGSET(artist); SONGSET(album); SONGSET(title);