* 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:
parent
61ac18531a
commit
bc5c5115cb
|
@ -26,6 +26,14 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* 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 <openjpeg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -895,5 +903,12 @@ int main(int argc, char **argv)
|
||||||
free(cp.tcps[tileno].tccps);
|
free(cp.tcps[tileno].tccps);
|
||||||
free(cp.tcps);
|
free(cp.tcps);
|
||||||
|
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,14 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* 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 <openjpeg.h>
|
||||||
|
@ -39,9 +47,9 @@ int ceildiv(int a, int b)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f=NULL;
|
||||||
char *src, *src_name;
|
char *src=NULL, *src_name=NULL;
|
||||||
char *dest, S1, S2, S3;
|
char *dest=NULL, S1, S2, S3;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
j2k_image_t img;
|
j2k_image_t img;
|
||||||
|
@ -50,7 +58,7 @@ int main(int argc, char **argv)
|
||||||
int w, wr, wrr, h, hr, hrr, max;
|
int w, wr, wrr, h, hr, hrr, max;
|
||||||
int i, image_type = -1, compno, pad, j;
|
int i, image_type = -1, compno, pad, j;
|
||||||
int adjust;
|
int adjust;
|
||||||
jp2_struct_t *jp2_struct;
|
jp2_struct_t *jp2_struct=NULL;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -553,5 +561,13 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j2k_dec_release();
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1458,6 +1458,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
j2k_dec_mstabent_t *e;
|
j2k_dec_mstabent_t *e;
|
||||||
int id = cio_read(2);
|
int id = cio_read(2);
|
||||||
if (id >> 8 != 0xff) {
|
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) {
|
if (e->handler) {
|
||||||
(*e->handler) ();
|
(*e->handler) ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j2k_state == J2K_STATE_NEOC)
|
if (j2k_state == J2K_STATE_NEOC)
|
||||||
break; /* RAJOUTE */
|
break; /* RAJOUTE */
|
||||||
}
|
}
|
||||||
|
@ -1562,6 +1564,26 @@ j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
||||||
return 0;
|
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
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.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,
|
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
||||||
j2k_cp_t * cp);
|
j2k_cp_t * cp);
|
||||||
|
|
||||||
|
void j2k_dec_release();//antonin
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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,
|
fprintf(stderr, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
||||||
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
free(tcd_image.tiles[tileno].comps[compno].data);
|
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;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
int tcd_decode_tile(unsigned char *src, int len, int tileno);
|
||||||
|
|
||||||
|
void tcd_dec_release();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue