Skip to content
Snippets Groups Projects
Commit 922e704b authored by Benjamin Morgan's avatar Benjamin Morgan Committed by Benjamin Morgan
Browse files

Do not stream to std::cout in G4strstreambuf destructor

G4strstreambufs attached to the Geant4's logging streams are generally
destructed post main by static destruction. ATLAS identified a case
in testing with Geant4 11.2:

https://its.cern.ch/jira/browse/SIM-839

that exposes an issue with G4strstreambuf's destructor here. It will
stream any remaining characters to std::cout, but this may not exist
at this point, resulting in a crash. It is however difficult to
reproduce this issue outside of this case.

Remove flushing to std::cout inside G4strstreambuf destructor.
Explicitly flush G4cout etc ostreams in G4iosFinalization to
ensure buffers are cleared. This function is explicitly called
in the destructor of G4UImanager, which is destructed by G4RunManagerKernel's
destructor. This should ensure clean destruction before static
destruction. Also explicitly flush in Sequential mode
parent 04b9f621
No related branches found
No related tags found
No related merge requests found
......@@ -52,12 +52,6 @@ class G4strstreambuf : public std::basic_streambuf<char>
~G4strstreambuf() override
{
// flushing buffer...
// std::cout is used because destination object may not be alive.
if (count != 0) {
buffer[count] = '\0';
std::cout << buffer;
}
delete[] buffer;
}
......@@ -219,6 +213,11 @@ void G4iosInitialization()
void G4iosFinalization()
{
// Reverse order
// --- Flush
_G4debug_p()->flush();
_G4cout_p()->flush();
_G4cerr_p()->flush();
// --- Streams
delete _G4debug_p();
_G4debug_p() = &std::cout;
......@@ -263,7 +262,11 @@ std::ostream G4cout(&G4coutbuf);
std::ostream G4cerr(&G4cerrbuf);
void G4iosInitialization() {}
void G4iosFinalization() {}
void G4iosFinalization() {
G4debug.flush();
G4cout.flush();
G4cerr.flush();
}
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment