From 0f95edc5e60164767037f4dc8e4118950572da92 Mon Sep 17 00:00:00 2001 From: joshua Date: Thu, 31 Mar 2022 19:05:45 +0200 Subject: [PATCH] Fix crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See bug N°244 https://qelectrotech.org/bugtracker/view.php?id=244 --- sources/qetproject.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 1b9eb7fc4..0f74a874b 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -120,8 +120,19 @@ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) : */ QETProject::~QETProject() { - for (auto diagram : m_diagrams_list) + //Each time a diagram is deleted we also remove it from m_diagram_list + //because a lot of thing append during the destructor of a diagram class + //and one of these thing (not directly in the destructor of the diagram + //but in another destructor called by the diagram destructor) + //is to get the diagram list of the project to make some updates @see QList QETProject::diagrams() const. + //So we need to remove the freshly deleted diagram from the list + //in each iteration of the loop to avoid the use of a dangling pointer. + const auto diag_list = m_diagrams_list; + for (const auto &diagram : diag_list) + { delete diagram; + m_diagrams_list.removeOne(diagram); + } } /**