Skip to content
Snippets Groups Projects
Commit 2aa8e78a authored by Philippe Canal's avatar Philippe Canal
Browse files

Improve tear down in case of interpreter static object holding pointer to object in TFiles.

We need to first Close the file before deleting the interpreter object,
otherwise the script:

   auto f = TFile::Open(filename,"RECREATE");
   TH1F h(...);
   h.Fill();
   // etc...
   .q

would result in an 'empty' file.

However, when closing the file, we can not delete the object its own and some interpreter
static object (for example a MakeClass skeleton) might hold pointer to those objects.

To resolve this, we introduce a new flag to TDirectory/TDirectoryFile/TFile Close ("nodelete")
that will write the data in to the physical file but will not remove the object from memory.

valgrind --suppressions=/opt/build/root_builds/rootcling.cmake/etc/valgrind-root.supp root.exe -b -l -q execLHEF.C
==6337== Memcheck, a memory error detector
==6337== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==6337== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==6337== Command: root.exe -b -l -q execLHEF.C
==6337==

Processing execLHEF.C...
direct
Warning in <TClass::Init>: no dictionary for class TRootLHEFEvent is available
Warning in <TClass::Init>: no dictionary for class TRootWeight is available
Warning in <TClass::Init>: no dictionary for class TRootLHEFParticle is available
Warning in <TClass::Init>: no dictionary for class TSortableObject is available
all=79618 zero=60000 low=9599 high=10019
reader
all=79618 zero=60000 low=9599 high=10019
legacySelector
Info in <TTreePlayer::MakeClass>: Files: lhef_leg_sel_gen.h and lhef_leg_sel_gen.C generated from TTree: LHEF
all=79618 zero=60000 low=9599 high=10019
selector
all=79618 zero=60000 low=9599 high=10019
makeClass
Info in <TTreePlayer::MakeClass>: Files: lhef_mc_gen.h and lhef_mc_gen.C generated from TTree: LHEF
all=79618 zero=60000 low=9599 high=10019
(int) 0
==6337== Invalid read of size 8
==6337==    at 0x1636165F: TTree::GetCurrentFile() const (TTree.cxx:5247)
==6337==    by 0x405F343: ???
==6337==    by 0x405E6DB: ???
==6337==    by 0x405E6AB: ???
==6337==    by 0x911919A: cling::IncrementalExecutor::runAndRemoveStaticDestructors(cling::Transaction*) (in /mnt/vdb/lsf/workspace/root-pullrequests-build/build/lib/libCling.so)
==6337==    by 0x90C7A3D: cling::Interpreter::runAndRemoveStaticDestructors() (in /mnt/vdb/lsf/workspace/root-pullrequests-build/build/lib/libCling.so)
==6337==    by 0x8FB13E2: TCling::ResetGlobals() (TCling.cxx:3237)
==6337==    by 0x52C4915: TROOT::EndOfProcessCleanups() (TROOT.cxx:1193)
==6337==    by 0x54CC89F: TUnixSystem::Exit(int, bool) (TUnixSystem.cxx:2153)
==6337==    by 0x5361A5B: TApplication::Terminate(int) (TApplication.cxx:1281)
==6337==    by 0x4E52AE2: TRint::Terminate(int) (TRint.cxx:686)
==6337==    by 0x4E5183E: TRint::Run(bool) (TRint.cxx:437)
==6337==  Address 0x11387c40 is 336 bytes inside a block of size 696 free'd
==6337==    at 0x4C2C171: operator delete(void*) (vg_replace_malloc.c:575)
==6337==    by 0x53BC849: TStorage::ObjectDealloc(void*) (TStorage.cxx:362)
==6337==    by 0x53A2A9A: TObject::operator delete(void*) (TObject.cxx:988)
==6337==    by 0x16353FA7: TTree::~TTree() (TTree.cxx:958)
==6337==    by 0x5416C48: TCollection::GarbageCollect(TObject*) (TCollection.cxx:734)
==6337==    by 0x541F3B6: TList::Delete(char const*) (TList.cxx:534)
==6337==    by 0x5419B66: THashList::Delete(char const*) (THashList.cxx:215)
==6337==    by 0x82D03C9: TDirectoryFile::Close(char const*) (TDirectoryFile.cxx:556)
==6337==    by 0x82E1049: TFile::Close(char const*) (TFile.cxx:942)
==6337==    by 0x52C411F: (anonymous namespace)::R__ListSlowClose(TList*) (TROOT.cxx:1092)
==6337==    by 0x52C4220: TROOT::CloseFiles() (TROOT.cxx:1113)
==6337==    by 0x52C48EF: TROOT::EndOfProcessCleanups() (TROOT.cxx:1190)
==6337==  Block was alloc'd at
==6337==    at 0x4C2B145: operator new(unsigned long) (vg_replace_malloc.c:333)
==6337==    by 0x53BC7DD: TStorage::ObjectAlloc(unsigned long) (TStorage.cxx:330)
==6337==    by 0x4E4F165: TObject::operator new(unsigned long) (TObject.h:152)
==6337==    by 0x162D5267: ROOT::new_TTree(void*) (G__Tree.cxx:3940)
==6337==    by 0x54669D2: TClass::New(TClass::ENewType, bool) const (TClass.cxx:4777)
==6337==    by 0x8329330: TKey::ReadObjectAny(TClass const*) (TKey.cxx:1058)
==6337==    by 0x82D1FB0: TDirectoryFile::GetObjectChecked(char const*, TClass const*) (TDirectoryFile.cxx:1044)
==6337==    by 0x16340AC4: void TDirectoryFile::GetObject<TTree>(char const*, TTree*&) (TDirectoryFile.h:80)
==6337==    by 0x405F27F: ???
==6337==    by 0x405E5F3: ???
==6337==    by 0x405E5BB: ???
==6337==    by 0x405E01D: ???
==6337==
==6337==
parent 8d4e0d2f
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment