From ff05fef19368df3ad090bb72a174e3d6897ed614 Mon Sep 17 00:00:00 2001 From: Qiyu Yan Date: Tue, 17 Sep 2024 21:44:16 +0800 Subject: [PATCH] Workaround a memory leak with old ROOT IO --- src/Framework/Ntuple/LinkDef.h | 2 +- src/Framework/Ntuple/NtpMCEventRecord.cxx | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Framework/Ntuple/LinkDef.h b/src/Framework/Ntuple/LinkDef.h index 7c2dd9268c..0e10c24e83 100644 --- a/src/Framework/Ntuple/LinkDef.h +++ b/src/Framework/Ntuple/LinkDef.h @@ -12,7 +12,7 @@ #pragma link C++ class genie::NtpMCJobConfig; #pragma link C++ class genie::NtpMCRecHeader; #pragma link C++ class genie::NtpMCRecordI; -#pragma link C++ class genie::NtpMCEventRecord; +#pragma link C++ class genie::NtpMCEventRecord-; #pragma link C++ class genie::NtpWriter; #endif diff --git a/src/Framework/Ntuple/NtpMCEventRecord.cxx b/src/Framework/Ntuple/NtpMCEventRecord.cxx index edf8fe9918..e8bfdcdb40 100644 --- a/src/Framework/Ntuple/NtpMCEventRecord.cxx +++ b/src/Framework/Ntuple/NtpMCEventRecord.cxx @@ -10,6 +10,7 @@ #include "Framework/EventGen/EventRecord.h" #include "Framework/Messenger/Messenger.h" +#include "TBuffer.h" #include "Framework/Ntuple/NtpMCEventRecord.h" using std::endl; @@ -75,3 +76,29 @@ void NtpMCEventRecord::Clear(Option_t * /*opt*/) this->hdr.ievent = 0; } //____________________________________________________________________________ + +// Extracted from the code ROOT generated +// added check-and-delete before streaming to +// avoid memory leak +void NtpMCEventRecord::Streamer(TBuffer &R__b) { + // Stream an object of class genie::NtpMCEventRecord. + + UInt_t R__s, R__c; + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(&R__s, &R__c); + if (R__v) { + } + genie::NtpMCRecordI::Streamer(R__b); + if (event) { + delete event; + event = nullptr; + } + R__b >> event; + R__b.CheckByteCount(R__s, R__c, ::genie::NtpMCEventRecord::IsA()); + } else { + R__c = R__b.WriteVersion(::genie::NtpMCEventRecord::IsA(), kTRUE); + genie::NtpMCRecordI::Streamer(R__b); + R__b << event; + R__b.SetByteCount(R__c, kTRUE); + } +} \ No newline at end of file