[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: fix use after free if window gets resized after the interface unloads
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Nov 19 16:06:00 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
d6adf06f by Pierre Lamot at 2026-11-19T15:56:25+00:00
qt: fix use after free if window gets resized after the interface unloads
When the UI may be unloaded before the video surface is released,
adjustQuickWindowMask will query MainCtx which gets destroyed along with the UI
there is no need to call adjustQuickWindowMask once the UI is destroyed
- - - - -
9c35ded8 by Pierre Lamot at 2026-11-19T15:56:25+00:00
qt: fix use after free while unregistering qml types with qt 6.8
Qt may still reference registered qml types in its destructor after the
QObject::destroyed signal is emitted.
The issue was observed with Qt 6.8, and not present with Qt 6.10 and 6.11
- - - - -
4 changed files:
- modules/gui/qt/maininterface/compositor_wayland.cpp
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/maininterface/mainui.hpp
- modules/gui/qt/qt.cpp
Changes:
=====================================
modules/gui/qt/maininterface/compositor_wayland.cpp
=====================================
@@ -161,6 +161,11 @@ void CompositorWayland::unloadGUI()
//needs to be released before the window
m_interfaceWindowHandler.reset();
+#ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
+ disconnect(m_qmlView.get(), &QWindow::widthChanged, this, &CompositorWayland::adjustQuickWindowMask);
+ disconnect(m_qmlView.get(), &QWindow::heightChanged, this, &CompositorWayland::adjustQuickWindowMask);
+#endif
+
//at this point we need to unload the QML content but the window still need to
//be valid as it may still be used by the vout window.
//we cant' just delete the qmlEngine as the QmlView as the root item is parented to the QmlView
=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -86,6 +86,7 @@
#include "mainctx_submodels.hpp"
static bool g_qmlTypesAreRegistered = false;
+static bool g_qmlTypesClearPending = false;
using namespace vlc::playlist;
@@ -132,9 +133,10 @@ MainUI::~MainUI()
}
else
{
- // `QObject::destroyed()` is signalled just before the object dies, but subclass `QQmlEngine`
- // itself should be dead at that point anyway. This should prevent undefined behavior.
- connect(m_engineBound, &QObject::destroyed, &MainUI::clearQMLTypes);
+ // The engine is still alive, the types can't be cleared yet
+ // Qt 6.8 still references theses types when destroying the QQmlEngine (after the QObject::destroyed signal)
+ // we can clear them manually in qt.cpp after the compositor (and the engine) is destroyed
+ g_qmlTypesClearPending = true;
}
}
@@ -207,6 +209,8 @@ end:
void MainUI::registerQMLTypes()
{
+ // types of a previous instance whose engine is now destroyed
+ clearPendingQMLTypes();
assert(!g_qmlTypesAreRegistered);
{
@@ -487,4 +491,11 @@ void MainUI::clearQMLTypes()
{
qmlClearTypeRegistrations();
g_qmlTypesAreRegistered = false;
+ g_qmlTypesClearPending = false;
+}
+
+void MainUI::clearPendingQMLTypes()
+{
+ if (g_qmlTypesClearPending)
+ clearQMLTypes();
}
=====================================
modules/gui/qt/maininterface/mainui.hpp
=====================================
@@ -33,6 +33,9 @@ public:
VLC_USED
QQuickItem* createRootItem();
+ // Clear the QML types registered by a destroyed MainUI, no QML engine must exist at this point
+ static void clearPendingQMLTypes();
+
private:
void registerQMLTypes();
static void clearQMLTypes();
=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -91,6 +91,7 @@ extern "C" char **environ;
#include "dialogs/help/help.hpp" /* Launch Update */
#include "util/dismiss_popup_event_filter.hpp"
#include "maininterface/compositor.hpp"
+#include "maininterface/mainui.hpp"
#include "util/vlctick.hpp"
#include "util/shared_input_item.hpp"
#include "util/vlcqtmessagehandler.hpp"
@@ -1480,6 +1481,9 @@ static void *ThreadCleanup( qt_intf_t *p_intf, CleanupReason cleanupReason )
{
p_intf->p_compositor.reset();
+ // the QML engines are destroyed along with the compositor
+ MainUI::clearPendingQMLTypes();
+
delete p_intf->mainSettings;
p_intf->mainSettings = nullptr;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8c3003dfdc3a48f5269b4baf8e9ca104b44b024a...9c35ded8a18b8b2b1fc7221cc676c9c2e372561d
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8c3003dfdc3a48f5269b4baf8e9ca104b44b024a...9c35ded8a18b8b2b1fc7221cc676c9c2e372561d
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list