From: Max Kellermann Date: Wed, 17 Sep 2008 23:00:12 +0000 (+0200) Subject: libmpdclient: don't strdup() MPD's welcome message X-Git-Tag: v0.12_alpha1~256 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7fff0ce33c1ebf8806827b6c5fb7dfb978ff5cc3;p=ncmpc.git libmpdclient: don't strdup() MPD's welcome message Why bother duplicating the buffer, when we can simply parse the response directly from the input buffer? --- diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 675521f..e63c20b 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -383,7 +383,6 @@ static int mpd_connect_un(mpd_Connection * connection, mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { int err; char * rt; - char * output = NULL; mpd_Connection * connection = malloc(sizeof(mpd_Connection)); struct timeval tv; fd_set fds; @@ -452,14 +451,11 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { } *rt = '\0'; - output = strdup(connection->buffer); - strcpy(connection->buffer,rt+1); - connection->buflen = strlen(connection->buffer); - - if(mpd_parseWelcome(connection,host,port,output) == 0) + if (mpd_parseWelcome(connection, host, port, connection->buffer) == 0) connection->doneProcessing = 1; - free(output); + strcpy(connection->buffer,rt+1); + connection->buflen = strlen(connection->buffer); return connection; }