diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2016-07-21 22:24:36 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2016-07-22 00:23:05 +0800 |
commit | 2f9914455c957062b0533fdbbbf38d5cb8ae11bd (patch) | |
tree | 6e6b7b387e46358278349f106a45f3a3306760c7 | |
parent | 79170894355bb8c308f6a1c22f03a6a094d546ff (diff) | |
download | mupdf-2f9914455c957062b0533fdbbbf38d5cb8ae11bd.tar.xz |
Fix pixmap and reference leak in pdfextract.
-rw-r--r-- | source/tools/pdfextract.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c index 79bdf37a..92a86be2 100644 --- a/source/tools/pdfextract.c +++ b/source/tools/pdfextract.c @@ -62,24 +62,33 @@ static void writepixmap(fz_context *ctx, fz_pixmap *pix, char *file, int rgb) static void saveimage(int num) { - fz_image *image; - fz_pixmap *pix; + fz_image *image = NULL; + fz_pixmap *pix = NULL; pdf_obj *ref; char buf[32]; ref = pdf_new_indirect(ctx, doc, num, 0); - /* TODO: detect DCTD and save as jpeg */ + fz_var(image); + fz_var(pix); - image = pdf_load_image(ctx, doc, ref); - pix = fz_get_pixmap_from_image(ctx, image, NULL, NULL, 0, 0); - fz_drop_image(ctx, image); - - snprintf(buf, sizeof(buf), "img-%04d", num); - writepixmap(ctx, pix, buf, dorgb); + fz_try(ctx) + { + /* TODO: detect DCTD and save as jpeg */ + image = pdf_load_image(ctx, doc, ref); + pix = fz_get_pixmap_from_image(ctx, image, NULL, NULL, 0, 0); + snprintf(buf, sizeof(buf), "img-%04d", num); + writepixmap(ctx, pix, buf, dorgb); + } + fz_always(ctx) + { + fz_drop_image(ctx, image); + fz_drop_pixmap(ctx, pix); + pdf_drop_obj(ctx, ref); + } + fz_catch(ctx) + fz_rethrow(ctx); - fz_drop_pixmap(ctx, pix); - pdf_drop_obj(ctx, ref); } static void savefont(pdf_obj *dict, int num) |