Re: [ROOT] Possible bug in TFile.cxx

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Wed Jul 31 2002 - 19:08:48 MEST


Hi Jiri,

  the problem is the following:

when closing a file all HEAP objects referenced in the file directory
are deleted. Stack objects are not deleted because they will be deleted
when the object goes out of scope. However, all objects created in cint
are created on the heap, even the ones created with a stack syntax, like
b in this case. Now what happens is that on closing of the file, b gets
deleted because it is on the heap while at program exit it is again
deleted by cint because the interpreter cleans up all its "stack"
objects. To solve this issue we would need to get from cint the info
that the just created object is on the cint stack. We are working with
Masa on such a solution. For the time being a work around is to new b.

Cheers, Fons.



On Wed, 2002-07-31 at 18:03, Jiri Masik wrote:
> Joseph Tuggle <jtuggle@fnal.gov> writes:
> 
> > Hello,
> > 
> > I'm writing a program that uses the TFile class to write out some 
> > histograms and other ROOT objects. My program goes something like this:
> > 
> > TFile outputFile("output.root", "recreate");
> > // All my code
> > outputFile.Write();
> > outputFile.Close();
> > 
> > However, I get a segmentation fault when I try to close the file. I 
> > traced the fault to the statement surrounded by asterisks below in 
> > TFile.cxx (I included the rest for context):
> > 
> >    // Delete free segments from free list (but don't delete list header)
> >    if (fFree) {
> >       fFree->Delete();
> >    }
> > 
> >    if (IsOpen()) {
> >       SysClose(fD);
> >       fD = -1;
> >    }
> > 
> >    fWritable = kFALSE;
> > 
> >    if (cursav)
> >       cursav->cd();
> >    else {
> >       gFile      = 0;
> > ***   gDirectory = gROOT; ***
> >    }
> > 
> > When it reaches this statement, it tells me the problem is with this 
> > line from Class TIter in TCollection.h:
> > 
> >    TIter(const TCollection *col, Bool_t dir = kIterForward)
> >         : fIterator(col ? col->MakeIterator(dir) : 0) { }
> > 
> > Any ideas?
> > 
> > Thanks!
> > Joe
> > 
> 
> Hi Joe,
> 
> do you run anything like
> root [0] TFile outputFile("output.root", "recreate");
> root [1] TH1F b("h1","",10,0.,1.)
> root [2] outputFile.Write()  
> root [3] outputFile.Close() 
> root [4] .q
> ?
> 
> I'm getting a segfault after .q too.
> 
> It seems that the histogram is destructed twice once when the file is
> closed and second when global objects are cleaned up.
> I have the current CVS sources, Debian/Linux/ppc. It is reproduucible
> on lxplus too. 
> cheers
> -- 
> 	Jiri
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:02 MET