diff --git a/hist/hist/src/THStack.cxx b/hist/hist/src/THStack.cxx index c525a2402ab69..72b6e0c0353c1 100644 --- a/hist/hist/src/THStack.cxx +++ b/hist/hist/src/THStack.cxx @@ -347,11 +347,14 @@ THStack::THStack(const THStack &hstack) : fMaximum(hstack.fMaximum), fMinimum(hstack.fMinimum) { - if (hstack.GetHists()) { - TIter next(hstack.GetHists()); - TH1 *h; - while ((h=(TH1*)next())) Add(h); + { + R__LOCKGUARD(gROOTMutex); + gROOT->GetListOfCleanups()->Add(this); } + + TIter next(hstack.GetHists()); + while (auto h = static_cast(next())) + Add(h); } ////////////////////////////////////////////////////////////////////////////////