changeset 13807:b014091b4417

Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
author faust3
date Sat, 30 Oct 2004 10:09:52 +0000
parents 0cdf4607d7ff
children 46910a7aa7e1
files codec-cfg.c codec-cfg.h
diffstat 2 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/codec-cfg.c	Sat Oct 30 09:46:16 2004 +0000
+++ b/codec-cfg.c	Sat Oct 30 10:09:52 2004 +0000
@@ -487,11 +487,7 @@
 	int tmp, i;
 	
 	// in case we call it a second time
-	if(video_codecs!=NULL)free(video_codecs);
-	video_codecs=NULL;
- 
- 	if(audio_codecs!=NULL)free(audio_codecs);
-	audio_codecs=NULL;
+	codecs_uninit_free();
 	
 	nr_vcodecs = 0;
 	nr_acodecs = 0;
@@ -715,12 +711,7 @@
 err_out_print_linenum:
 	PRINT_LINENUM;
 err_out:
-	if (audio_codecs)
-		free(audio_codecs);
-	if (video_codecs)
-		free(video_codecs);
-	video_codecs=NULL;
-	audio_codecs=NULL;
+	codecs_uninit_free();
 
 	free(line);
 	line=NULL;
@@ -735,6 +726,32 @@
 	goto err_out_print_linenum;
 }
 
+static void codecs_free(codecs_t* codecs,int count) {
+	int i;
+		for ( i = 0; i < count; i++)
+			if ( (codecs[i]).name ) {
+				if( (codecs[i]).name )
+					free((codecs[i]).name);
+				if( (codecs[i]).info )
+					free((codecs[i]).info);
+				if( (codecs[i]).comment )
+					free((codecs[i]).comment);
+				if( (codecs[i]).dll )
+					free((codecs[i]).dll);
+				if( (codecs[i]).drv )
+					free((codecs[i]).drv);
+			}
+		if (codecs)
+			free(codecs);
+}
+
+void codecs_uninit_free() {
+	codecs_free(video_codecs,nr_vcodecs);
+	video_codecs=NULL;
+	codecs_free(audio_codecs,nr_acodecs);
+	audio_codecs=NULL;
+}
+
 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
 		codecs_t *start)
 {
--- a/codec-cfg.h	Sat Oct 30 09:46:16 2004 +0000
+++ b/codec-cfg.h	Sat Oct 30 10:09:52 2004 +0000
@@ -65,5 +65,6 @@
 void select_codec(char* codecname,int audioflag);
 void list_codecs(int audioflag);
 void codecs_reset_selection(int audioflag);
+void codecs_uninit_free();
 
 #endif