summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonin Descampe <antonin@gmail.com>2004-08-06 14:13:51 +0000
committerAntonin Descampe <antonin@gmail.com>2004-08-06 14:13:51 +0000
commitbc5c5115cbd4b5d6500348f7af2fa49e02b216ce (patch)
tree66c869d78bf9a64845e59a3df7a36330595c7e26
parent61ac18531a62bcc31552875d2d9c5458bac452e2 (diff)
* Inserted tool for memory leaks fixing in debug mode
* Fixed some memory leaks in the decoder (some are still present when multiple tiles!)
-rw-r--r--codec/image_to_j2k.c15
-rw-r--r--codec/j2k_to_image.c24
-rw-r--r--libopenjpeg/j2k.c22
-rw-r--r--libopenjpeg/j2k.h2
-rw-r--r--libopenjpeg/tcd.c28
-rw-r--r--libopenjpeg/tcd.h2
6 files changed, 89 insertions, 4 deletions
diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c
index 54bd0c92..e7047026 100644
--- a/codec/image_to_j2k.c
+++ b/codec/image_to_j2k.c
@@ -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;
}
diff --git a/codec/j2k_to_image.c b/codec/j2k_to_image.c
index 53104736..f1534d53 100644
--- a/codec/j2k_to_image.c
+++ b/codec/j2k_to_image.c
@@ -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;
}
diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c
index e8f766e4..6c611adf 100644
--- a/libopenjpeg/j2k.c
+++ b/libopenjpeg/j2k.c
@@ -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>
diff --git a/libopenjpeg/j2k.h b/libopenjpeg/j2k.h
index aafa9de6..7df8ecc7 100644
--- a/libopenjpeg/j2k.h
+++ b/libopenjpeg/j2k.h
@@ -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
diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c
index ab71c129..ff9e0c95 100644
--- a/libopenjpeg/tcd.c
+++ b/libopenjpeg/tcd.c
@@ -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);
+}
diff --git a/libopenjpeg/tcd.h b/libopenjpeg/tcd.h
index 6e64717d..3201243d 100644
--- a/libopenjpeg/tcd.h
+++ b/libopenjpeg/tcd.h
@@ -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