From 8a837a11d41322f194fcee3f63fab66f7e94991c Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Sun, 21 Jun 2026 01:45:07 +1200 Subject: [PATCH] Fix four memory leaks found by AddressSanitizer - StyleEditor: QGridLayout(this) pre-empted the widget's layout slot, causing setLayout(main_layout) to silently fail and orphan main_layout. Fix: use QGridLayout() without a parent so setLayout() succeeds. - ExportDialog: ~ExportDialog() was empty, leaving ExportDiagramLine heap objects in diagram_lines_ unfreed. Fix: qDeleteAll(diagram_lines_). - GenericPanel::getItemForDiagram: when called without the bool* created arg, it created a parentless QTreeWidgetItem that callers immediately discarded. Fix: return nullptr when created==nullptr and item not found (all callers already guard with if (item)). - ElementScene: m_paste_area (created in initPasteArea) was temporarily added/removed from the scene during XML loading but never freed in the destructor. Fix: delete it if not currently in the scene. Co-Authored-By: Claude Sonnet 4.6 --- sources/editor/elementscene.cpp | 3 +++ sources/editor/styleeditor.cpp | 2 +- sources/exportdialog.cpp | 1 + sources/genericpanel.cpp | 6 ++++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index bd2c9fdd4..baf0e7495 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -107,6 +107,9 @@ ElementScene::~ElementScene() if (m_decorator) delete m_decorator; + + if (m_paste_area && !m_paste_area->scene()) + delete m_paste_area; } /** diff --git a/sources/editor/styleeditor.cpp b/sources/editor/styleeditor.cpp index e441719bf..1818e8bf5 100644 --- a/sources/editor/styleeditor.cpp +++ b/sources/editor/styleeditor.cpp @@ -386,7 +386,7 @@ StyleEditor::StyleEditor(QETElementEditor *editor, CustomElementGraphicPart *p, outline_color->setSizeAdjustPolicy(QComboBox::AdjustToContents); filling_color->setSizeAdjustPolicy(QComboBox::AdjustToContents); - auto grid_layout = new QGridLayout(this); + auto grid_layout = new QGridLayout(); grid_layout->addWidget(new QLabel(tr("Contour :")), 0,0, Qt::AlignRight); grid_layout->addWidget(outline_color, 0, 1); grid_layout->addWidget(new QLabel(tr("Remplissage :")), 1, 0, Qt::AlignRight); diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 18fcfc98f..3298ad44c 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -112,6 +112,7 @@ ExportDialog::ExportDialog( */ ExportDialog::~ExportDialog() { + qDeleteAll(diagram_lines_); } /** diff --git a/sources/genericpanel.cpp b/sources/genericpanel.cpp index da40a343a..dbb856b75 100644 --- a/sources/genericpanel.cpp +++ b/sources/genericpanel.cpp @@ -321,9 +321,11 @@ QTreeWidgetItem *GenericPanel::getItemForDiagram(Diagram *diagram, if (created) *created = false; return(diagram_qtwi); } - + + if (!created) return(nullptr); + diagram_qtwi = makeItem(QET::Diagram); - if (created) *created = true; + *created = true; return(diagram_qtwi); }