Code

libmpdclient: don't strdup() MPD's welcome message
authorMax Kellermann <max@duempel.org>
Wed, 17 Sep 2008 23:00:12 +0000 (01:00 +0200)
committerMax Kellermann <max@duempel.org>
Wed, 17 Sep 2008 23:00:12 +0000 (01:00 +0200)
Why bother duplicating the buffer, when we can simply parse the
response directly from the input buffer?

src/libmpdclient.c

index 675521f3b67592bd8621f8ab5d7126846dd00b42..e63c20bbf673c5aa3eb2950bbc5ba4f4ce3ffe5a 100644 (file)
@@ -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;
 }