From 65996a1ffa6937ae5fa1825ef9cac09927163c1c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 11 Oct 2017 20:39:11 +0200 Subject: Use custom allocator everywhere zlib is used. --- source/fitz/output-png.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/fitz/output-png.c') diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c index 59dbba94..15fb41f0 100644 --- a/source/fitz/output-png.c +++ b/source/fitz/output-png.c @@ -4,6 +4,16 @@ #include +static void *zalloc_outpng(void *opaque, unsigned int items, unsigned int size) +{ + return fz_malloc_array_no_throw(opaque, items, size); +} + +static void zfree_outpng(void *opaque, void *address) +{ + fz_free(opaque, address); +} + static inline void big32(unsigned char *buf, unsigned int v) { buf[0] = (v >> 24) & 0xff; @@ -194,6 +204,9 @@ png_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st writer->csize = compressBound(writer->usize); writer->udata = fz_malloc(ctx, writer->usize); writer->cdata = fz_malloc(ctx, writer->csize); + writer->stream.opaque = ctx; + writer->stream.zalloc = zalloc_outpng; + writer->stream.zfree = zfree_outpng; err = deflateInit(&writer->stream, Z_DEFAULT_COMPRESSION); if (err != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); -- cgit v1.2.3