changeset 21537:21263c9ddd87

Avoid memory and fd leaks in asf streaming open code.
author reimar
date Sat, 09 Dec 2006 19:12:51 +0000
parents 4d1ba1f391f3
children c9b6588932b5
files stream/asf_streaming.c
diffstat 1 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/stream/asf_streaming.c	Sat Dec 09 18:57:48 2006 +0000
+++ b/stream/asf_streaming.c	Sat Dec 09 19:12:51 2006 +0000
@@ -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) {