From c890d59151db124bd244600974c1d7cd9fce006a Mon Sep 17 00:00:00 2001 From: James Shen Date: Sun, 19 May 2024 16:55:28 -0400 Subject: [PATCH] fix memory leak in PMTWaveforms --- src/daq/include/RAT/PMTWaveform.hh | 2 +- src/daq/src/PMTWaveform.cc | 4 ++-- src/daq/src/PMTWaveformGenerator.cc | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/daq/include/RAT/PMTWaveform.hh b/src/daq/include/RAT/PMTWaveform.hh index b3a3f775..743d47a4 100644 --- a/src/daq/include/RAT/PMTWaveform.hh +++ b/src/daq/include/RAT/PMTWaveform.hh @@ -17,7 +17,7 @@ class PMTWaveform { virtual ~PMTWaveform(); virtual double GetHeight(double time); - std::vector fPulse; + std::vector fPulse; }; } // namespace RAT diff --git a/src/daq/src/PMTWaveform.cc b/src/daq/src/PMTWaveform.cc index 9876e6b5..14266243 100644 --- a/src/daq/src/PMTWaveform.cc +++ b/src/daq/src/PMTWaveform.cc @@ -9,8 +9,8 @@ PMTWaveform::~PMTWaveform() {} double PMTWaveform::GetHeight(double currenttime) { double height = 0.; - for (unsigned int i = 0; i < fPulse.size() && fPulse[i]->GetPulseStartTime() <= currenttime; i++) { - height += fPulse[i]->GetPulseHeight(currenttime); + for (unsigned int i = 0; i < fPulse.size() && fPulse[i].GetPulseStartTime() <= currenttime; i++) { + height += fPulse[i].GetPulseHeight(currenttime); } return height; } diff --git a/src/daq/src/PMTWaveformGenerator.cc b/src/daq/src/PMTWaveformGenerator.cc index 0cb8c1c0..a5dcd5f4 100644 --- a/src/daq/src/PMTWaveformGenerator.cc +++ b/src/daq/src/PMTWaveformGenerator.cc @@ -68,7 +68,8 @@ PMTWaveform PMTWaveformGenerator::GenerateWaveforms(DS::MCPMT *mcpmt, double tri for (int iph = 0; iph < mcpmt->GetMCPhotonCount(); iph++) { DS::MCPhoton *mcpe = mcpmt->GetMCPhoton(iph); - PMTPulse *pmtpulse = new PMTPulse(fPMTPulseType, fPMTPulseShape); + pmtwf.fPulse.push_back(PMTPulse(fPMTPulseType, fPMTPulseShape)); + PMTPulse *pmtpulse = &pmtwf.fPulse.back(); pmtpulse->SetPulseCharge(mcpe->GetCharge() * fTerminationOhms); pmtpulse->SetPulseMin(fPMTPulseMin); pmtpulse->SetPulseOffset(fPMTPulseOffset); @@ -81,8 +82,6 @@ PMTWaveform PMTWaveformGenerator::GenerateWaveforms(DS::MCPMT *mcpmt, double tri pmtpulse->SetPulseTimes(fPMTPulseShapeTimes); pmtpulse->SetPulseValues(fPMTPulseShapeValues); - - pmtwf.fPulse.push_back(pmtpulse); } return pmtwf;