[MPlayer-cvslog] r21553 - trunk/stream/asf_streaming.c
reimar
subversion at mplayerhq.hu
Sat Dec 9 20:12:51 CET 2006
Author: reimar
Date: Sat Dec 9 20:12:51 2006
New Revision: 21553
Modified:
trunk/stream/asf_streaming.c
Log:
Avoid memory and fd leaks in asf streaming open code.
Modified: trunk/stream/asf_streaming.c
==============================================================================
--- trunk/stream/asf_streaming.c (original)
+++ trunk/stream/asf_streaming.c Sat Dec 9 20:12:51 2006
@@ -745,8 +745,7 @@
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 @@
//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 @@
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 @@
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 @@
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 @@
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 @@
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) {
More information about the MPlayer-cvslog
mailing list