aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_DCT.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-09-16 05:08:58 +0200
committerJay Berkenbilt <ejb@ql.org>2017-09-16 05:09:04 +0200
commit249e95f608200ec9e4c43bbbe75a66ab67ad0745 (patch)
tree153b48eacbd3e0829c2fbff3c9fac9a79255405e /libqpdf/Pl_DCT.cc
parent6898bc8d9815f84e80a0bf7b72150947bb634094 (diff)
downloadqpdf-249e95f608200ec9e4c43bbbe75a66ab67ad0745.tar.zst
Fix test failure on MSVC
Diffstat (limited to 'libqpdf/Pl_DCT.cc')
-rw-r--r--libqpdf/Pl_DCT.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc
index b9d54b86..8e1a5177 100644
--- a/libqpdf/Pl_DCT.cc
+++ b/libqpdf/Pl_DCT.cc
@@ -68,6 +68,20 @@ Pl_DCT::finish()
{
this->buf.finish();
+ // Using a PointerHolder<Buffer> here and passing it into compress
+ // and decompress causes a memory leak with setjmp/longjmp. Just
+ // use a pointer and delete it.
+ Buffer* b = this->buf.getBuffer();
+ if (b->getSize() == 0)
+ {
+ // Special case: empty data will never succeed and probably
+ // means we're calling finish a second time from an exception
+ // handler.
+ delete b;
+ this->getNext()->finish();
+ return;
+ }
+
struct jpeg_compress_struct cinfo_compress;
struct jpeg_decompress_struct cinfo_decompress;
struct qpdf_jpeg_error_mgr jerr;
@@ -77,10 +91,6 @@ Pl_DCT::finish()
jerr.pub.error_exit = error_handler;
bool error = false;
- // Using a PointerHolder<Buffer> here and passing it into compress
- // and decompress causes a memory leak with setjmp/longjmp. Just
- // use a pointer and delete it.
- Buffer* b = this->buf.getBuffer();
// The jpeg library is a "C" library, so we use setjmp and longjmp
// for exception handling.
if (setjmp(jerr.jmpbuf) == 0)