summaryrefslogtreecommitdiff
path: root/fitz/filt_flate.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-15 21:25:04 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-15 21:25:04 +0000
commit7992dd366101180c050f37167d91518c52cf025c (patch)
treef85ad161cba95a6355c52c1c97b57b5380cef6d1 /fitz/filt_flate.c
parentddbce91f5b70281f84a742845e9228ccfb607756 (diff)
downloadmupdf-7992dd366101180c050f37167d91518c52cf025c.tar.xz
More Memsqueezing fixes.
Diffstat (limited to 'fitz/filt_flate.c')
-rw-r--r--fitz/filt_flate.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c
index d7077bc8..9b3370c4 100644
--- a/fitz/filt_flate.c
+++ b/fitz/filt_flate.c
@@ -12,7 +12,7 @@ struct fz_flate_s
static void *zalloc(void *opaque, unsigned int items, unsigned int size)
{
- return fz_malloc_array(opaque, items, size);
+ return fz_malloc_array_no_throw(opaque, items, size);
}
static void zfree(void *opaque, void *ptr)
@@ -84,20 +84,34 @@ fz_stream *
fz_open_flated(fz_stream *chain)
{
fz_flate *state;
- int code;
+ int code = Z_OK;
+ fz_context *ctx = chain->ctx;
+ fz_stream *stream;
+
+ fz_var(code);
- state = fz_malloc(chain->ctx, sizeof(fz_flate));
+ state = fz_malloc(ctx, sizeof(fz_flate));
state->chain = chain;
state->z.zalloc = zalloc;
state->z.zfree = zfree;
- state->z.opaque = chain->ctx;
+ state->z.opaque = ctx;
state->z.next_in = NULL;
state->z.avail_in = 0;
- code = inflateInit(&state->z);
- if (code != Z_OK)
- fz_warn(chain->ctx, "zlib error: inflateInit: %s", state->z.msg);
-
- return fz_new_stream(chain->ctx, state, read_flated, close_flated);
+ fz_try(ctx)
+ {
+ code = inflateInit(&state->z);
+ if (code != Z_OK)
+ fz_throw(ctx, "zlib error: inflateInit: %s", state->z.msg);
+ stream = fz_new_stream(chain->ctx, state, read_flated, close_flated);
+ }
+ fz_catch(ctx)
+ {
+ if (code == Z_OK)
+ inflateEnd(&state->z);
+ fz_free(ctx, state);
+ fz_rethrow(ctx);
+ }
+ return stream;
}