From 77846eb667bcdd327e6e4200d0d3a2247bf5b31b Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Thu, 26 Sep 2024 15:17:54 +0200
Subject: [PATCH] Correct valgrind memory leaks

---
 src/libnptm/Configuration.cpp | 7 ++++---
 src/trapping/clffft.cpp       | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/libnptm/Configuration.cpp b/src/libnptm/Configuration.cpp
index 6f36e84f..286e33f7 100644
--- a/src/libnptm/Configuration.cpp
+++ b/src/libnptm/Configuration.cpp
@@ -12,7 +12,7 @@
    
    A copy of the GNU General Public License is distributed along with
    this program in the COPYING file. If not, see: <https://www.gnu.org/licenses/>.
- */
+*/
 
 /*! \file Configuration.cpp
  *
@@ -856,6 +856,7 @@ ScattererConfiguration* ScattererConfiguration::from_hdf5(const std::string& fil
     } // di loop
     delete[] elements;
     status = hdf_file->close();
+    delete hdf_file;
     conf = new ScattererConfiguration(
 				      nsph,
 				      configuration_count,
@@ -872,9 +873,9 @@ ScattererConfiguration* ScattererConfiguration::from_hdf5(const std::string& fil
 				      _exdc,
 				      _wp,
 				      _xip
-				      );
+    );
+    delete[] xi_vec;
   }
-  
   return conf;
 }
 
diff --git a/src/trapping/clffft.cpp b/src/trapping/clffft.cpp
index b3638375..46828b2d 100644
--- a/src/trapping/clffft.cpp
+++ b/src/trapping/clffft.cpp
@@ -326,15 +326,18 @@ void lffft(string data_file, string output_path) {
 		if (is != 2222) {
 		  if (is != 1111) {
 		    if (is > 0) { // Goes to 305
+		      if (ac) delete[] ac;
 		      ac = new dcomplex[cil->nlemt]();
 		      camp(ac, am0m, ws, cil);
 		      // Goes to 445
 		    } else if (is < 0) { // Goes to 405
+		      if (ac) delete[] ac;
 		      ac = new dcomplex[cil->nlemt]();
 		      czamp(ac, amd, indam, ws, cil);
 		      // Goes to 445
 		    }
 		  } else {
+		    if (ac) delete[] ac;
 		    ac = new dcomplex[cil->nlemt]();
 		    samp(ac, tmsm, tmse, ws, cil);
 		    // Goes to 445
-- 
GitLab