Problem 792

Summary: memory leak and other problems in G4GeneralParticleSource
Product: Geant4 Reporter: jasondet
Component: eventAssignee: flei
Status: RESOLVED LATER    
Severity: normal    
Priority: P2    
Version: 7.1   
Hardware: All   
OS: All   

Description jasondet 2005-09-09 12:42:16 CEST
I think I found a memory leak in G4GeneralParticleSource: whenever one calls
AddaSource(w), a new G4SingleParticleSource is allocated and the pointer to it
is pushed back into the sourceVector. If one then calls DeleteaSource(i) or
ClearAll(), the pointer is erased from sourceVector, but the memory for the
G4GeneralParticleSource it points to is never deallocated.

I also noticed that while ClearAll() clears the sourceProbability vector,
DeleteaSource(i) does not delete any entries in sourceProbability. This is
likely also a bug.

I recommend fixing DeleteaSource(i) to deallocate the memory for entry i before
erasing it, and to handle sourceProbability as well. Then I would recommend
rewriting ClearAll() to keep calling DeleteaSource(0) while sourceVector.size()
is non-zero so that the behavior of the two functions is always consistent.

Jason
Comment 1 flei 2005-09-29 04:41:59 CEST
The memory leak is very limited and will not cause too much a problem in most
simulations. Will look into this later.
Jason, it seems you may already have this fixed. If so can you send me your
correced code?

Fan