From 5df654ace40225a02b651cd044d1baff0da8ae52 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Thu, 2 Jan 2014 19:38:14 +0100 Subject: [PATCH] Fix memory leak in Gallium EGL driver With this patch, the reference count of the textures created in 'Surface::_validate()' gets decreased in the '~Surface()' destructor. Fixes #1012. --- libports/src/lib/egl/driver.cc | 7 ++++++ .../nitpicker/qnitpickerglcontext.cpp | 24 ------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/libports/src/lib/egl/driver.cc b/libports/src/lib/egl/driver.cc index 06c5e5931..081bdf02f 100644 --- a/libports/src/lib/egl/driver.cc +++ b/libports/src/lib/egl/driver.cc @@ -411,6 +411,13 @@ class Surface : public native_surface wait = _wait; } + ~Surface() + { + for (int i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) + if (_textures[i]) + pipe_texture_reference(&_textures[i], 0); + } + /** * Return texture used as backing store for the surface */ diff --git a/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qnitpickerglcontext.cpp b/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qnitpickerglcontext.cpp index 5d560387a..52b460d90 100644 --- a/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qnitpickerglcontext.cpp +++ b/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qnitpickerglcontext.cpp @@ -81,13 +81,6 @@ bool QNitpickerGLContext::makeCurrent(QPlatformSurface *surface) if (qnglc_verbose) PDBG("w->framebuffer() = %p", w->framebuffer()); -#if 0 - - /* - * Unfortunalety, this code triggers a memory leak somewhere, - * so it cannot be used yet. - */ - if (w->egl_surface() != EGL_NO_SURFACE) if (!eglDestroySurface(_egl_display, w->egl_surface())) qFatal("eglDestroySurface() failed"); @@ -100,23 +93,6 @@ bool QNitpickerGLContext::makeCurrent(QPlatformSurface *surface) w->egl_surface(egl_surface); -#else - - /* temporary workaround, the surface gets created only once */ - - if (w->egl_surface() == EGL_NO_SURFACE) { - - EGLSurface egl_surface = - eglCreateWindowSurface(_egl_display, _egl_config, &egl_window, 0); - - if (egl_surface == EGL_NO_SURFACE) - qFatal("eglCreateiWindowSurface() failed"); - - w->egl_surface(egl_surface); - } - -#endif - if (!eglMakeCurrent(_egl_display, w->egl_surface(), w->egl_surface(), _egl_context)) qFatal("eglMakeCurrent() failed");