ref: 1d120cab65c74fe97e4e4512f6a034f0fba0cac5
parent: b1bfe4ae823054ac2dc94af15246fa489304cf80
author: Robin Watts <robin.watts@artifex.com>
date: Tue Jan 24 08:20:11 EST 2012
Tweak jbig2dec to cope better with NULLs. Fix various destructors in jbig2dec to cope with being called with image = NULL. This cures a problem in mupdf where it SEGVs when called on "1239 - skip invalid content streams.pdf" from the sumatra test set.
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -60,7 +60,8 @@
/* clone an image pointer by bumping its reference count */
Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image)
{
- image->refcount++;
+ if (image)
+ image->refcount++;
return image;
}
@@ -67,6 +68,8 @@
/* release an image pointer, freeing it it appropriate */
void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image)
{
+ if (image == NULL)
+ return;
image->refcount--;
if (!image->refcount) jbig2_image_free(ctx, image);
}
@@ -74,7 +77,8 @@
/* free a Jbig2Image structure and its associated memory */
void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image)
{
- jbig2_free(ctx->allocator, image->data);
+ if (image)
+ jbig2_free(ctx->allocator, image->data);
jbig2_free(ctx->allocator, image);
}