From 7fff0ce33c1ebf8806827b6c5fb7dfb978ff5cc3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Sep 2008 01:00:12 +0200 Subject: [PATCH] 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? --- src/libmpdclient.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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; } -- 2.30.2