Commit f401ad7a authored by Even Rouault's avatar Even Rouault Committed by Albert Astals Cid

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().
parent 2a115270
......@@ -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();
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment