sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 306dafb1f6d8340986d5389a6a59bb5666a59d8b
parent a7318dbc8ac66f1d0fea23e5f09e4ccb3be1da87
Author: Thuban <thuban@singularity.fr>
Date:   Sat, 22 Jun 2013 09:45:44 +0200

forgotten free

Diffstat:
Mdwm.suckless.org/dwmstatus/mpdstatus.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/dwm.suckless.org/dwmstatus/mpdstatus.c b/dwm.suckless.org/dwmstatus/mpdstatus.c @@ -22,10 +22,10 @@ getmpdstat() { const char * artist = NULL; char * retstr = NULL; int elapsed = 0, total = 0; - struct mpd_connection * conn = mpd_connection_new(NULL, 0, 30000); + struct mpd_connection * conn ; if (!(conn = mpd_connection_new("localhost", 0, 30000)) || mpd_connection_get_error(conn)){ - return smprintf(""); + return smprintf(""); } mpd_command_list_begin(conn, true); @@ -34,13 +34,12 @@ getmpdstat() { mpd_command_list_end(conn); struct mpd_status* theStatus = mpd_recv_status(conn); - if (!theStatus) retstr = smprintf(""); - else - if (mpd_status_get_state(theStatus) == MPD_STATE_PLAY) { + if ((theStatus) && (mpd_status_get_state(theStatus) == MPD_STATE_PLAY)) { mpd_response_next(conn); song = mpd_recv_song(conn); title = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_TITLE, 0)); artist = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_ARTIST, 0)); + elapsed = mpd_status_get_elapsed_time(theStatus); total = mpd_status_get_total_time(theStatus); mpd_song_free(song); @@ -48,10 +47,11 @@ getmpdstat() { elapsed/60, elapsed%60, total/60, total%60, artist, title); - } - else retstr = smprintf(""); + free((char*)title); + free((char*)artist); + } + else retstr = smprintf(""); mpd_response_finish(conn); mpd_connection_free(conn); return retstr; } -