[wiki] [sites] forgotten free || Thuban

From: <git_AT_suckless.org>
Date: Sat, 22 Jun 2013 09:45:47 +0200

commit 306dafb1f6d8340986d5389a6a59bb5666a59d8b
Author: Thuban <thuban_AT_singularity.fr>
Date: Sat Jun 22 09:45:44 2013 +0200

    forgotten free

diff --git a/dwm.suckless.org/dwmstatus/mpdstatus.c b/dwm.suckless.org/dwmstatus/mpdstatus.c
index 1f526ca..d72409f 100644
--- a/dwm.suckless.org/dwmstatus/mpdstatus.c
+++ b/dwm.suckless.org/dwmstatus/mpdstatus.c
_AT_@ -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);
_AT_@ -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);
_AT_@ -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;
 }
-
Received on Sat Jun 22 2013 - 09:45:47 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 22 2013 - 09:48:11 CEST