Skip to content

Commit

Permalink
Fix leak in the Writer
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Oct 10, 2024
1 parent 117bbce commit 7087dbf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
DataObject* p;
StatusCode code = m_dataSvc->retrieveObject("/Event" + k4FWCore::frameLocation, p);
AnyDataWrapper<podio::Frame>* 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<AnyDataWrapper<podio::Frame>*>(p);
deletePtr = true;
}
// This is the case when no reading is being done
// Will be deleted by the store
Expand Down Expand Up @@ -263,6 +266,9 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&

debug() << "Writing frame" << endmsg;
iosvc->getWriter().writeFrame(ptr->getData(), podio::Category::Event, m_collectionsToSave);
if (deletePtr && m_collectionsToAdd.empty()) {
delete ptr;
}
}
};

Expand Down

0 comments on commit 7087dbf

Please sign in to comment.