diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:07:09 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-17 00:07:09 +0000 |
commit | c53b6af33c996a7ae6815ac15254297d43f43a9c (patch) | |
tree | fb3a9d65ec564cacc60d8a59b2310867ae0926cb /fitz/filt_flate.c | |
parent | 6888c5757779610c9da201e34b70c1800b898616 (diff) | |
download | mupdf-c53b6af33c996a7ae6815ac15254297d43f43a9c.tar.xz |
Change stream 'close' functions to facilitate error cleanup.
Rather than passing a stream to a close function, just pass context
and state - that's all that is required. This enables us to
call close to cleanup neatly if the stream fails to allocate.
Diffstat (limited to 'fitz/filt_flate.c')
-rw-r--r-- | fitz/filt_flate.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index aafb0fc7..d83228a1 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -67,17 +67,17 @@ read_flated(fz_stream *stm, unsigned char *outbuf, int outlen) } static void -close_flated(fz_stream *stm) +close_flated(fz_context *ctx, void *state_) { - fz_flate *state = stm->state; + fz_flate *state = (fz_flate *)state_; int code; code = inflateEnd(&state->z); if (code != Z_OK) - fz_warn(stm->ctx, "zlib error: inflateEnd: %s", state->z.msg); + fz_warn(ctx, "zlib error: inflateEnd: %s", state->z.msg); fz_close(state->chain); - fz_free(stm->ctx, state); + fz_free(ctx, state); } fz_stream * @@ -86,7 +86,6 @@ fz_open_flated(fz_stream *chain) fz_flate *state; int code = Z_OK; fz_context *ctx = chain->ctx; - fz_stream *stream; fz_var(code); @@ -104,7 +103,6 @@ fz_open_flated(fz_stream *chain) 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) { @@ -113,5 +111,5 @@ fz_open_flated(fz_stream *chain) fz_free(ctx, state); fz_rethrow(ctx); } - return stream; + return fz_new_stream(chain->ctx, state, read_flated, close_flated); } |