TTree of struct crashes on destructor while reading

I’m creating a TTree with a struct like:

“struct roides_t {
Int_t index;
Int_t event;
Int_t step;
Int_t rerun;
Float_t weight;
Float_t etamin ;
Float_t etamax ;
Float_t phimin ;
Float_t phimax ;
Char_t algoname[100];

Then I read the TFile with:

def validate():
file = TFile(“feature.root”,“read”)
roides_tree = file.Get( ‘RoIDesTree’ )
roides = roides_t()
roides_tree.SetBranchAddress( “RoIDes”, AddressOf( roides, ‘index’ ))
entries = roides_tree.GetEntries()

print "Found %d entries"%entries
nb = roides_tree.GetEntry( 6 )
print "End of validate, close files"
print "End of validate, close files closed"

if name == ‘main’:

With this function defined, I have a crash in the Tclass dst (from gdb):

#2 0x00007ffff45e8636 in TClass::Destructor(void*, bool) () from /afs/
#3 0x00007ffff735740b in PyROOT::op_dealloc_nofree(PyROOT::ObjectProxy*) ()

But if everything that is in validate() is moved in the main explicitly, the crash is not happening. I’ve added the file and the code to this entry.
I’m using:
Python 2.7.6 (default, Jul 8 2014, 13:33:49) [GCC 4.8.1] on linux2
ROOT 5.34/24

Please can you help me to understand where the memory corruption is happening?
Francesca (1.13 KB)
feature.root (18.3 KB)

The I run your python script I get:

Traceback (most recent call last):
  File "", line 7, in <module>
    import rootpy
  File "/Users/couet/git/roottrunk-bin/lib/", line 301, in _importhook
    return _orig_ihook( name, *args, **kwds )
ImportError: No module named rootpy

I’m using some ATLAS setup. You can try to replace that line with:
import libPyROOT


How do you run this script … I still get some strange messages.

I run as usual:

[fpastore@lxplus047] >python
Found 97 entries
End of validate, close files
End of validate, close files closed

… and then hung!

or in gdb:

[fpastore@lxplus047] >gdb python
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-83.el6)
Copyright © 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and “show warranty” for details.
This GDB was configured as “x86_64-redhat-linux-gnu”.
For bug reporting instructions, please see:
Reading symbols from /usr/bin/python…(no debugging symbols found)…done.
Missing separate debuginfos, use: debuginfo-install python-2.6.6-64.el6.x86_64
(gdb) run
Starting program: /usr/bin/python
[Thread debugging using libthread_db enabled]
Detaching after fork from child process 26783.
[New Thread 0x7fffedc44700 (LWP 26789)]
Found 97 entries
End of validate, close files
End of validate, close files closed

Program received signal SIGSEGV, Segmentation fault.
0x0000003b07e788bd in _int_free () from /lib64/
(gdb) where
#0 0x0000003b07e788bd in _int_free () from /lib64/
#1 0x0000003b08f77e9a in G__calldtor () from /usr/lib64/root/
#2 0x00007ffff11eba87 in TClass::Destructor(void*, bool) () from /usr/lib64/root/
#3 0x00007ffff19cf66b in PyROOT::op_dealloc_nofree(PyROOT::ObjectProxy*) ()
from /usr/lib64/python2.6/site-packages/
#4 0x00007ffff19cf6a9 in ?? () from /usr/lib64/python2.6/site-packages/
#5 0x0000003b09a9a705 in ?? () from /usr/lib64/
#6 0x0000003b09ad278d in PyEval_EvalFrameEx () from /usr/lib64/
#7 0x0000003b09ad6b7f in PyEval_EvalFrameEx () from /usr/lib64/
#8 0x0000003b09ad7647 in PyEval_EvalCodeEx () from /usr/lib64/
#9 0x0000003b09ad7722 in PyEval_EvalCode () from /usr/lib64/
#10 0x0000003b09af1b9c in ?? () from /usr/lib64/
#11 0x0000003b09af1c70 in PyRun_FileExFlags () from /usr/lib64/
#12 0x0000003b09af315c in PyRun_SimpleFileExFlags () from /usr/lib64/
#13 0x0000003b09aff892 in Py_Main () from /usr/lib64/
#14 0x0000003b07e1ed5d in __libc_start_main () from /lib64/
#15 0x0000000000400649 in _start ()


Ah ok … it looks fine for me. On Mac, both ROOT 6.07/03 and 5.34/35 give me:

$ python 
Found 97 entries
End of validate, close files
End of validate, close files closed

… no “hung”.

Hmmm, I’m on lxplus:
Python 2.6.6
ROOT 5.34/32

which python are you using?

$ python --version
Python 2.7.10

But I am not a python expert … I will ask a colleague who might have more hints.

Hi Francesca,

I tried to reproduce your script on lxplus using these instructions to set up root*. The script also needs rootpy, can you give us a recipe to set up an environment equivalent to yours (I know you probably set up the atlas environment)?


I’m not sourcing any ATLAS setup, and I commented out all settings in the .bash_profile, then:
-bash-4.1$ which root
(which is ROOT 5.34/32)
-bash-4.1$ python --version
Python 2.6.6

No idea of where the settings are coming from (no ROOTSYS is set), probably the default lxplus bash configuration??


Hi Francesca,

I got confused by

thanks for clarifying. How do I get the rootpy version you are using?


no idea… I just do the import in the file I sent you. I didn’t install any rootpy by myself…
How can I guess it?


it must be in your environment.
Do you see any hint in the output of

python -v


no “root” string found in the output of your command.
Anyhow, while doing other make-ups, I discovered that I fill the char[100] variable in the structure with a string that in some cases is shorter than 100, and this is probably the reason of my crash in reading it back (some memory corruption…). Fixed it, I don’t have any problem.
Strange that you don’t see the crash, while I do.
It would be anyhow nice to know which rootpy version I’m using, just for reference in next dev.


Not is problem some case shorter, is problem many case longer. TTree simply return pointer, PyROOT simply eat pointer: but is tell size 100. Not true! Size is 102 most case. Check bytes read return GetEntry().

Because is memory overwrite, some see crash, some no. Is depend hit important bytes or no.


Hi Dominique,
I found indeed an overwrite when producing the tuple. Problem is solved.