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_dctd.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_dctd.c')
-rw-r--r-- | fitz/filt_dctd.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 5fb1a933..bae91195 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -180,14 +180,15 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) } static void -close_dctd(fz_stream *stm) +close_dctd(fz_context *ctx, void *state_) { - fz_dctd *state = stm->state; + fz_dctd *state = (fz_dctd *)state_; if (setjmp(state->jb)) { - state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; - fz_warn(state->ctx, "jpeg error: %s", state->msg); + if (state->cinfo.src) + state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; + fz_warn(ctx, "jpeg error: %s", state->msg); goto skip; } @@ -195,11 +196,12 @@ close_dctd(fz_stream *stm) jpeg_finish_decompress(&state->cinfo); skip: - state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; + if (state->cinfo.src) + state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; jpeg_destroy_decompress(&state->cinfo); - fz_free(stm->ctx, state->scanline); + fz_free(ctx, state->scanline); fz_close(state->chain); - fz_free(stm->ctx, state); + fz_free(ctx, state); } fz_stream * |