Problem 2194 - Incorrect call to putenv in TShielding constructor
Summary: Incorrect call to putenv in TShielding constructor
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: physics_lists (show other problems)
Version: 10.4
Hardware: All All
: P4 normal
Assignee: Gunter.Folger
URL:
Depends on:
Blocks:
 
Reported: 2019-09-26 17:49 CEST by Kyle Knoepfel
Modified: 2019-09-26 18:36 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Kyle Knoepfel 2019-09-26 17:49:28 CEST
A putenv call is made inside of the TShielding constructor in line 162 of the G4 file physics_lists/lists/include/Shielding.icc:

if ( LEN_model == "HP" ) {
  //Activate prodcuton of fission fragments in neutronHP
  char env_ff[]="G4NEUTRONHP_PRODUCE_FISSION_FRAGMENTS=1";
  putenv(env_ff); // Oops--caching pointer to stack variable
}

The putenv call accepts a char* argument, which is cached by the environment.  The above argument code compiles because a char[] array decays to a char*.  The problem is that env_ff is a stack variable that goes away once the program goes past line 163.  Subsequent calls to getenv in the TROOT destructor (or anywhere else) will likely fail because an invalid pointer is accessed.

This error is preventing the Mu2e experiment from using multi-threaded processing of events, which is where the error was first noticed.
Comment 1 Kyle Knoepfel 2019-09-26 18:36:57 CEST
Krzysztof has informed me that this bug has been fixed with 10.5.  Will mark this as resolved.  My apologies for the noise.