diff options
-rw-r--r-- | source/fitz/output-png.c | 9 | ||||
-rw-r--r-- | source/fitz/output-ps.c | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c index 4a325959..87c69428 100644 --- a/source/fitz/output-png.c +++ b/source/fitz/output-png.c @@ -79,6 +79,7 @@ typedef struct png_band_writer_s unsigned char *cdata; uLong usize, csize; z_stream stream; + int stream_ended; } png_band_writer; static void @@ -262,6 +263,7 @@ png_write_trailer(fz_context *ctx, fz_band_writer *writer_) unsigned char block[1]; int err; + writer->stream_ended = 1; err = deflateEnd(&writer->stream); if (err != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); @@ -274,6 +276,13 @@ png_drop_band_writer(fz_context *ctx, fz_band_writer *writer_) { png_band_writer *writer = (png_band_writer *)(void *)writer_; + if (!writer->stream_ended) + { + int err = deflateEnd(&writer->stream); + if (err != Z_OK) + fz_warn(ctx, "ignoring compression error %d", err); + } + fz_free(ctx, writer->cdata); fz_free(ctx, writer->udata); } diff --git a/source/fitz/output-ps.c b/source/fitz/output-ps.c index d3ff0ec3..126c54ff 100644 --- a/source/fitz/output-ps.c +++ b/source/fitz/output-ps.c @@ -6,6 +6,7 @@ typedef struct ps_band_writer_s { fz_band_writer super; z_stream stream; + int stream_ended; int input_size; unsigned char *input; int output_size; @@ -120,6 +121,10 @@ ps_write_trailer(fz_context *ctx, fz_band_writer *writer_) err = deflate(&writer->stream, Z_FINISH); if (err != Z_STREAM_END) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); + writer->stream_ended = 1; + err = deflateEnd(&writer->stream); + if (err != Z_OK) + fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); fz_write_data(ctx, out, writer->output, writer->output_size - writer->stream.avail_out); fz_write_string(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n"); @@ -130,6 +135,13 @@ ps_drop_band_writer(fz_context *ctx, fz_band_writer *writer_) { ps_band_writer *writer = (ps_band_writer *)writer_; + if (!writer->stream_ended) + { + int err = deflateEnd(&writer->stream); + if (err != Z_OK) + fz_warn(ctx, "ignoring compression error %d", err); + } + fz_free(ctx, writer->input); fz_free(ctx, writer->output); } |