From 67dc887e53e8f147910161efe6b239674b71820e Mon Sep 17 00:00:00 2001 From: slmistry Date: Thu, 10 Sep 2015 13:01:25 +0100 Subject: [PATCH] - Update image creation to include a copy of the manager. - Fix memory leak in opj_image_destroy --- src/lib/openjp2/image.c | 9 ++++++--- src/lib/openjp2/openjpeg.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/image.c b/src/lib/openjp2/image.c index 7725c8bd..17d4ffc2 100644 --- a/src/lib/openjp2/image.c +++ b/src/lib/openjp2/image.c @@ -42,6 +42,7 @@ opj_image_t* opj_image_create0(opj_manager_t manager) { opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image."); return NULL; } + image->m_manager = manager; return image; } @@ -66,6 +67,7 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_create(opj_manager_t manager opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image."); return NULL; } + image->m_manager = manager; image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ @@ -100,9 +102,9 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_create(opj_manager_t manager void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { - opj_manager_t l_manager = opj_manager_get_global_manager(); - - opj_manager_image_destroy(l_manager, image); + if (image) { + opj_manager_image_destroy(image->m_manager, image); + } } OPJ_API void OPJ_CALLCONV opj_manager_image_destroy(opj_manager_t manager, opj_image_t *image) @@ -243,6 +245,7 @@ opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_c return opj_manager_image_tile_create(l_manager, numcmpts, cmptparms, clrspc); } + OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_tile_create(opj_manager_t manager, OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { OPJ_UINT32 compno; diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 12f3f582..d85a8fd1 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -749,6 +749,8 @@ typedef struct opj_image { OPJ_BYTE *icc_profile_buf; /** size of ICC profile */ OPJ_UINT32 icc_profile_len; + /** OpenJpeg Manager (memory/event) */ + opj_manager_t m_manager; } opj_image_t;