From 29ec343e071827562f0179e1edae47e778d20593 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 9 Dec 2006 19:12:51 +0000 Subject: Avoid memory and fd leaks in asf streaming open code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21553 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/asf_streaming.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'stream/asf_streaming.c') diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c index 491c44ba22..13ff3d57ec 100644 --- a/stream/asf_streaming.c +++ b/stream/asf_streaming.c @@ -745,8 +745,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { int r = send( fd, http_hdr->buffer+i, http_hdr->buffer_size-i, 0 ); if(r <0) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_SocketWriteError,strerror(errno)); - http_free( http_hdr ); - return -1; + goto err_out; } i += r; } @@ -757,8 +756,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { //printf("read: %d\n", i ); if( i<=0 ) { perror("read"); - http_free( http_hdr ); - return -1; + goto err_out; } http_response_append( http_hdr, buffer, i ); } while( !http_is_header_entire( http_hdr ) ); @@ -769,8 +767,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { ret = asf_http_parse_response(asf_http_ctrl, http_hdr); if( ret<0 ) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_HeaderParseFailed); - http_free( http_hdr ); - return -1; + goto err_out; } switch( asf_http_ctrl->streaming_type ) { case ASF_Live_e: @@ -778,18 +775,17 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { case ASF_PlainText_e: if( http_hdr->body_size>0 ) { if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { - http_free( http_hdr ); - return -1; + goto err_out; } } if( asf_http_ctrl->request==1 ) { if( asf_http_ctrl->streaming_type!=ASF_PlainText_e ) { // First request, we only got the ASF header. ret = asf_streaming_parse_header(fd,stream->streaming_ctrl); - if(ret < 0) return -1; + if(ret < 0) goto err_out; if(asf_http_ctrl->n_audio == 0 && asf_http_ctrl->n_video == 0) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_NoStreamFound); - return -1; + goto err_out; } asf_http_ctrl->request++; done = 0; @@ -801,8 +797,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { case ASF_Redirector_e: if( http_hdr->body_size>0 ) { if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { - http_free( http_hdr ); - return -1; + goto err_out; } } *demuxer_type = DEMUXER_TYPE_PLAYLIST; @@ -816,9 +811,7 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { case ASF_Unknown_e: default: mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_UnknownASFStreamingType); - closesocket(fd); - http_free( http_hdr ); - return -1; + goto err_out; } // Check if we got a redirect. } while(!done); @@ -837,6 +830,13 @@ static int asf_http_streaming_start( stream_t *stream, int *demuxer_type ) { http_free( http_hdr ); return 0; + +err_out: + if (fd > 0) + closesocket(fd); + stream->fd = -1; + http_free(http_hdr); + return -1; } static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { -- cgit v1.2.3