From 0fe36bccd381afcdfb3265d4d9a3a57bbfa73c08 Mon Sep 17 00:00:00 2001
From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it>
Date: Wed, 20 Mar 2024 18:22:39 +0100
Subject: [PATCH] correct valgrind omp errors

---
 src/cluster/cluster.cpp | 16 +++++++++-------
 src/libnptm/Commons.cpp |  2 +-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index 54bb4df4..8e86c417 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -386,22 +386,24 @@ void cluster(string config_file, string data_file, string output_path) {
 	dcomplex **tqsps_2 = new dcomplex*[2];
 	for (int ti = 0; ti < 2; ti++) {
 	  tqse_2[ti] = new double[nsph]();
-	  tqce_2[ti] = new double[nsph]();
-	  tqcs_2[ti] = new double[nsph]();
+	  tqce_2[ti] = new double[3]();
+	  tqcs_2[ti] = new double[3]();
 	  tqspe_2[ti] = new dcomplex[nsph]();
-	  tqcpe_2[ti] = new dcomplex[nsph]();
-	  tqcps_2[ti] = new dcomplex[nsph]();
+	  tqcpe_2[ti] = new dcomplex[3]();
+	  tqcps_2[ti] = new dcomplex[3]();
 	  tqss_2[ti] = new double[nsph]();
 	  tqsps_2[ti] = new dcomplex[nsph]();
 	  for (int tj=0; tj<nsph; tj++) {
 	    tqse_2[ti][tj] = tqse[ti][tj];
+	    tqspe_2[ti][tj] = tqspe[ti][tj];
+	    tqss_2[ti][tj] = tqss[ti][tj];
+	    tqsps_2[ti][tj] = tqsps[ti][tj];
+	  }
+	  for (int tj=0; tj<3; tj++) {
 	    tqce_2[ti][tj] = tqce[ti][tj];
 	    tqcs_2[ti][tj] = tqcs[ti][tj];
-	    tqspe_2[ti][tj] = tqspe[ti][tj];
 	    tqcpe_2[ti][tj] = tqcpe[ti][tj];
 	    tqcps_2[ti][tj] = tqcps[ti][tj];
-	    tqss_2[ti][tj] = tqss[ti][tj];
-	    tqsps_2[ti][tj] = tqsps[ti][tj];
 	  }
 	}
 	double ****zpv_2 = new double***[c4->lm]; //[gconf->l_max][3][2][2]; // Matrix: dim[LM x 3 x 2 x 2]
diff --git a/src/libnptm/Commons.cpp b/src/libnptm/Commons.cpp
index 10b22cb9..4fad87d2 100644
--- a/src/libnptm/Commons.cpp
+++ b/src/libnptm/Commons.cpp
@@ -328,7 +328,7 @@ C1_AddOns::~C1_AddOns() {
   for (int ai = nlemt - 1; ai > -1; ai--) {
     delete[] am0m[ai];
   }
-  delete am0m;
+  delete[] am0m;
   delete[] vint;
   delete[] vintm;
   delete[] vintt;
-- 
GitLab