From 4457ebd282a03b05491e5dd118568423dc3c1837 Mon Sep 17 00:00:00 2001 From: Carlos Castillo Date: Fri, 15 Aug 2014 18:14:58 -0700 Subject: [PATCH] cpp/capi.cpp: fix ImageProvider leak GoImageProvider had a memory leak where it got a pointer to a QImage, and never freed it. Qt already has a refcounting system in place so every QImage is actually a pointer to pixel data, but it relies on the destructor for every QImage instance to be called. --- cpp/capi.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cpp/capi.cpp b/cpp/capi.cpp index 54a3cbd0..73517a1d 100644 --- a/cpp/capi.cpp +++ b/cpp/capi.cpp @@ -139,12 +139,15 @@ class GoImageProvider : public QQuickImageProvider { width = requestedSize.width(); height = requestedSize.height(); } - QImage *image = reinterpret_cast(hookRequestImage(imageFunc, (char*)ba.constData(), ba.size(), width, height)); - *size = image->size(); + QImage *ptr = reinterpret_cast(hookRequestImage(imageFunc, (char*)ba.constData(), ba.size(), width, height)); + QImage image = *ptr; + delete ptr; + + *size = image.size(); if (requestedSize.isValid() && requestedSize != *size) { - *image = image->scaled(requestedSize, Qt::KeepAspectRatio); + image = image.scaled(requestedSize, Qt::KeepAspectRatio); } - return *image; + return image; }; private: