Problem 1905

Summary: Memory Leak in G4VScatteringCollision
Product: Geant4 Reporter: John Peterson <jrpeter>
Component: processes/hadronic/models/im_r_matrixAssignee: Gunter.Folger
Status: RESOLVED FIXED    
Severity: normal    
Priority: P4    
Version: 10.2   
Hardware: All   
OS: All   
Attachments: A Brief Excerpt of Valgrind Output

Description John Peterson 2016-11-01 16:05:05 CET
Created attachment 425 [details]
A Brief Excerpt of Valgrind Output

While debugging my application which uses Geant4 for the simulation of gamma ray interactions with mater using the standard QBBC physics list, Valgrind detected a memory leak shown in the included excerpt. Note that this output is repeated many times over apparently for each interaction.

Line 49 of G4VScatteringCollision.cc (processes/hadronic/models/im_r_matrix/src/G4VScatteringCollision.cc), where theAngularDistribution is initialized is reported as a memory leak because on line 183 of the same file, in G4VScatteringCollision::establish_G4MT_TLS_G4VScatteringCollision(), the variable theAngularDistribution is overwritten with a new G4AngularDistribution without destroying the original.

Something similar to the following fixes the memory leak 

180  void G4VScatteringCollision::establish_G4MT_TLS_G4VScatteringCollision()
181  {
182    establish_G4MT_TLS_G4VCollision();
183    if (theAngularDistribution)
184    {
185      delete(theAngularDistribution);
186    }
187    theAngularDistribution = new G4AngularDistribution(true);
189  }

Two additional comments on the fix. I am not familiar with the contents and behavior of the G4AngularDistribution class, so this fix preserves the original behavior of replacing theAngularDistribution. Second, the check to see if theAngularDistribution is not a null pointer before deletion is likely unnecessary. I do not see a way for the program to get to this step without theAngularDistribution being initialized.
Comment 1 Gunter.Folger 2016-12-12 12:13:09 CET
Will look at this.
Comment 2 Gunter.Folger 2018-07-05 13:39:07 CEST
Fixed in Geant4 10.4