From 7087dbf83ec989b1d325674ee5aa76216b21b551 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 10 Oct 2024 08:57:12 +0200 Subject: [PATCH] Fix leak in the Writer --- k4FWCore/components/Writer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/k4FWCore/components/Writer.cpp b/k4FWCore/components/Writer.cpp index 25c9874c..ba95fbe4 100644 --- a/k4FWCore/components/Writer.cpp +++ b/k4FWCore/components/Writer.cpp @@ -188,10 +188,13 @@ class Writer final : public Gaudi::Functional::ConsumerretrieveObject("/Event" + k4FWCore::frameLocation, p); AnyDataWrapper* ptr; + bool deletePtr = false; // This is the case when we are reading from a file + // Since we unregistered the object, we need to delete it if (code.isSuccess()) { m_dataSvc->unregisterObject(p).ignore(); ptr = dynamic_cast*>(p); + deletePtr = true; } // This is the case when no reading is being done // Will be deleted by the store @@ -263,6 +266,9 @@ class Writer final : public Gaudi::Functional::ConsumergetWriter().writeFrame(ptr->getData(), podio::Category::Event, m_collectionsToSave); + if (deletePtr && m_collectionsToAdd.empty()) { + delete ptr; + } } };