From 73ed29b64be2a832afdabc525b6cc61d63833451 Mon Sep 17 00:00:00 2001 From: Inoki Date: Mon, 2 May 2022 13:08:22 +0200 Subject: [PATCH] Use `deleteLater` to safely del QObject instances --- mainwindow.cpp | 2 +- qefientrydetailview.cpp | 7 +++---- qefientrydpdetailview.cpp | 3 +-- qefientryview.cpp | 26 ++++++++++++-------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 376d615..b8d9a2a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,6 +15,6 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { - if (m_entryView != nullptr) delete m_entryView; + if (m_entryView != nullptr) m_entryView->deleteLater(); } diff --git a/qefientrydetailview.cpp b/qefientrydetailview.cpp index 875095e..325bf3b 100644 --- a/qefientrydetailview.cpp +++ b/qefientrydetailview.cpp @@ -43,7 +43,7 @@ QEFIEntryDetailBriefView::QEFIEntryDetailBriefView( QEFIEntryDetailBriefView::~QEFIEntryDetailBriefView() { - if (m_briefLayout != nullptr) delete m_briefLayout; + if (m_briefLayout != nullptr) m_briefLayout->deleteLater(); m_briefLayout = nullptr; } @@ -71,10 +71,9 @@ QEFIEntryDetailView::QEFIEntryDetailView(QEFIEntry &entry, QWidget *parent) QEFIEntryDetailView::~QEFIEntryDetailView() { - if (m_topLevelLayout != nullptr) delete m_topLevelLayout; + if (m_topLevelLayout != nullptr) m_topLevelLayout->deleteLater(); m_topLevelLayout = nullptr; - // Has ownership been passed to layout? - if (m_tab != nullptr) delete m_tab; + if (m_tab != nullptr) m_tab->deleteLater(); m_tab = nullptr; } diff --git a/qefientrydpdetailview.cpp b/qefientrydpdetailview.cpp index af9c373..3a7cf52 100644 --- a/qefientrydpdetailview.cpp +++ b/qefientrydpdetailview.cpp @@ -25,9 +25,8 @@ QEFIEntryDPDetailView::QEFIEntryDPDetailView(QEFIDevicePath *dp, QWidget *parent QEFIEntryDPDetailView::~QEFIEntryDPDetailView() { - // TODO: Use smart ptr if (m_topLevelLayout != nullptr) { - delete m_topLevelLayout; + m_topLevelLayout->deleteLater(); m_topLevelLayout = nullptr; } } diff --git a/qefientryview.cpp b/qefientryview.cpp index a05dbbb..d4dbe8b 100644 --- a/qefientryview.cpp +++ b/qefientryview.cpp @@ -89,26 +89,24 @@ QEFIEntryView::QEFIEntryView(QWidget *parent) QEFIEntryView::~QEFIEntryView() { - // TODO: Use smart ptr if (m_topLevelLayout != nullptr) { - delete m_topLevelLayout; + m_topLevelLayout->deleteLater(); m_topLevelLayout = nullptr; } - if (m_entries != nullptr) delete m_entries; + if (m_entries != nullptr) m_entries->deleteLater(); m_entries = nullptr; // Seems that we have no ownership on it -// if (m_buttonLayout != nullptr) delete m_buttonLayout; -// m_buttonLayout = nullptr; - - if (m_moveUpEntryButton != nullptr) delete m_moveUpEntryButton; - if (m_moveDownEntryButton != nullptr) delete m_moveDownEntryButton; - if (m_setCurrentButton != nullptr) delete m_setCurrentButton; - if (m_saveButton != nullptr) delete m_saveButton; - if (m_resetButton != nullptr) delete m_resetButton; - if (m_rebootTargetButton != nullptr) delete m_rebootTargetButton; - if (m_bootTimeoutLabel != nullptr) delete m_bootTimeoutLabel; + if (m_buttonLayout != nullptr) m_buttonLayout->deleteLater(); + + if (m_moveUpEntryButton != nullptr) m_moveUpEntryButton->deleteLater(); + if (m_moveDownEntryButton != nullptr) m_moveDownEntryButton->deleteLater(); + if (m_setCurrentButton != nullptr) m_setCurrentButton->deleteLater(); + if (m_saveButton != nullptr) m_saveButton->deleteLater(); + if (m_resetButton != nullptr) m_resetButton->deleteLater(); + if (m_rebootTargetButton != nullptr) m_rebootTargetButton->deleteLater(); + if (m_bootTimeoutLabel != nullptr) m_bootTimeoutLabel->deleteLater(); } void QEFIEntryView::entryChanged(int currentRow) @@ -286,7 +284,7 @@ class DetailDialog : public QDialog ~DetailDialog() { - if (m_topLevelLayout) delete m_topLevelLayout; + if (m_topLevelLayout) m_topLevelLayout->deleteLater(); } };