From fe42bc0a7187f8172692a4b6ca93cd60388973bb Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Thu, 13 Oct 2016 12:34:04 -0700 Subject: [PATCH] Avoid access gROOT after its teardown in destructors (Fix ROOT-8395) --- graf2d/graf/src/TCutG.cxx | 3 ++- math/fumili/src/TFumili.cxx | 3 ++- montecarlo/eg/src/TDatabasePDG.cxx | 3 ++- tree/tree/src/TChain.cxx | 8 +++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/graf2d/graf/src/TCutG.cxx b/graf2d/graf/src/TCutG.cxx index 49c71b29220b6..ce71aee05fd15 100644 --- a/graf2d/graf/src/TCutG.cxx +++ b/graf2d/graf/src/TCutG.cxx @@ -242,7 +242,8 @@ TCutG::~TCutG() { delete fObjectX; delete fObjectY; - gROOT->GetListOfSpecials()->Remove(this); + if ( gROOT && !gROOT->TestBit( TObject::kInvalidObject ) ) + gROOT->GetListOfSpecials()->Remove(this); } //////////////////////////////////////////////////////////////////////////////// diff --git a/math/fumili/src/TFumili.cxx b/math/fumili/src/TFumili.cxx index fdaa4168040bf..edc3492058dc9 100644 --- a/math/fumili/src/TFumili.cxx +++ b/math/fumili/src/TFumili.cxx @@ -211,7 +211,8 @@ void TFumili::BuildArrays(){ TFumili::~TFumili() { DeleteArrays(); - gROOT->GetListOfSpecials()->Remove(this); + if (gROOT && !gROOT->TestBit(TObject::kInvalidObject)) + gROOT->GetListOfSpecials()->Remove(this); if (gFumili == this) gFumili = 0; } diff --git a/montecarlo/eg/src/TDatabasePDG.cxx b/montecarlo/eg/src/TDatabasePDG.cxx index 66426747caabb..5f7f220964e62 100644 --- a/montecarlo/eg/src/TDatabasePDG.cxx +++ b/montecarlo/eg/src/TDatabasePDG.cxx @@ -91,7 +91,8 @@ TDatabasePDG::~TDatabasePDG() fListOfClasses->Delete(); delete fListOfClasses; } - gROOT->GetListOfSpecials()->Remove(this); + if (gROOT && !gROOT->TestBit(TObject::kInvalidObject)) + gROOT->GetListOfSpecials()->Remove(this); auto fgInstance = GetInstancePtr(); *fgInstance = nullptr; } diff --git a/tree/tree/src/TChain.cxx b/tree/tree/src/TChain.cxx index 5e9e016eb6aef..4d1d22ef750ae 100644 --- a/tree/tree/src/TChain.cxx +++ b/tree/tree/src/TChain.cxx @@ -173,7 +173,9 @@ TChain::TChain(const char* name, const char* title) TChain::~TChain() { - gROOT->GetListOfCleanups()->Remove(this); + bool rootAlive = gROOT && !gROOT->TestBit(TObject::kInvalidObject); + + if (rootAlive) gROOT->GetListOfCleanups()->Remove(this); SafeDelete(fProofChain); fStatus->Delete(); @@ -196,10 +198,10 @@ TChain::~TChain() delete[] fTreeOffset; fTreeOffset = 0; - gROOT->GetListOfSpecials()->Remove(this); + if (rootAlive) gROOT->GetListOfSpecials()->Remove(this); // Remove from the global list - gROOT->GetListOfDataSets()->Remove(this); + if (rootAlive) gROOT->GetListOfDataSets()->Remove(this); // This is the same as fFile, don't delete it a second time. fDirectory = 0;