# HG changeset patch # User reimar # Date 1390170292 0 # Node ID 85b5f38299fb223dd939cfc2c768ad12cda42c75 # Parent 33a38520487532c2dab1dac49f927fd98bc3ac4c cddb: fix multiple leaks, both for error and normal use cases. diff -r 33a385204875 -r 85b5f38299fb stream/stream_cddb.c --- a/stream/stream_cddb.c Sun Jan 19 22:24:50 2014 +0000 +++ b/stream/stream_cddb.c Sun Jan 19 22:24:52 2014 +0000 @@ -376,9 +376,9 @@ 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 @@ 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 @@ 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; }