From 79c659e08773aa7119cd5537cdd9f6a208fe49a4 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 24 Jun 2017 16:36:50 +0800 Subject: Handle pnm/pam band writers throwing exceptions. --- source/fitz/output-pnm.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/fitz/output-pnm.c b/source/fitz/output-pnm.c index 496d8ea0..2b39899e 100644 --- a/source/fitz/output-pnm.c +++ b/source/fitz/output-pnm.c @@ -123,9 +123,15 @@ void fz_write_pixmap_as_pnm(fz_context *ctx, fz_output *out, fz_pixmap *pixmap) { fz_band_writer *writer = fz_new_pnm_band_writer(ctx, out); - fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, 0, 0, 0, pixmap->colorspace); - fz_write_band(ctx, writer, pixmap->stride, pixmap->h, pixmap->samples); - fz_drop_band_writer(ctx, writer); + fz_try(ctx) + { + fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, 0, 0, 0, pixmap->colorspace); + fz_write_band(ctx, writer, pixmap->stride, pixmap->h, pixmap->samples); + } + fz_always(ctx) + fz_drop_band_writer(ctx, writer); + fz_catch(ctx) + fz_rethrow(ctx); } void @@ -220,9 +226,15 @@ void fz_write_pixmap_as_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap) { fz_band_writer *writer = fz_new_pam_band_writer(ctx, out); - fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, 0, 0, 0, pixmap->colorspace); - fz_write_band(ctx, writer, pixmap->stride, pixmap->h, pixmap->samples); - fz_drop_band_writer(ctx, writer); + fz_try(ctx) + { + fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, 0, 0, 0, pixmap->colorspace); + fz_write_band(ctx, writer, pixmap->stride, pixmap->h, pixmap->samples); + } + fz_always(ctx) + fz_drop_band_writer(ctx, writer); + fz_catch(ctx) + fz_rethrow(ctx); } void -- cgit v1.2.3