Skip to content

Commit

Permalink
Fix leaking LCEvent every loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored and andresailer committed Nov 24, 2022
1 parent 8c21c30 commit 6f98cf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
19 changes: 7 additions & 12 deletions k4MarlinWrapper/k4MarlinWrapper/LCEventWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,18 @@

#include <GaudiKernel/DataObject.h>

#include <memory>

class LCEventWrapper : public DataObject {
public:
// Set delete_event to true when manually creating the LCEvent
LCEventWrapper(EVENT::LCEvent* theEvent, bool delete_event = false)
: m_event(theEvent), m_delete_event(delete_event) {}
LCEventWrapper(std::unique_ptr<EVENT::LCEvent>&& theEvent) : m_event(std::move(theEvent)) {}

~LCEventWrapper() {
if (m_delete_event) {
delete m_event;
}
};
~LCEventWrapper() = default;

EVENT::LCEvent* getEvent() const { return m_event; }
EVENT::LCEvent* getEvent() const { return m_event.get(); }

private:
EVENT::LCEvent* m_event = nullptr;
bool m_delete_event = false;
std::unique_ptr<EVENT::LCEvent> m_event{nullptr};
};

// Event Status Data Object to indicate if there was underlying LCEvent
Expand All @@ -55,4 +50,4 @@ class LCEventWrapperStatus : public DataObject {
bool hasLCEvent = false;
};

#endif
#endif
2 changes: 1 addition & 1 deletion k4MarlinWrapper/src/components/LcioEventAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ StatusCode LcioEvent::execute() {
// wrappers
info() << "Reading from file: " << m_fileNames[0] << endmsg;

auto myEvWr = new LCEventWrapper(theEvent.release());
auto myEvWr = new LCEventWrapper(std::move(theEvent));
const StatusCode sc = eventSvc()->registerObject("/Event/LCEvent", myEvWr);
if (sc.isFailure()) {
error() << "Failed to store the LCEvent" << endmsg;
Expand Down
5 changes: 3 additions & 2 deletions k4MarlinWrapper/src/components/MarlinProcessorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include "k4MarlinWrapper/MarlinProcessorWrapper.h"
#include "IMPL/LCEventImpl.h"

DECLARE_COMPONENT(MarlinProcessorWrapper)

Expand Down Expand Up @@ -209,9 +210,9 @@ StatusCode MarlinProcessorWrapper::execute() {

if (sc.isFailure()) {
// Register empty event
the_event = new lcio::LCEventImpl();
debug() << "Registering empty Event for EDM4hep to LCIO conversion event in TES" << endmsg;
auto pO = std::make_unique<LCEventWrapper>(the_event, true);
auto pO = std::make_unique<LCEventWrapper>(std::make_unique<lcio::LCEventImpl>());
the_event = static_cast<IMPL::LCEventImpl*>(pO->getEvent());
StatusCode reg_sc = evtSvc()->registerObject("/Event/LCEvent", pO.release());
if (reg_sc.isFailure()) {
error() << "Failed to register empty LCIO Event" << endmsg;
Expand Down

0 comments on commit 6f98cf9

Please sign in to comment.