From 83ec09f66c4548d356423894708e6727aaa39c88 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 22 Aug 2017 10:51:21 -0400 Subject: Do memory checks Slightly improve memory cleanup in Pl_DCT Make it easier to test with valgrind --- libqpdf/Pl_DCT.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'libqpdf/Pl_DCT.cc') diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index 68cdc973..121ee273 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -107,6 +107,25 @@ Pl_DCT::finish() } } +class Freer +{ + public: + Freer(unsigned char** p) : + p(p) + { + } + ~Freer() + { + if (*p) + { + free(*p); + } + } + + private: + unsigned char** p; +}; + void Pl_DCT::compress(void* cinfo_p, PointerHolder b) { @@ -124,6 +143,7 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder b) # pragma GCC diagnostic pop #endif unsigned char* outbuffer = 0; + Freer freer(&outbuffer); unsigned long outsize = 0; jpeg_mem_dest(cinfo, &outbuffer, &outsize); @@ -160,8 +180,6 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder b) jpeg_finish_compress(cinfo); this->getNext()->write(outbuffer, outsize); this->getNext()->finish(); - - free(outbuffer); } void -- cgit v1.2.3-54-g00ecf