From dedd9cfcdb74b9af67346fad81217829f3c2c3ce Mon Sep 17 00:00:00 2001 From: ctraizet <cedric.traizet@c-s.fr> Date: Fri, 8 Mar 2019 09:44:48 +0100 Subject: [PATCH] BUG: delete all watchers in the destructor of ProgressReporterManager --- Modules/Wrappers/SWIG/src/otbPythonLogOutput.i | 1 + .../src/python/otbProgressReporterManager.cxx | 15 +++++++++++++++ .../SWIG/src/python/otbProgressReporterManager.h | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Modules/Wrappers/SWIG/src/otbPythonLogOutput.i b/Modules/Wrappers/SWIG/src/otbPythonLogOutput.i index 34b0f99214..2dac6aa7c8 100644 --- a/Modules/Wrappers/SWIG/src/otbPythonLogOutput.i +++ b/Modules/Wrappers/SWIG/src/otbPythonLogOutput.i @@ -85,6 +85,7 @@ public: static ProgressReporterManager_Pointer New(); virtual void Delete(); + void DeleteWatcherList(); void SetLogOutputCallback(otb::LogOutputCallback* callback); itkCommand* GetAddProcessCommand(); diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx index 89ea154a43..0e231beefd 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx @@ -31,6 +31,21 @@ ProgressReporterManager::ProgressReporterManager() m_AddProcessCommand->SetCallbackFunction(this, &ProgressReporterManager::LinkWatchers); } +ProgressReporterManager::~ProgressReporterManager() +{ + this->DeleteWatcherList(); +} + +void ProgressReporterManager::DeleteWatcherList() +{ + //Delete all stored progress reporter + for (auto watcher: m_WatcherList) + { + delete watcher; + } + m_WatcherList.clear(); +} + void ProgressReporterManager::LinkWatchers(itk::Object* itkNotUsed(caller), const itk::EventObject& event) { if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid(event)) diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h index e1aaf0d1f8..4900aed18b 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h @@ -70,12 +70,15 @@ public: return m_AddProcessCommand.GetPointer(); } + /** Delete all watchers */ + void DeleteWatcherList(); + protected: /** Default constructor */ ProgressReporterManager(); /** Destructor. */ - virtual ~ProgressReporterManager() = default; + virtual ~ProgressReporterManager(); /** Load the watchers for internal progress and writing progress report. */ void LinkWatchers(itk::Object* caller, const itk::EventObject& event); -- GitLab