From c53b6af33c996a7ae6815ac15254297d43f43a9c Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Sat, 17 Dec 2011 00:07:09 +0000 Subject: 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. --- fitz/filt_faxd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'fitz/filt_faxd.c') diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index be88eda1..309844bf 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -643,9 +643,9 @@ rtc: } static void -close_faxd(fz_stream *stm) +close_faxd(fz_context *ctx, void *state_) { - fz_faxd *fax = stm->state; + fz_faxd *fax = (fz_faxd *)state_; int i; /* if we read any extra bytes, try to put them back */ @@ -654,9 +654,9 @@ close_faxd(fz_stream *stm) fz_unread_byte(fax->chain); fz_close(fax->chain); - fz_free(stm->ctx, fax->ref); - fz_free(stm->ctx, fax->dst); - fz_free(stm->ctx, fax); + fz_free(ctx, fax->ref); + fz_free(ctx, fax->dst); + fz_free(ctx, fax); } fz_stream * @@ -665,7 +665,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fz_faxd *fax; fz_obj *obj; fz_context *ctx; - fz_stream *stream; assert(chain); ctx = chain->ctx; @@ -724,8 +723,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) memset(fax->ref, 0, fax->stride); memset(fax->dst, 0, fax->stride); - - stream = fz_new_stream(ctx, fax, read_faxd, close_faxd); } fz_catch(ctx) { @@ -734,5 +731,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fz_free(ctx, fax); fz_rethrow(ctx); } - return stream; + + return fz_new_stream(ctx, fax, read_faxd, close_faxd); } -- cgit v1.2.3