Problem 1905 - Memory Leak in G4VScatteringCollision
Summary: Memory Leak in G4VScatteringCollision
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: processes/hadronic/models/im_r_matrix (show other problems)
Version: 10.2
Hardware: All All
: P4 normal
Assignee: Gunter.Folger
URL:
Depends on:
Blocks:
 
Reported: 2016-11-01 16:05 CET by John Peterson
Modified: 2018-07-05 13:39 CEST (History)
0 users

See Also:


Attachments
A Brief Excerpt of Valgrind Output (7.00 KB, text/plain)
2016-11-01 16:05 CET, John Peterson
Details

Note You need to log in before you can comment on or make changes to this problem.
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