From c4e72e0f01842f617c2f18ecbd54f07e0b13e929 Mon Sep 17 00:00:00 2001 From: kochebina Date: Tue, 13 Jun 2023 14:46:42 +0200 Subject: [PATCH 1/2] Some mem leaks corrections --- source/digits_hits/src/GateSpatialResolution.cc | 8 +++++--- source/digits_hits/src/GateToASCII.cc | 9 +++++++-- source/digits_hits/src/GateToASCIIMessenger.cc | 2 ++ source/digits_hits/src/GateToBinary.cc | 4 ++++ source/digits_hits/src/GateToBinaryMessenger.cc | 2 ++ source/digits_hits/src/GateToRootMessenger.cc | 3 +++ source/digits_hits/src/GateToTreeMessenger.cc | 9 +++++++++ 7 files changed, 32 insertions(+), 5 deletions(-) diff --git a/source/digits_hits/src/GateSpatialResolution.cc b/source/digits_hits/src/GateSpatialResolution.cc index 936cc2be5..a6f81a789 100755 --- a/source/digits_hits/src/GateSpatialResolution.cc +++ b/source/digits_hits/src/GateSpatialResolution.cc @@ -50,7 +50,6 @@ GateSpatialResolution::GateSpatialResolution(GateSinglesDigitizer *digitizer, G4 m_fwhmY(0), m_fwhmZ(0), m_IsConfined(true), - m_Navigator(0), m_Touchable(0), m_systemDepth(-1), m_outputDigi(0), @@ -60,13 +59,15 @@ GateSpatialResolution::GateSpatialResolution(GateSinglesDigitizer *digitizer, G4 G4String colName = digitizer->GetOutputName() ; collectionName.push_back(colName); m_Messenger = new GateSpatialResolutionMessenger(this); + m_Navigator = new G4Navigator(); + } GateSpatialResolution::~GateSpatialResolution() { delete m_Messenger; - + delete m_Navigator; } @@ -188,7 +189,6 @@ void GateSpatialResolution::Digitize() // Do not use from TransportationManager as it is not recommended G4Navigator *navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking(); G4VPhysicalVolume *WorldVolume = navigator->GetWorldVolume(); - m_Navigator = new G4Navigator(); m_Navigator->SetWorldVolume(WorldVolume); G4VPhysicalVolume* PV = m_Navigator->LocateGlobalPointAndSetup(m_outputDigi->GetGlobalPos()); @@ -199,6 +199,8 @@ void GateSpatialResolution::Digitize() { UpdateVolumeID(); } + + m_OutputDigiCollection->insert(m_outputDigi); diff --git a/source/digits_hits/src/GateToASCII.cc b/source/digits_hits/src/GateToASCII.cc index aa77886ca..a5a5f97f4 100644 --- a/source/digits_hits/src/GateToASCII.cc +++ b/source/digits_hits/src/GateToASCII.cc @@ -73,8 +73,8 @@ GateToASCII::GateToASCII(const G4String& name, GateOutputMgr* outputMgr, DigiMod GateToASCII::~GateToASCII() { - // for (size_t i=0; iCreateNewOutputChannelCommand(singleOutputChannel); + + delete singleOutputChannel; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... @@ -347,6 +349,9 @@ void GateToASCII::RegisterNewCoincidenceDigiCollection(const G4String& aCollecti // G4cout << " GateToASCII::RegisterNewCoincidenceDigiCollection \n"; m_asciiMessenger->CreateNewOutputChannelCommand(coincOutputChannel); + delete coincOutputChannel; + + } long GateToASCII::VOutputChannel::m_outputFileSizeLimit = 2000000000; diff --git a/source/digits_hits/src/GateToASCIIMessenger.cc b/source/digits_hits/src/GateToASCIIMessenger.cc index f1185dd46..f35fa8660 100644 --- a/source/digits_hits/src/GateToASCIIMessenger.cc +++ b/source/digits_hits/src/GateToASCIIMessenger.cc @@ -213,6 +213,8 @@ void GateToASCIIMessenger::CreateNewOutputChannelCommand(GateToASCII::VOutputCha newCmd->SetGuidance(aGuidance.c_str()); newCmd->SetGuidance("1. true/false"); OutputChannelCmdList.push_back( newCmd ); + + delete newCmd; } //-------------------------------------------------------------------------------------------------------- diff --git a/source/digits_hits/src/GateToBinary.cc b/source/digits_hits/src/GateToBinary.cc index 649e913bc..5cf566bc2 100644 --- a/source/digits_hits/src/GateToBinary.cc +++ b/source/digits_hits/src/GateToBinary.cc @@ -425,6 +425,8 @@ void GateToBinary::RegisterNewSingleDigiCollection( m_outputChannelVector.push_back( singleOutputChannel ); m_binaryMessenger->CreateNewOutputChannelCommand( singleOutputChannel ); + + delete singleOutputChannel; } @@ -437,6 +439,8 @@ void GateToBinary::RegisterNewCoincidenceDigiCollection( m_outputChannelVector.push_back( coincOutputChannel ); m_binaryMessenger->CreateNewOutputChannelCommand( coincOutputChannel ); + + delete coincOutputChannel; } void GateToBinary::VOutputChannel::OpenFile( diff --git a/source/digits_hits/src/GateToBinaryMessenger.cc b/source/digits_hits/src/GateToBinaryMessenger.cc index c37612c8f..b8e4a0ccf 100644 --- a/source/digits_hits/src/GateToBinaryMessenger.cc +++ b/source/digits_hits/src/GateToBinaryMessenger.cc @@ -211,6 +211,8 @@ void GateToBinaryMessenger::CreateNewOutputChannelCommand( // Add the new command m_outputChannelCmd.push_back( newCmd ); + + delete newCmd; } G4bool GateToBinaryMessenger::IsAnOutputChannelCmd( G4UIcommand* command ) diff --git a/source/digits_hits/src/GateToRootMessenger.cc b/source/digits_hits/src/GateToRootMessenger.cc index 03b1e34f7..3b48af829 100644 --- a/source/digits_hits/src/GateToRootMessenger.cc +++ b/source/digits_hits/src/GateToRootMessenger.cc @@ -144,6 +144,9 @@ GateToRootMessenger::~GateToRootMessenger() delete CoincidenceMaskCmd; delete SingleMaskCmd; delete SaveRndmCmd; + + + for (size_t i = 0; igetOpticalParamsToWrite()) @@ -70,6 +71,7 @@ GateToTreeMessenger::GateToTreeMessenger(GateToTree *m) : G4String s = "/gate/output/tree/optical/branches/" + name + "/disable"; auto c = new G4UIcmdWithoutParameter(s, this); m_mapoptical_cmdParameter_toTreeParameter.emplace(c, name); + delete c; } @@ -79,6 +81,7 @@ GateToTreeMessenger::GateToTreeMessenger(GateToTree *m) : G4String s = "/gate/output/tree/Singles/branches/" + name + "/disable"; auto c = new G4UIcmdWithoutParameter(s, this); m_mapsingles_cmdParameter_toTreeParameter.emplace(c, name); + delete c; } for(auto &&m: m_gateToTree->getCoincidencesParamsToWrite()) @@ -87,6 +90,7 @@ GateToTreeMessenger::GateToTreeMessenger(GateToTree *m) : G4String s = "/gate/output/tree/Coincidences/branches/" + name + "/disable"; auto c = new G4UIcmdWithoutParameter(s, this); m_mapscoincidences_cmdParameter_toTreeParameter.emplace(c, name); + delete c; } @@ -104,6 +108,11 @@ GateToTreeMessenger::~GateToTreeMessenger() delete m_enableHitsOutput; delete m_disableHitsOutput; + delete m_enableOpticalDataOutput; + delete m_disableOpticalDataOutput; + delete m_addCollectionCmd; + + } void GateToTreeMessenger::SetNewValue(G4UIcommand *icommand, G4String string) From ecf07f881bec8f2efd703ed5b752722300ad27ea Mon Sep 17 00:00:00 2001 From: kochebina Date: Tue, 13 Jun 2023 15:55:01 +0200 Subject: [PATCH 2/2] remove corrections from ASCII and Binary --- source/digits_hits/src/GateToASCII.cc | 4 ++-- source/digits_hits/src/GateToASCIIMessenger.cc | 2 +- source/digits_hits/src/GateToBinary.cc | 4 ++-- source/digits_hits/src/GateToBinaryMessenger.cc | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/digits_hits/src/GateToASCII.cc b/source/digits_hits/src/GateToASCII.cc index a5a5f97f4..5f9dc9e1b 100644 --- a/source/digits_hits/src/GateToASCII.cc +++ b/source/digits_hits/src/GateToASCII.cc @@ -336,7 +336,7 @@ void GateToASCII::RegisterNewSingleDigiCollection(const G4String& aCollectionNam // G4cout << " GateToASCII::RegisterNewSingleDigiCollection \n"; m_asciiMessenger->CreateNewOutputChannelCommand(singleOutputChannel); - delete singleOutputChannel; + //delete singleOutputChannel; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... @@ -349,7 +349,7 @@ void GateToASCII::RegisterNewCoincidenceDigiCollection(const G4String& aCollecti // G4cout << " GateToASCII::RegisterNewCoincidenceDigiCollection \n"; m_asciiMessenger->CreateNewOutputChannelCommand(coincOutputChannel); - delete coincOutputChannel; + // delete coincOutputChannel; } diff --git a/source/digits_hits/src/GateToASCIIMessenger.cc b/source/digits_hits/src/GateToASCIIMessenger.cc index f35fa8660..a9dfe33c4 100644 --- a/source/digits_hits/src/GateToASCIIMessenger.cc +++ b/source/digits_hits/src/GateToASCIIMessenger.cc @@ -214,7 +214,7 @@ void GateToASCIIMessenger::CreateNewOutputChannelCommand(GateToASCII::VOutputCha newCmd->SetGuidance("1. true/false"); OutputChannelCmdList.push_back( newCmd ); - delete newCmd; + //delete newCmd; } //-------------------------------------------------------------------------------------------------------- diff --git a/source/digits_hits/src/GateToBinary.cc b/source/digits_hits/src/GateToBinary.cc index 5cf566bc2..6ca143172 100644 --- a/source/digits_hits/src/GateToBinary.cc +++ b/source/digits_hits/src/GateToBinary.cc @@ -426,7 +426,7 @@ void GateToBinary::RegisterNewSingleDigiCollection( m_binaryMessenger->CreateNewOutputChannelCommand( singleOutputChannel ); - delete singleOutputChannel; + //delete singleOutputChannel; } @@ -440,7 +440,7 @@ void GateToBinary::RegisterNewCoincidenceDigiCollection( m_binaryMessenger->CreateNewOutputChannelCommand( coincOutputChannel ); - delete coincOutputChannel; + //delete coincOutputChannel; } void GateToBinary::VOutputChannel::OpenFile( diff --git a/source/digits_hits/src/GateToBinaryMessenger.cc b/source/digits_hits/src/GateToBinaryMessenger.cc index b8e4a0ccf..d08367eac 100644 --- a/source/digits_hits/src/GateToBinaryMessenger.cc +++ b/source/digits_hits/src/GateToBinaryMessenger.cc @@ -212,7 +212,7 @@ void GateToBinaryMessenger::CreateNewOutputChannelCommand( // Add the new command m_outputChannelCmd.push_back( newCmd ); - delete newCmd; + //delete newCmd; } G4bool GateToBinaryMessenger::IsAnOutputChannelCmd( G4UIcommand* command )