[MPlayer-cvslog] r36655 - trunk/stream/stream_cddb.c

reimar subversion at mplayerhq.hu
Sun Jan 19 23:24:52 CET 2014


Author: reimar
Date: Sun Jan 19 23:24:52 2014
New Revision: 36655

Log:
cddb: fix multiple leaks, both for error and normal use cases.

Modified:
   trunk/stream/stream_cddb.c

Modified: trunk/stream/stream_cddb.c
==============================================================================
--- trunk/stream/stream_cddb.c	Sun Jan 19 23:24:50 2014	(r36654)
+++ trunk/stream/stream_cddb.c	Sun Jan 19 23:24:52 2014	(r36655)
@@ -376,9 +376,9 @@ static int cddb_http_request(char *comma
                       cddb_data_t *cddb_data)
 {
     char request[4096];
-    int fd, ret = 0;
-    URL_t *url;
-    HTTP_header_t *http_hdr;
+    int fd = -1, ret = -1;
+    URL_t *url = NULL;
+    HTTP_header_t *http_hdr = NULL;
 
     if (reply_parser == NULL || command == NULL || cddb_data == NULL)
         return -1;
@@ -391,26 +391,27 @@ static int cddb_http_request(char *comma
     url = url_new(request);
     if (url == NULL) {
         mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NotAValidURL);
-        return -1;
+        goto out;
     }
 
     fd = http_send_request(url,0);
     if (fd < 0) {
         mp_msg(MSGT_DEMUX, MSGL_ERR,
                MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest);
-        return -1;
+        goto out;
     }
 
     http_hdr = http_read_response(fd);
     if (http_hdr == NULL) {
         mp_msg(MSGT_DEMUX, MSGL_ERR,
                MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse);
-        return -1;
+        goto out;
     }
 
     http_debug_hdr(http_hdr);
     mp_msg(MSGT_OPEN, MSGL_INFO,"body=[%s]\n", http_hdr->body);
 
+    ret = 0;
     switch (http_hdr->status_code) {
     case 200:
         ret = reply_parser(http_hdr, cddb_data);
@@ -422,8 +423,10 @@ static int cddb_http_request(char *comma
         mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown);
     }
 
-    http_free(http_hdr);
-    url_free(url);
+out:
+    if (fd >= 0) closesocket(fd);
+    if (http_hdr) http_free(http_hdr);
+    if (url) url_free(url);
 
     return ret;
 }


More information about the MPlayer-cvslog mailing list