From 978416807b7e92d9317036cb4348ee172dde7d4e Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Fri, 8 Oct 2010 09:08:54 +0200 Subject: Fix memory leak in QPixmap::toSymbianRSgImage() when an error occurs. In the cases where an error occured while converting a QPixmap to a VGImage this function would return without deleting the RSgImage pointer that it created. Fix is to use a QScopedPointer instead. Also don't use q_check_ptr() since this isn't a CBase derived class. In case you are wondering why I didn't use a custom deleter here so that Close() was also called, we need to make sure that Close() is called on the RSgImage instance before calling Close() on the driver. Reviewed-by: mread --- src/openvg/qvg_symbian.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/openvg/qvg_symbian.cpp b/src/openvg/qvg_symbian.cpp index ef0160c..a9625b2 100644 --- a/src/openvg/qvg_symbian.cpp +++ b/src/openvg/qvg_symbian.cpp @@ -228,7 +228,7 @@ void* QVGPixmapData::toNativeType(NativeType type) sgInfo.iSizeInPixels.SetSize(w, h); sgInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface; - RSgImage *sgImage = q_check_ptr(new RSgImage()); + QScopedPointer sgImage(new RSgImage()); err = sgImage->Create(sgInfo, NULL, NULL); if (err != KErrNone) { driver.Close(); @@ -239,7 +239,7 @@ void* QVGPixmapData::toNativeType(NativeType type) EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, - (EGLClientBuffer)sgImage, + (EGLClientBuffer)sgImage.data(), (EGLint*)KEglImageAttribs); if (!eglImage || eglGetError() != EGL_SUCCESS) { sgImage->Close(); @@ -261,13 +261,14 @@ void* QVGPixmapData::toNativeType(NativeType type) if (vgGetError() != VG_NO_ERROR) { sgImage->Close(); - sgImage = 0; + sgImage.reset(); } + // release stuff vgDestroyImage(dstVgImage); QEgl::eglDestroyImageKHR(QEgl::display(), eglImage); driver.Close(); - return reinterpret_cast(sgImage); + return reinterpret_cast(sgImage.take()); #endif } else if (type == QPixmapData::FbsBitmap) { CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); -- cgit v0.12