]> Creatis software - gdcm.git/commitdiff
ENH: This lib was leaking like crazy...
authormalaterre <malaterre>
Wed, 26 Oct 2005 20:44:41 +0000 (20:44 +0000)
committermalaterre <malaterre>
Wed, 26 Oct 2005 20:44:41 +0000 (20:44 +0000)
src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c
src/gdcmmpeg2/src/mpeg2dec/store.c

index ea6d164810c138eab19c098ba5154e2fae238ea4..dbfe0f3f25cddabe7b122fa4550de87480d948dd 100644 (file)
@@ -42,6 +42,7 @@ static int  Decode_Bitstream _ANSI_ARGS_((void));
 static int  Headers _ANSI_ARGS_((void));
 static void Initialize_Sequence _ANSI_ARGS_((void));
 static void Initialize_Decoder _ANSI_ARGS_((void));
+static void DeInitialize_Decoder _ANSI_ARGS_((void));
 static void Deinitialize_Sequence _ANSI_ARGS_((void));
 static void Process_Options _ANSI_ARGS_((int argc, char *argv[]));
 
@@ -280,6 +281,8 @@ char *argv[];
     /*close(enhan.Infile);*/
     ld->close_stream(enhan.Infile);
 
+  DeInitialize_Decoder();
+
   return ret;
 }
 #endif /*GDCM_BUILD_MPEG2DEC*/
@@ -306,6 +309,11 @@ static void Initialize_Decoder()
 
 }
 
+static void DeInitialize_Decoder()
+{
+  free(Clip-384); // WTF !!!
+}
+
 /* mostly IMPLEMENTAION specific rouintes */
 static void Initialize_Sequence()
 {
@@ -761,6 +769,9 @@ static void Deinitialize_Sequence()
 {
   int i;
 
+  /* First clenup the static buffer in store.c */
+  FreeStaticBuffer();
+
   /* clear flags */
   base.MPEG2_Flag=0;
 
index db1f039184355c0d37f6c62acd1da410396f64eb..61366c097915e3dc605ac4ba9180fde1e591b3ec 100644 (file)
@@ -53,6 +53,14 @@ static void conv420to422 _ANSI_ARGS_((unsigned char *src, unsigned char *dst));
 static unsigned char obfr[OBFRSIZE];
 static unsigned char *optr;
 static ostream *outfile;
+unsigned char *static_malloc[6] = {0,0,0,0,0,0}; //worse case there is 6 buffer in this impl unit.
+
+void FreeStaticBuffer()
+{
+  int i;
+  for(i=0;i<6;++i)
+    free(static_malloc[i]);
+}
 
 /*
  * store a picture as either one frame or two fields
@@ -207,9 +215,11 @@ int offset, incr, height;
       if (!(u422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
                                            *Coded_Picture_Height)))
         Error("malloc failed");
+      static_malloc[0] = u422;
       if (!(v422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
                                            *Coded_Picture_Height)))
         Error("malloc failed");
+      static_malloc[1] = v422;
     }
   
     conv420to422(src[1],u422);
@@ -284,18 +294,22 @@ int tgaflag;
         if (!(u422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
                                              *Coded_Picture_Height)))
           Error("malloc failed");
+        static_malloc[2] = u422;
         if (!(v422 = (unsigned char *)malloc((Coded_Picture_Width>>1)
                                              *Coded_Picture_Height)))
           Error("malloc failed");
+        static_malloc[3] = v422;
       }
 
       if (!(u444 = (unsigned char *)malloc(Coded_Picture_Width
                                            *Coded_Picture_Height)))
         Error("malloc failed");
+      static_malloc[4] = u444;
 
       if (!(v444 = (unsigned char *)malloc(Coded_Picture_Width
                                            *Coded_Picture_Height)))
         Error("malloc failed");
+      static_malloc[5] = v444;
     }
 
     if (chroma_format==CHROMA420)