Fix lots and lots of potential memory/fd leaks in http_streaming_start

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21556 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2006-12-09 19:33:28 +00:00
parent 14dc3c4f29
commit 5129d87b43
1 changed files with 28 additions and 19 deletions

View File

@ -718,9 +718,10 @@ base64_encode(const void *enc, int encLen, char *out, int outMax) {
} }
static int http_streaming_start(stream_t *stream, int* file_format) { static int http_streaming_start(stream_t *stream, int* file_format) {
HTTP_header_t *http_hdr; HTTP_header_t *http_hdr = NULL;
unsigned int i; unsigned int i;
int fd=-1; int fd = stream->fd;
int res = 0;
int redirect = 0; int redirect = 0;
int auth_retry=0; int auth_retry=0;
int seekable=0; int seekable=0;
@ -730,16 +731,16 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
do do
{ {
if (fd > 0) closesocket(fd);
fd = http_send_request( url, 0 ); fd = http_send_request( url, 0 );
if( fd<0 ) { if( fd<0 ) {
return -1; goto err_out;
} }
http_free(http_hdr);
http_hdr = http_read_response( fd ); http_hdr = http_read_response( fd );
if( http_hdr==NULL ) { if( http_hdr==NULL ) {
closesocket( fd ); goto err_out;
http_free( http_hdr );
return -1;
} }
stream->fd=fd; stream->fd=fd;
@ -784,23 +785,23 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
*file_format = DEMUXER_TYPE_AAC; *file_format = DEMUXER_TYPE_AAC;
else else
*file_format = DEMUXER_TYPE_AUDIO; *file_format = DEMUXER_TYPE_AUDIO;
return 0; goto out;
} }
case 400: // Server Full case 400: // Server Full
mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server is full, skipping!\n"); mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server is full, skipping!\n");
return -1; goto err_out;
case 401: // Service Unavailable case 401: // Service Unavailable
mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n"); mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n");
return -1; goto err_out;
case 403: // Service Forbidden case 403: // Service Forbidden
mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return 'Service Forbidden'\n"); mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return 'Service Forbidden'\n");
return -1; goto err_out;
case 404: // Resource Not Found case 404: // Resource Not Found
mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n"); mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n");
return -1; goto err_out;
default: default:
mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n"); mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n");
return -1; goto err_out;
} }
} }
@ -819,14 +820,16 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
while(mime_type_table[i].mime_type != NULL) { while(mime_type_table[i].mime_type != NULL) {
if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) { if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) {
*file_format = mime_type_table[i].demuxer_type; *file_format = mime_type_table[i].demuxer_type;
return seekable; res = seekable;
goto out;
} }
i++; i++;
} }
} }
// Not found in the mime type table, don't fail, // Not found in the mime type table, don't fail,
// we should try raw HTTP // we should try raw HTTP
return seekable; res = seekable;
goto out;
// Redirect // Redirect
case 301: // Permanently case 301: // Permanently
case 302: // Temporarily case 302: // Temporarily
@ -834,23 +837,29 @@ static int http_streaming_start(stream_t *stream, int* file_format) {
// TODO: RFC 2616, recommand to detect infinite redirection loops // TODO: RFC 2616, recommand to detect infinite redirection loops
next_url = http_get_field( http_hdr, "Location" ); next_url = http_get_field( http_hdr, "Location" );
if( next_url!=NULL ) { if( next_url!=NULL ) {
closesocket( fd );
stream->streaming_ctrl->url = url_redirect( &url, next_url ); stream->streaming_ctrl->url = url_redirect( &url, next_url );
http_free( http_hdr );
redirect = 1; redirect = 1;
} }
break; break;
case 401: // Authentication required case 401: // Authentication required
if( http_authenticate(http_hdr, url, &auth_retry)<0 ) return STREAM_UNSUPORTED; if( http_authenticate(http_hdr, url, &auth_retry)<0 ) {
res = STREAM_UNSUPORTED;
goto err_out;
}
redirect = 1; redirect = 1;
break; break;
default: default:
mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
return -1; goto err_out;
} }
} while( redirect ); } while( redirect );
return -1; err_out:
if (fd > 0) closesocket( fd );
res = -1;
out:
http_free( http_hdr );
return res;
} }
static int fixup_open(stream_t *stream,int seekable) { static int fixup_open(stream_t *stream,int seekable) {