Commit 249e95f608200ec9e4c43bbbe75a66ab67ad0745

Authored by Jay Berkenbilt
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 68 {
69 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 85 struct jpeg_compress_struct cinfo_compress;
72 86 struct jpeg_decompress_struct cinfo_decompress;
73 87 struct qpdf_jpeg_error_mgr jerr;
... ... @@ -77,10 +91,6 @@ Pl_DCT::finish()
77 91 jerr.pub.error_exit = error_handler;
78 92  
79 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 94 // The jpeg library is a "C" library, so we use setjmp and longjmp
85 95 // for exception handling.
86 96 if (setjmp(jerr.jmpbuf) == 0)
... ...