From 1932cd7dd01f95348ffdf87a63bf2db7a7c3a662 Mon Sep 17 00:00:00 2001
From: Tadej Novak <tadej.novak@cern.ch>
Date: Thu, 23 Sep 2021 15:15:07 +0200
Subject: [PATCH] Fix a leak in FEI4SimTool

---
 .../PixelDigitization/src/FEI3SimTool.cxx         |  8 ++------
 .../PixelDigitization/src/FEI4SimTool.cxx         | 15 +++++++--------
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/InnerDetector/InDetDigitization/PixelDigitization/src/FEI3SimTool.cxx b/InnerDetector/InDetDigitization/PixelDigitization/src/FEI3SimTool.cxx
index 6a262f6a4489..2f243f410ee0 100644
--- a/InnerDetector/InDetDigitization/PixelDigitization/src/FEI3SimTool.cxx
+++ b/InnerDetector/InDetDigitization/PixelDigitization/src/FEI3SimTool.cxx
@@ -178,9 +178,7 @@ void FEI3SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
 
     // Front-End simulation
     if (bunch >= 0 && bunch < moduleData->getNumberOfBCID(barrel_ec, layerIndex)) {
-      Pixel1RawData* p_rdo = new Pixel1RawData(id_readout, nToT, bunch, 0, bunch);
-      rdoCollection.push_back(p_rdo);
-      p_rdo = nullptr;
+      rdoCollection.push_back(new Pixel1RawData(id_readout, nToT, bunch, 0, bunch));
     }
 
     // Duplication mechanism for FEI3 small hits :
@@ -191,9 +189,7 @@ void FEI3SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
       }
 
       if (smallHitChk && bunch > 0 && bunch <= moduleData->getNumberOfBCID(barrel_ec, layerIndex)) {
-        Pixel1RawData* p_rdo = new Pixel1RawData(id_readout, nToT, bunch - 1, 0, bunch - 1);
-        rdoCollection.push_back(p_rdo);
-        p_rdo = nullptr;
+        rdoCollection.push_back(new Pixel1RawData(id_readout, nToT, bunch - 1, 0, bunch - 1));
       }
     }
   }
diff --git a/InnerDetector/InDetDigitization/PixelDigitization/src/FEI4SimTool.cxx b/InnerDetector/InDetDigitization/PixelDigitization/src/FEI4SimTool.cxx
index 1cc63919f226..616f5803e324 100644
--- a/InnerDetector/InDetDigitization/PixelDigitization/src/FEI4SimTool.cxx
+++ b/InnerDetector/InDetDigitization/PixelDigitization/src/FEI4SimTool.cxx
@@ -48,7 +48,7 @@ void FEI4SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
   int maxFEI4SmallHit = 2;
   int overflowToT = moduleData->getFEI4OverflowToT(barrel_ec, layerIndex);
 
-  std::vector<Pixel1RawData*> p_rdo_small_fei4;
+  std::vector<std::unique_ptr<Pixel1RawData>> p_rdo_small_fei4;
   int nSmallHitsFEI4 = 0;
   std::vector<int> row, col;
   const int maxRow = p_design->rowsPerCircuit();
@@ -169,18 +169,17 @@ void FEI4SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
 
     // Front-End simulation
     if (bunch >= 0 && bunch < moduleData->getNumberOfBCID(barrel_ec, layerIndex)) {
-      Pixel1RawData* p_rdo = new Pixel1RawData(id_readout, nToT, bunch, 0, bunch);
+      auto p_rdo = std::make_unique<Pixel1RawData>(id_readout, nToT, bunch, 0, bunch);
       if (nToT > maxFEI4SmallHit) {
-        rdoCollection.push_back(p_rdo);
+        rdoCollection.push_back(p_rdo.release());
         FEI4Map[iirow][iicol] = 2; //Flag for "big hits"
       } else {
-        p_rdo_small_fei4.push_back(p_rdo);
+        p_rdo_small_fei4.push_back(std::move(p_rdo));
         row.push_back(iirow);
         col.push_back(iicol);
         FEI4Map[iirow][iicol] = 1; //Flag for low hits
         nSmallHitsFEI4++;
       }
-      p_rdo = nullptr;
     }
   }
 
@@ -198,7 +197,7 @@ void FEI4SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
             "rowBig = " << rowBigHit << " colBig = " << colBigHit << " Map Content = " <<
               FEI4Map[rowBigHit][colBigHit]);
           if (FEI4Map[rowBigHit][colBigHit] == 2 && !recorded) {
-            rdoCollection.push_back(p_rdo_small_fei4[ismall]);
+            rdoCollection.push_back(p_rdo_small_fei4[ismall].release());
             recorded = true;
           }
         }
@@ -207,13 +206,13 @@ void FEI4SimTool::process(SiChargedDiodeCollection& chargedDiodes, PixelRDO_Coll
       // Second case: Record small hits which are phi-neighbours with a big hit:
       if (!recorded && row[ismall] < maxRow - 1) {
         if (FEI4Map[row[ismall] + 1][col[ismall]] == 2) {
-          rdoCollection.push_back(p_rdo_small_fei4[ismall]);
+          rdoCollection.push_back(p_rdo_small_fei4[ismall].release());
           recorded = true;
         }
       }
       if (!recorded && row[ismall] != 0) {
         if (FEI4Map[row[ismall] - 1][col[ismall]] == 2) {
-          rdoCollection.push_back(p_rdo_small_fei4[ismall]);
+          rdoCollection.push_back(p_rdo_small_fei4[ismall].release());
           recorded = true;
         }
       }
-- 
GitLab