RootTalk


ROOT Discussion Forums

TEfficiency crash on destructor if it has attached functions

Discuss installing and running ROOT here. Please post bug reports here.

Moderator: rootdev

TEfficiency crash on destructor if it has attached functions

Unread postby rneves » Sat Sep 10, 2011 13:48

Hi,

I've been using the TEfficiency class, and I ran into some troubles.
I noticed that if I create a TFile, then a TEfficiency, attach some function to it and then either {delete the TEff. object; close the file; quit root without closing the file}, ie, somehow call the TEfficiency destructor, it crashes.
However if I create the file after attaching the function, it runs smoothly.

Example:
===========================================
// DOESNT WORK
// If TFile is initialized here it crashes
TFile *f = new TFile("out.root","RECREATE");

TEfficiency* pEff = new TEfficiency("eff","my efficiency;x;#epsilon",20,0,10);
TRandom3 rand;
bool bPassed;
double x;
for(int i=0; i<10000; ++i)
{
x = rand.Uniform(10);
bPassed = rand.Rndm() < TMath::Gaus(x,5,4);
pEff->Fill(bPassed,x);
}

TF1* f2 = new TF1("thres","0.8",0,10);
pEff->GetListOfFunctions()->AddFirst(f2);

pEff->Draw("AP");

//
// WORKS if TFile is declared here instead
//

pEff->Write();
f->Close();
===========================================


I went further and found out that the crash occurs in the following line in the destructor (TEfficiency.cxx)

// ...
if(fFunctions) {
TIter next(fFunctions);
TObject* obj = 0;
while((obj = next())) {
delete obj; <<<-------------
}
fFunctions->Delete();
}
// ...

If line indicated above is commented, no crash happens. Of course this can bring a memory leak if the delete (TList) fFunctions doesn't delete all of it's contents. But if it does, then is the above loop really necessary?

What can you tell about this issue? Is this a feature or should be filled as a bug??

Many thanks in advance,
Ricardo
rneves
 
Posts: 8
Joined: Sat Sep 06, 2008 15:09

Re: TEfficiency crash on destructor if it has attached funct

Unread postby moneta » Mon Sep 12, 2011 14:49

Hi,

Yes it is a bug in the destructor of TEfficiency, where the functions were deleted two times. It is now fixed in the trunk and 5.30 patches. Thank you for your post

Lorenzo
moneta
 
Posts: 1416
Joined: Fri Jun 03, 2005 14:38
Location: CERN


Return to ROOT Support

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests