From: malaterre Date: Wed, 26 Oct 2005 20:44:41 +0000 (+0000) Subject: ENH: This lib was leaking like crazy... X-Git-Tag: OpenJPEG.Version1.2~131 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=80a0be0291e7d8760528d89b2fb0a9dcd6d40cb9;p=gdcm.git ENH: This lib was leaking like crazy... --- diff --git a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c index ea6d1648..dbfe0f3f 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c +++ b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c @@ -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; diff --git a/src/gdcmmpeg2/src/mpeg2dec/store.c b/src/gdcmmpeg2/src/mpeg2dec/store.c index db1f0391..61366c09 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/store.c +++ b/src/gdcmmpeg2/src/mpeg2dec/store.c @@ -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)