From 81fbff722576bd59d333456d26eaf848cd44dc80 Mon Sep 17 00:00:00 2001 From: Carlos Castillo Date: Wed, 11 Jun 2014 20:35:11 -0700 Subject: [PATCH] Fixed memory leak in imageprovider. Qt uses "implicit shared memory" for many of its types which is a scheme similar to copy on write, and is tracked by reference counting in the constructors/destructor of its classes. Unfortunately the imageprovider code creates an *QImage, which since it wasn't delete'd the destructor is not called, so when QML is done with its own copies, the shared image data can't be freed. --- cpp/capi.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/capi.cpp b/cpp/capi.cpp index 54a3cbd0..45702d66 100644 --- a/cpp/capi.cpp +++ b/cpp/capi.cpp @@ -140,11 +140,14 @@ class GoImageProvider : public QQuickImageProvider { height = requestedSize.height(); } QImage *image = reinterpret_cast(hookRequestImage(imageFunc, (char*)ba.constData(), ba.size(), width, height)); - *size = image->size(); + QImage tmp = *image; + delete image; + + *size = tmp.size(); if (requestedSize.isValid() && requestedSize != *size) { - *image = image->scaled(requestedSize, Qt::KeepAspectRatio); + tmp = tmp.scaled(requestedSize, Qt::KeepAspectRatio); } - return *image; + return tmp; }; private: