From 69cf6832bd87e713b9fa27ce3657dbf0437afda7 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 9 Dec 2024 20:03:28 +0800 Subject: [PATCH] fix: Fix memory leaks in Displayer and RecognitionMenu Fix two memory management issues: - Add missing deletion of m_imageItem in Displayer::setSources - Set proper parent for PSM menu to ensure proper cleanup These changes prevent memory leaks and ensure proper resource cleanup when the application exits or when components are destroyed. --- qt/src/Displayer.cc | 1 + qt/src/RecognitionMenu.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/qt/src/Displayer.cc b/qt/src/Displayer.cc index d2b4366e..ea6046cf 100644 --- a/qt/src/Displayer.cc +++ b/qt/src/Displayer.cc @@ -126,6 +126,7 @@ bool Displayer::setSources(QList sources) { m_renderTimer.stop(); if(m_imageItem) { m_scene->removeItem(m_imageItem); + delete m_imageItem; } m_currentSource = nullptr; qDeleteAll(m_sourceRenderers); diff --git a/qt/src/RecognitionMenu.cc b/qt/src/RecognitionMenu.cc index 1eb9677f..671690c8 100644 --- a/qt/src/RecognitionMenu.cc +++ b/qt/src/RecognitionMenu.cc @@ -170,7 +170,7 @@ void RecognitionMenu::rebuild() { // Add PSM items addSeparator(); - QMenu* psmMenu = new QMenu(); + QMenu* psmMenu = new QMenu(this); int activePsm = ConfigSettings::get>("psm")->getValue(); struct PsmEntry {