From 6f244dc84d87f382f584187b8758f6fa918c211c Mon Sep 17 00:00:00 2001 From: Jian Liang Date: Sat, 4 Jul 2015 13:18:27 +0800 Subject: Fix memory leak in QJpegHandlerPrivate Since the introduction of jpeg auto transform, it is possible to read jpeg header after its state was changed from ReadHeaer to Ready which will lead to creating some resources again without releasing them. For example, if you call QImageReader::setAutoTransform(true) and then call QImageReader::read(), QJpegHandlerPrivate::readJpegHeader() will be called twice and it will allocate resource again without releasing the old one. This patch add a new state ReadingEnd to prevent the header from being read twice. Change-Id: If2497f6e3668958c0c792a66e1b77eb2773584a2 Reviewed-by: Allan Sandfeld Jensen --- src/gui/image/qjpeghandler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qjpeghandler.cpp b/src/gui/image/qjpeghandler.cpp index c0fda647aa..e29f9783a6 100644 --- a/src/gui/image/qjpeghandler.cpp +++ b/src/gui/image/qjpeghandler.cpp @@ -710,6 +710,7 @@ public: enum State { Ready, ReadHeader, + ReadingEnd, Error }; @@ -958,7 +959,7 @@ bool QJpegHandlerPrivate::read(QImage *image) for (int i = 0; i < readTexts.size()-1; i+=2) image->setText(readTexts.at(i), readTexts.at(i+1)); - state = Ready; + state = ReadingEnd; return true; } @@ -1006,7 +1007,7 @@ bool QJpegHandler::canRead() const if(d->state == QJpegHandlerPrivate::Ready && !canRead(device())) return false; - if (d->state != QJpegHandlerPrivate::Error) { + if (d->state != QJpegHandlerPrivate::Error && d->state != QJpegHandlerPrivate::ReadingEnd) { setFormat("jpeg"); return true; } -- cgit v1.2.3