diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-19 15:19:40 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-19 15:19:40 +0000 |
commit | 3028fbf00d2d571b6f67001b5c09c15e3e2cfa26 (patch) | |
tree | 7be7037d3a0c4d093d1861a15cae812ae8377d54 /fitz/res_pixmap.c | |
parent | da81dc0f28246b37a487e8ace9443f2689f855c0 (diff) | |
download | mupdf-3028fbf00d2d571b6f67001b5c09c15e3e2cfa26.tar.xz |
More Memory squeezing fixes
Diffstat (limited to 'fitz/res_pixmap.c')
-rw-r--r-- | fitz/res_pixmap.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 99132a31..2ab95678 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -446,12 +446,17 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) static const unsigned char pngsig[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; FILE *fp; unsigned char head[13]; - unsigned char *udata, *cdata, *sp, *dp; + unsigned char *udata = NULL; + unsigned char *cdata = NULL; + unsigned char *sp, *dp; uLong usize, csize; int y, x, k, sn, dn; int color; int err; + fz_var(udata); + fz_var(cdata); + if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) fz_throw(ctx, "pixmap must be grayscale or rgb to write as png"); @@ -471,8 +476,16 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) usize = (pixmap->w * dn + 1) * pixmap->h; csize = compressBound(usize); - udata = fz_malloc(ctx, usize); - cdata = fz_malloc(ctx, csize); + fz_try(ctx) + { + udata = fz_malloc(ctx, usize); + cdata = fz_malloc(ctx, csize); + } + fz_catch(ctx) + { + fz_free(ctx, udata); + fz_rethrow(ctx); + } sp = pixmap->samples; dp = udata; |