From 4225e67834c1df8736c1fc1e258fb2dcc8573bc0 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 20 Nov 2019 11:41:14 +0100 Subject: [PATCH] Janitor : Make sure memory is released by using unique_ptr --- .../SummaryPlotCommands/RicEditSummaryPlotFeature.cpp | 9 +++++++-- .../SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp | 9 ++++++--- .../SummaryPlotCommands/RicSummaryCurveCreatorDialog.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp index ae7d3f30ab..2eb44d8edd 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp @@ -60,9 +60,14 @@ void RicEditSummaryPlotFeature::closeDialogAndResetTargetPlot() //-------------------------------------------------------------------------------------------------- RicSummaryCurveCreatorDialog* RicEditSummaryPlotFeature::curveCreatorDialog() { - static RicSummaryCurveCreatorDialog* singletonDialog = new RicSummaryCurveCreatorDialog( nullptr ); + static std::unique_ptr singletonDialog; - return singletonDialog; + if ( !singletonDialog ) + { + singletonDialog.reset( new RicSummaryCurveCreatorDialog( nullptr ) ); + } + + return singletonDialog.get(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp index 0f4b59a0ba..f7d8ca667a 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.cpp @@ -36,7 +36,7 @@ RicSummaryCurveCreatorDialog::RicSummaryCurveCreatorDialog( QWidget* parent ) : QDialog( parent, RiuTools::defaultDialogFlags() ) { - m_curveCreatorSplitterUi = new RicSummaryCurveCreatorSplitterUi( this ); + m_curveCreatorSplitterUi.reset( new RicSummaryCurveCreatorSplitterUi( this ) ); QWidget* propertyWidget = m_curveCreatorSplitterUi->getOrCreateWidget( this ); @@ -46,7 +46,7 @@ RicSummaryCurveCreatorDialog::RicSummaryCurveCreatorDialog( QWidget* parent ) setWindowTitle( "Plot Editor" ); resize( 1200, 800 ); - connect( m_curveCreatorSplitterUi, SIGNAL( signalCloseButtonPressed() ), this, SLOT( accept() ) ); + connect( m_curveCreatorSplitterUi.get(), SIGNAL( signalCloseButtonPressed() ), this, SLOT( accept() ) ); connect( this, SIGNAL( finished( int ) ), this, SLOT( slotDialogFinished() ) ); } @@ -54,7 +54,10 @@ RicSummaryCurveCreatorDialog::RicSummaryCurveCreatorDialog( QWidget* parent ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RicSummaryCurveCreatorDialog::~RicSummaryCurveCreatorDialog() {} +RicSummaryCurveCreatorDialog::~RicSummaryCurveCreatorDialog() +{ + m_curveCreatorSplitterUi->setPdmObject( nullptr ); +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h index 1c154052f4..88d6fee07c 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreatorDialog.h @@ -47,5 +47,5 @@ private slots: void slotDialogFinished(); private: - RicSummaryCurveCreatorSplitterUi* m_curveCreatorSplitterUi; + std::unique_ptr m_curveCreatorSplitterUi; };