From f17ff4be2c11ea1b8dae8b603574ba6741c0d6a7 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 19 Apr 2024 14:30:15 +0800 Subject: [PATCH] Gui: fix memory leak in QGuiGLThreadContext `QCoreApplicationPrivate::cleanupThreadData` calls `~QGuiGLThreadContext`, which calls `QOpenGLContextPrivate::setCurrentContext`, which creates a new `QGuiGLThreadContext`, which is not destroyed anymore. since `~QGuiGLThreadContext` sets a nullptr we exit early. Fixes: QTBUG-124538 Change-Id: I51e40fcf8fd1169a4dfd336fac9c82f44d42f68e Reviewed-by: Laszlo Agocs (cherry picked from commit d139642aefde2d00683cf29f3875ccfae6c66779) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qopenglcontext.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index d8da482ecc3..ecbae48ec35 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -154,6 +154,9 @@ QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context qWarning("No QTLS available. currentContext won't work"); return nullptr; } + if (!context) + return nullptr; + threadContext = new QGuiGLThreadContext; qwindow_context_storage()->setLocalData(threadContext); }