diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2021-03-10 01:38:44 +0100 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2021-03-10 13:40:00 +0100 |
commit | 69c909b087376970d24e92e7b479f1981b94f070 (patch) | |
tree | 7ad71811a1474ca656d4eb57be9ec8c679eb6f98 /jbig2dec | |
parent | 0309f0a2363f496d75f22d43ce543db5babcc486 (diff) | |
download | ghostpdl-69c909b087376970d24e92e7b479f1981b94f070.tar.gz |
Bug 703653: jbig2dec: Use correct freeing function for JBIG2 images.
When jbig2_image_compose() errors out, remember to release all allocated
pattern images. Previously the most recently allocated image would not
be release.
Finally remember to free the array of images itself.
Diffstat (limited to 'jbig2dec')
-rw-r--r-- | jbig2dec/jbig2_halftone.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/jbig2dec/jbig2_halftone.c b/jbig2dec/jbig2_halftone.c index 9c275f29c..78902f8e7 100644 --- a/jbig2dec/jbig2_halftone.c +++ b/jbig2dec/jbig2_halftone.c @@ -73,8 +73,10 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im new->patterns[i] = jbig2_image_new(ctx, HPW, HPH); if (new->patterns[i] == NULL) { jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate pattern element image"); + /* new->patterns[i] above did not succeed, so releasing patterns 0..i-1 is enough */ for (j = 0; j < i; j++) - jbig2_free(ctx->allocator, new->patterns[j]); + jbig2_image_release(ctx, new->patterns[j]); + jbig2_free(ctx->allocator, new->patterns); jbig2_free(ctx->allocator, new); return NULL; } @@ -84,8 +86,10 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im code = jbig2_image_compose(ctx, new->patterns[i], image, -i * (int32_t) HPW, 0, JBIG2_COMPOSE_REPLACE); if (code < 0) { jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to compose image into collective bitmap dictionary"); - for (j = 0; j < i; j++) - jbig2_free(ctx->allocator, new->patterns[j]); + /* new->patterns[i] above succeeded, so release all patterns 0..i */ + for (j = 0; j <= i; j++) + jbig2_image_release(ctx, new->patterns[j]); + jbig2_free(ctx->allocator, new->patterns); jbig2_free(ctx->allocator, new); return NULL; } |