From 531f7ea84daa607e370757d82d8bf7e300fc76b5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 24 Oct 2017 16:00:54 +0200 Subject: Fix colorspace reference counting in fz_load_*_info. These are called from fz_new_image_from_buffer. --- source/fitz/load-pnm.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'source/fitz/load-pnm.c') diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c index 0a1fa3f4..95c613c0 100644 --- a/source/fitz/load-pnm.c +++ b/source/fitz/load-pnm.c @@ -623,35 +623,18 @@ pnm_read_image(fz_context *ctx, struct info *pnm, const unsigned char *p, size_t fz_pixmap * fz_load_pnm(fz_context *ctx, const unsigned char *p, size_t total) { - fz_pixmap *img = NULL; struct info pnm = { 0 }; - - fz_try(ctx) - img = pnm_read_image(ctx, &pnm, p, total, 0); - fz_always(ctx) - fz_drop_colorspace(ctx, pnm.cs); - fz_catch(ctx) - fz_rethrow(ctx); - - return img; + return pnm_read_image(ctx, &pnm, p, total, 0); } void fz_load_pnm_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep) { struct info pnm = { 0 }; - - fz_try(ctx) - { - pnm_read_image(ctx, &pnm, p, total, 1); - *cspacep = pnm.cs; - *wp = pnm.width; - *hp = pnm.height; - *xresp = 72; - *yresp = 72; - } - fz_always(ctx) - fz_drop_colorspace(ctx, pnm.cs); - fz_catch(ctx) - fz_rethrow(ctx); + (void) pnm_read_image(ctx, &pnm, p, total, 1); + *cspacep = fz_keep_colorspace(ctx, pnm.cs); /* pnm.cs is a borrowed device colorspace */ + *wp = pnm.width; + *hp = pnm.height; + *xresp = 72; + *yresp = 72; } -- cgit v1.2.3