* Inserted tool for memory leaks fixing in debug mode

* Fixed some memory leaks in the decoder (some are still present when multiple tiles!)
This commit is contained in:
Antonin Descampe 2004-08-06 14:13:51 +00:00
parent 61ac18531a
commit bc5c5115cb
6 changed files with 89 additions and 4 deletions

View File

@ -26,6 +26,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
//MEMORY LEAK
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h> // Must be included first
#include <crtdbg.h>
#endif
//MEM
#include <openjpeg.h>
#include <stdio.h>
#include <stdlib.h>
@ -895,5 +903,12 @@ int main(int argc, char **argv)
free(cp.tcps[tileno].tccps);
free(cp.tcps);
//MEMORY LEAK
#ifdef _DEBUG
_CrtDumpMemoryLeaks();
#endif
//MEM
return 0;
}

View File

@ -25,6 +25,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
//MEMORY LEAK
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h> // Must be included first
#include <crtdbg.h>
#endif
//MEM
#include <openjpeg.h>
@ -39,9 +47,9 @@ int ceildiv(int a, int b)
int main(int argc, char **argv)
{
FILE *f;
char *src, *src_name;
char *dest, S1, S2, S3;
FILE *f=NULL;
char *src=NULL, *src_name=NULL;
char *dest=NULL, S1, S2, S3;
int len;
j2k_image_t img;
@ -50,7 +58,7 @@ int main(int argc, char **argv)
int w, wr, wrr, h, hr, hrr, max;
int i, image_type = -1, compno, pad, j;
int adjust;
jp2_struct_t *jp2_struct;
jp2_struct_t *jp2_struct=NULL;
if (argc < 3) {
fprintf(stderr,
@ -553,5 +561,13 @@ int main(int argc, char **argv)
break;
}
j2k_dec_release();
//MEMORY LEAK
#ifdef _DEBUG
_CrtDumpMemoryLeaks();
#endif
//MEM
return 0;
}

View File

@ -1458,6 +1458,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
cio_init(src, len);
for (;;) {
j2k_dec_mstabent_t *e;
int id = cio_read(2);
if (id >> 8 != 0xff) {
@ -1473,6 +1474,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
if (e->handler) {
(*e->handler) ();
}
if (j2k_state == J2K_STATE_NEOC)
break; /* RAJOUTE */
}
@ -1562,6 +1564,26 @@ j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
return 0;
}
void j2k_dec_release()
{
int i=0;
//tcd_dec_release();
if (j2k_tile_len!=NULL) free(j2k_tile_len);
if (j2k_tile_data!=NULL) free(j2k_tile_data);
if (j2k_default_tcp.ppt_data!=NULL) free(j2k_default_tcp.ppt_data);
if (j2k_default_tcp.tccps!=NULL) free(j2k_default_tcp.tccps);
for (i=0;i<j2k_cp->tw*j2k_cp->th;i++) {
if (j2k_cp->tcps[i].ppt_data!=NULL) free(j2k_cp->tcps[i].ppt_data);
if (j2k_cp->tcps[i].tccps!=NULL) free(j2k_cp->tcps[i].tccps);
}
if (j2k_cp->ppm_data!=NULL) free(j2k_cp->ppm_data);
if (j2k_cp->tcps!=NULL) free(j2k_cp->tcps);
if (j2k_img->comps!=NULL) free(j2k_img->comps);
if (j2k_cp->tileno!=NULL) free(j2k_cp->tileno);
}
#ifdef WIN32
#include <windows.h>

View File

@ -220,4 +220,6 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t * img,
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp);
void j2k_dec_release();//antonin
#endif

View File

@ -1614,6 +1614,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
fprintf(stderr, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
for (compno = 0; compno < tile->numcomps; compno++) {
free(tcd_image.tiles[tileno].comps[compno].data);
}
@ -1624,3 +1625,30 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
return l;
}
void tcd_dec_release()
{
int tileno,compno,resno,bandno,precno;
for (tileno=0;tileno<tcd_image.tw*tcd_image.th;tileno++) {
tcd_tile_t tile=tcd_image.tiles[tileno];
for (compno=0;compno<tile.numcomps;compno++) {
tcd_tilecomp_t tilec=tile.comps[compno];
for (resno=0;resno<tilec.numresolutions;resno++) {
tcd_resolution_t res=tilec.resolutions[resno];
for (bandno=0;bandno<res.numbands;bandno++) {
tcd_band_t band=res.bands[bandno];
for (precno=0;precno<res.ph*res.pw;precno++) {
tcd_precinct_t prec=band.precincts[precno];
if (prec.cblks!=NULL) free(prec.cblks);
if (prec.imsbtree!=NULL) free(prec.imsbtree);
if (prec.incltree!=NULL) free(prec.incltree);
}
if (band.precincts!=NULL) free(band.precincts);
}
}
if (tilec.resolutions!=NULL) free(tilec.resolutions);
}
if (tile.comps!=NULL) free(tile.comps);
}
if (tcd_image.tiles!=NULL) free(tcd_image.tiles);
}

View File

@ -179,4 +179,6 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
*/
int tcd_decode_tile(unsigned char *src, int len, int tileno);
void tcd_dec_release();
#endif