From 0125803d4b39b824fa23fda902ad44d2bbd9d837 Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Thu, 17 Dec 2020 03:22:42 +0100
Subject: [PATCH] JetRec: Fix memory leak.

PseudoJetContainer needs to delete the objects in m_emptyExtractors.
---
 .../Jet/JetRec/JetRec/PseudoJetContainer.h           |  4 +++-
 .../Jet/JetRec/Root/PseudoJetContainer.cxx           | 12 ++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Reconstruction/Jet/JetRec/JetRec/PseudoJetContainer.h b/Reconstruction/Jet/JetRec/JetRec/PseudoJetContainer.h
index 94eacde5975..b4b47d1ef4f 100644
--- a/Reconstruction/Jet/JetRec/JetRec/PseudoJetContainer.h
+++ b/Reconstruction/Jet/JetRec/JetRec/PseudoJetContainer.h
@@ -6,7 +6,7 @@
 #define PseudoJetContainer_H
 
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 
@@ -55,6 +55,8 @@ public:
                      const std::vector<PseudoJet> & vecPJ,
                      bool debug=false);
 
+  ~PseudoJetContainer();
+
   // fill xAOD jet with constit&ghosts extracted from final PSeudoJet
   bool extractConstituents(xAOD::Jet&, const std::vector<PseudoJet>&) const;
   bool extractConstituents(xAOD::Jet& jet, const PseudoJet &finalPJ) const;
diff --git a/Reconstruction/Jet/JetRec/Root/PseudoJetContainer.cxx b/Reconstruction/Jet/JetRec/Root/PseudoJetContainer.cxx
index 449796aacf5..104ede8af88 100644
--- a/Reconstruction/Jet/JetRec/Root/PseudoJetContainer.cxx
+++ b/Reconstruction/Jet/JetRec/Root/PseudoJetContainer.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 // PseudoJetContainer.cxx
@@ -44,6 +44,14 @@ PseudoJetContainer::PseudoJetContainer(const IConstituentExtractor* c,
 }
 
 
+PseudoJetContainer::~PseudoJetContainer()
+{
+  for (const IConstituentExtractor* e : m_emptyExtractors) {
+    delete e;
+  }
+}
+
+
 bool
 PseudoJetContainer::extractConstituents(xAOD::Jet& jet, 
                                         const std::vector<PseudoJet>& inConstits) const
@@ -137,7 +145,7 @@ void PseudoJetContainer::append(const PseudoJetContainer* other) {
                    pj.set_user_index(pj.user_index() + offset);return pj;}
                  );
 
-  for(auto e : other->m_emptyExtractors){m_emptyExtractors.insert(e);}
+  for(auto e : other->m_emptyExtractors){m_emptyExtractors.insert(e->clone());}
 
   if (m_debug){checkInvariants("append()");}
 }
-- 
GitLab