From 17cafab7b8fa27289677cf767ef8d01cbc6cb730 Mon Sep 17 00:00:00 2001 From: Adam Higerd Date: Wed, 12 Feb 2025 18:02:34 -0600 Subject: [PATCH] Qt: Fix use-after-free in shader settings --- src/platform/qt/SettingsView.cpp | 4 ++-- src/platform/qt/SettingsView.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 195fe0441..967cf1a4d 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -437,9 +437,9 @@ void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) { QObject::disconnect(m_shader, nullptr, this, nullptr); } m_shader = shaderSelector; - QObject::connect(this, &SettingsView::saveSettingsRequested, m_shader, &ShaderSelector::saveSettings); - QObject::connect(m_ui.buttonBox, &QDialogButtonBox::rejected, m_shader, &ShaderSelector::revert); if (shaderSelector) { + QObject::connect(this, &SettingsView::saveSettingsRequested, m_shader, &ShaderSelector::saveSettings); + QObject::connect(m_ui.buttonBox, &QDialogButtonBox::rejected, m_shader, &ShaderSelector::revert); addPage(tr("Shaders"), m_shader, Page::SHADERS); } else { addPage(tr("Shaders"), m_dummyShader, Page::SHADERS); diff --git a/src/platform/qt/SettingsView.h b/src/platform/qt/SettingsView.h index 1e45ec87a..710456958 100644 --- a/src/platform/qt/SettingsView.h +++ b/src/platform/qt/SettingsView.h @@ -7,10 +7,12 @@ #include #include +#include #include #include "ColorPicker.h" #include "LogConfigModel.h" +#include "ShaderSelector.h" #include @@ -25,7 +27,6 @@ namespace QGBA { class ConfigController; class InputController; class ShortcutController; -class ShaderSelector; class SettingsView : public QDialog { Q_OBJECT @@ -80,7 +81,7 @@ private: ConfigController* m_controller; InputController* m_input; - ShaderSelector* m_shader = nullptr; + QPointer m_shader; QLabel* m_dummyShader; LogConfigModel m_logModel; QTimer m_checkTimer;