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 <allan.jensen@theqtcompany.com>
This commit is contained in:
parent
8a928783b9
commit
6f244dc84d
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user