poppler/JBIG2Stream.cc | 16 +++++++++++----- poppler/JBIG2Stream.h | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-)
New commits: commit f401ad7a29b95a39db0c2333b2c8f3573374140b Author: Even Rouault <[email protected]> Date: Sun Dec 1 19:15:49 2019 +0000 JBIG2Stream: fix leak in reset() if called several times JBIG2Stream::reset() currently allocates new values for the segments and globalSegments member variable. This causes a memory leak if the method is called several times, which can be triggered by the GDAL library that uses Poppler. So add a freeSegments() method where we move the related cleanup of close(), and call that method from reset() and close(). diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc index 1486fe25..684ed090 100644 --- a/poppler/JBIG2Stream.cc +++ b/poppler/JBIG2Stream.cc @@ -1244,6 +1244,8 @@ JBIG2Stream::~JBIG2Stream() { } void JBIG2Stream::reset() { + freeSegments(); + // read the globals stream globalSegments = new std::vector<JBIG2Segment*>(); if (globalsStream.isStream()) { @@ -1274,11 +1276,7 @@ void JBIG2Stream::reset() { } } -void JBIG2Stream::close() { - if (pageBitmap) { - delete pageBitmap; - pageBitmap = nullptr; - } +void JBIG2Stream::freeSegments() { if (segments) { for (auto entry : *segments) { delete entry; @@ -1293,6 +1291,14 @@ void JBIG2Stream::close() { delete globalSegments; globalSegments = nullptr; } +} + +void JBIG2Stream::close() { + if (pageBitmap) { + delete pageBitmap; + pageBitmap = nullptr; + } + freeSegments(); dataPtr = dataEnd = nullptr; FilterStream::close(); } diff --git a/poppler/JBIG2Stream.h b/poppler/JBIG2Stream.h index 2a82ea14..3feeccc1 100644 --- a/poppler/JBIG2Stream.h +++ b/poppler/JBIG2Stream.h @@ -61,6 +61,8 @@ private: bool hasGetChars() override { return true; } int getChars(int nChars, unsigned char *buffer) override; + void freeSegments(); + void readSegments(); bool readSymbolDictSeg(unsigned int segNum, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs); _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
