changeset 17831:f36966ddbf77

exit if calloc() fails; free(muxer) before returning NULL if muxer_init() fails (to avoid memleak). Fixes cid 173
author nicodvb
date Sun, 12 Mar 2006 18:13:11 +0000
parents e640ecc0be46
children 7fa8bfd0dea3
files libmpdemux/muxer.c
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/muxer.c	Sun Mar 12 18:11:32 2006 +0000
+++ b/libmpdemux/muxer.c	Sun Mar 12 18:13:11 2006 +0000
@@ -21,30 +21,47 @@
 muxer_t *muxer_new_muxer(int type,FILE *f){
     muxer_t* muxer=malloc(sizeof(muxer_t));
     memset(muxer,0,sizeof(muxer_t));
+    if(!muxer)
+        return NULL;
     muxer->file = f;
     switch (type) {
       case MUXER_TYPE_MPEG:
 	if(! muxer_init_muxer_mpeg(muxer))
-	  return NULL;
+        {
+          free(muxer);
+          return NULL;
+        }
 	break;
       case MUXER_TYPE_RAWVIDEO:
         if(! muxer_init_muxer_rawvideo(muxer))
+        {
+	  free(muxer);
 	  return NULL;
+        }
 	break;
       case MUXER_TYPE_RAWAUDIO:
         if(! muxer_init_muxer_rawaudio(muxer))
+        {
+          free(muxer);
           return NULL;
+        }
         break;
 #if defined(USE_LIBAVFORMAT) || defined(USE_LIBAVFORMAT_SO)
       case MUXER_TYPE_LAVF:
         if(! muxer_init_muxer_lavf(muxer))
-	  return NULL;
+        {
+          free(muxer);
+          return NULL;
+        }
         break;
 #endif
       case MUXER_TYPE_AVI:
       default:
 	if(! muxer_init_muxer_avi(muxer))
-	  return NULL;
+        {
+          free(muxer);
+          return NULL;
+        }
     }
     return muxer;
 }