Commit 249e95f608200ec9e4c43bbbe75a66ab67ad0745
1 parent
6898bc8d
Fix test failure on MSVC
Showing
1 changed file
with
14 additions
and
4 deletions
libqpdf/Pl_DCT.cc
| @@ -68,6 +68,20 @@ Pl_DCT::finish() | @@ -68,6 +68,20 @@ Pl_DCT::finish() | ||
| 68 | { | 68 | { |
| 69 | this->buf.finish(); | 69 | this->buf.finish(); |
| 70 | 70 | ||
| 71 | + // Using a PointerHolder<Buffer> here and passing it into compress | ||
| 72 | + // and decompress causes a memory leak with setjmp/longjmp. Just | ||
| 73 | + // use a pointer and delete it. | ||
| 74 | + Buffer* b = this->buf.getBuffer(); | ||
| 75 | + if (b->getSize() == 0) | ||
| 76 | + { | ||
| 77 | + // Special case: empty data will never succeed and probably | ||
| 78 | + // means we're calling finish a second time from an exception | ||
| 79 | + // handler. | ||
| 80 | + delete b; | ||
| 81 | + this->getNext()->finish(); | ||
| 82 | + return; | ||
| 83 | + } | ||
| 84 | + | ||
| 71 | struct jpeg_compress_struct cinfo_compress; | 85 | struct jpeg_compress_struct cinfo_compress; |
| 72 | struct jpeg_decompress_struct cinfo_decompress; | 86 | struct jpeg_decompress_struct cinfo_decompress; |
| 73 | struct qpdf_jpeg_error_mgr jerr; | 87 | struct qpdf_jpeg_error_mgr jerr; |
| @@ -77,10 +91,6 @@ Pl_DCT::finish() | @@ -77,10 +91,6 @@ Pl_DCT::finish() | ||
| 77 | jerr.pub.error_exit = error_handler; | 91 | jerr.pub.error_exit = error_handler; |
| 78 | 92 | ||
| 79 | bool error = false; | 93 | bool error = false; |
| 80 | - // Using a PointerHolder<Buffer> here and passing it into compress | ||
| 81 | - // and decompress causes a memory leak with setjmp/longjmp. Just | ||
| 82 | - // use a pointer and delete it. | ||
| 83 | - Buffer* b = this->buf.getBuffer(); | ||
| 84 | // The jpeg library is a "C" library, so we use setjmp and longjmp | 94 | // The jpeg library is a "C" library, so we use setjmp and longjmp |
| 85 | // for exception handling. | 95 | // for exception handling. |
| 86 | if (setjmp(jerr.jmpbuf) == 0) | 96 | if (setjmp(jerr.jmpbuf) == 0) |