mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-05-25 13:08:28 -04:00
JXR: fix memory leaks
This commit is contained in:
@@ -48,7 +48,7 @@ Depending on the format, you can specify the following additional options.
|
|||||||
|
|
||||||
- `--help`: Displays help on commandline options.
|
- `--help`: Displays help on commandline options.
|
||||||
- `--fuzz <max>`: The fuzziness. Used to add some deviation in ARGB data
|
- `--fuzz <max>`: The fuzziness. Used to add some deviation in ARGB data
|
||||||
(nornally used on lossy codec).
|
(normally used on lossy codec).
|
||||||
- `--perceptive-fuzz`: Used to scale dynamically the fuzziness based on
|
- `--perceptive-fuzz`: Used to scale dynamically the fuzziness based on
|
||||||
the alpha channel value. This is useful on images with pre-multiplied and
|
the alpha channel value. This is useful on images with pre-multiplied and
|
||||||
small alphas. Qt can use different roundings based on optimizations resulting
|
small alphas. Qt can use different roundings based on optimizations resulting
|
||||||
|
|||||||
@@ -123,17 +123,17 @@ public:
|
|||||||
|
|
||||||
~JXRHandlerPrivate()
|
~JXRHandlerPrivate()
|
||||||
{
|
{
|
||||||
if (pCodecFactory) {
|
|
||||||
PKCreateCodecFactory_Release(&pCodecFactory);
|
|
||||||
}
|
|
||||||
if (pFactory) {
|
|
||||||
PKCreateFactory_Release(&pFactory);
|
|
||||||
}
|
|
||||||
if (pDecoder) {
|
if (pDecoder) {
|
||||||
PKImageDecode_Release(&pDecoder);
|
pDecoder->Release(&pDecoder);
|
||||||
}
|
}
|
||||||
if (pEncoder) {
|
if (pEncoder) {
|
||||||
PKImageEncode_Release(&pEncoder);
|
pEncoder->Release(&pEncoder);
|
||||||
|
}
|
||||||
|
if (pCodecFactory) {
|
||||||
|
pCodecFactory->Release(&pCodecFactory);
|
||||||
|
}
|
||||||
|
if (pFactory) {
|
||||||
|
pFactory->Release(&pFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +556,11 @@ public:
|
|||||||
if (device == nullptr || pEncoder == nullptr) {
|
if (device == nullptr || pEncoder == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (auto err = PKImageEncode_Release(&pEncoder)) {
|
if (auto err = pEncoder->Terminate(pEncoder)) {
|
||||||
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandlerPrivate::finalizeWriting() error while terminating the encoder:" << err;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (auto err = pEncoder->Release(&pEncoder)) {
|
||||||
qCWarning(LOG_JXRPLUGIN) << "JXRHandlerPrivate::finalizeWriting() error while releasing the encoder:" << err;
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandlerPrivate::finalizeWriting() error while releasing the encoder:" << err;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -999,13 +1003,13 @@ bool JXRHandler::read(QImage *outImage)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (auto err = pConverter->Initialize(pConverter, d->pDecoder, nullptr, convFmt)) {
|
if (auto err = pConverter->Initialize(pConverter, d->pDecoder, nullptr, convFmt)) {
|
||||||
PKFormatConverter_Release(&pConverter);
|
pConverter->Release(&pConverter);
|
||||||
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to initialize the converter:" << err;
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to initialize the converter:" << err;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (d->pDecoder->WMP.wmiI.cBitsPerUnit == size_t(img.depth())) { // in place conversion
|
if (d->pDecoder->WMP.wmiI.cBitsPerUnit == size_t(img.depth())) { // in place conversion
|
||||||
if (auto err = pConverter->Copy(pConverter, &rect, img.bits(), img.bytesPerLine())) {
|
if (auto err = pConverter->Copy(pConverter, &rect, img.bits(), img.bytesPerLine())) {
|
||||||
PKFormatConverter_Release(&pConverter);
|
pConverter->Release(&pConverter);
|
||||||
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to copy converted data:" << err;
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to copy converted data:" << err;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1014,12 +1018,13 @@ bool JXRHandler::read(QImage *outImage)
|
|||||||
qint64 buffSize = convStrideSize * img.height();
|
qint64 buffSize = convStrideSize * img.height();
|
||||||
qint64 limit = QImageReader::allocationLimit();
|
qint64 limit = QImageReader::allocationLimit();
|
||||||
if (limit && (buffSize + img.sizeInBytes()) > limit * 1024 * 1024) {
|
if (limit && (buffSize + img.sizeInBytes()) > limit * 1024 * 1024) {
|
||||||
|
pConverter->Release(&pConverter);
|
||||||
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to covert due to allocation limit set:" << limit << "MiB";
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to covert due to allocation limit set:" << limit << "MiB";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QVector<quint8> ba(buffSize);
|
QVector<quint8> ba(buffSize);
|
||||||
if (auto err = pConverter->Copy(pConverter, &rect, ba.data(), convStrideSize)) {
|
if (auto err = pConverter->Copy(pConverter, &rect, ba.data(), convStrideSize)) {
|
||||||
PKFormatConverter_Release(&pConverter);
|
pConverter->Release(&pConverter);
|
||||||
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to copy converted data:" << err;
|
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() unable to copy converted data:" << err;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1027,7 +1032,7 @@ bool JXRHandler::read(QImage *outImage)
|
|||||||
std::memcpy(img.scanLine(y), ba.data() + convStrideSize * y, (std::min)(convStrideSize, qint64(img.bytesPerLine())));
|
std::memcpy(img.scanLine(y), ba.data() + convStrideSize * y, (std::min)(convStrideSize, qint64(img.bytesPerLine())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PKFormatConverter_Release(&pConverter);
|
pConverter->Release(&pConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metadata (e.g.: icc profile, description, etc...)
|
// Metadata (e.g.: icc profile, description, etc...)
|
||||||
|
|||||||
Reference in New Issue
Block a user