diff options
author | Jay Berkenbilt <ejb@ql.org> | 2017-08-22 16:51:21 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2017-08-22 20:13:10 +0200 |
commit | 83ec09f66c4548d356423894708e6727aaa39c88 (patch) | |
tree | 6eeda68288a72a8a1d90a908d5a624e55e3c43fc /libqpdf | |
parent | 85ef2cb6fd3d3e9dbeee013eceeb19b9f3c7f731 (diff) | |
download | qpdf-83ec09f66c4548d356423894708e6727aaa39c88.tar.zst |
Do memory checks
Slightly improve memory cleanup in Pl_DCT
Make it easier to test with valgrind
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/Pl_DCT.cc | 22 |
1 files changed, 20 insertions, 2 deletions
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<Buffer> b) { @@ -124,6 +143,7 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder<Buffer> 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<Buffer> b) jpeg_finish_compress(cinfo); this->getNext()->write(outbuffer, outsize); this->getNext()->finish(); - - free(outbuffer); } void |