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
This commit is contained in:
reimar 2006-12-09 19:12:51 +00:00
parent a0897b21c1
commit 29ec343e07
1 changed files with 15 additions and 15 deletions

View File

@ -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) {