diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:49:23 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:49:23 +0000 |
commit | 3eae1449777c4ecccc73a156c7dfff42f927ccc4 (patch) | |
tree | b0cd1bc08b3af218dd06c501402782db91ad0523 /fitz/filt_flate.c | |
parent | c53b6af33c996a7ae6815ac15254297d43f43a9c (diff) | |
download | mupdf-3eae1449777c4ecccc73a156c7dfff42f927ccc4.tar.xz |
More memsqueezing fixes; stream creation.
Diffstat (limited to 'fitz/filt_flate.c')
-rw-r--r-- | fitz/filt_flate.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index d83228a1..2eb0c563 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -83,33 +83,35 @@ close_flated(fz_context *ctx, void *state_) fz_stream * fz_open_flated(fz_stream *chain) { - fz_flate *state; + fz_flate *state = NULL; int code = Z_OK; fz_context *ctx = chain->ctx; fz_var(code); - - state = fz_malloc_struct(ctx, fz_flate); - state->chain = chain; - - state->z.zalloc = zalloc; - state->z.zfree = zfree; - state->z.opaque = ctx; - state->z.next_in = NULL; - state->z.avail_in = 0; + fz_var(state); fz_try(ctx) { + state = fz_malloc_struct(ctx, fz_flate); + state->chain = chain; + + state->z.zalloc = zalloc; + state->z.zfree = zfree; + state->z.opaque = ctx; + state->z.next_in = NULL; + state->z.avail_in = 0; + code = inflateInit(&state->z); if (code != Z_OK) fz_throw(ctx, "zlib error: inflateInit: %s", state->z.msg); } fz_catch(ctx) { - if (code == Z_OK) + if (state && code == Z_OK) inflateEnd(&state->z); fz_free(ctx, state); + fz_close(chain); fz_rethrow(ctx); } - return fz_new_stream(chain->ctx, state, read_flated, close_flated); + return fz_new_stream(ctx, state, read_flated, close_flated); } |