Hi -
I’m working on a research project to make a MySQL plugin read information from ROOT files. I’ve created a simple class RootReader to open a ROOT file and see if it contains a TTree, in which case it’s considered valid for the purposes of this project:
RootReader::RootReader(char* fn) { strcpy(filename, fn); } // constructor
bool RootReader::isValid() {
TFile file(filename);
if (file.IsZombie()) return false;
TTree* tree = (TTree*)file.Get(“CollectionTree”);
bool foundTree = (tree != NULL);
return foundTree;
}
When I use RootReader in a simple C program it works fine. However, when I link RootReader and the ROOT libs into MySQL, there is a seg fault deep inside the ROOT call chain during the call to the TFile constructor. This seg fault does not always occur at the same line of code but always happens somewhere inside cint/src/v6_func.cxx. I suspect some kind of memory corruption.
The Makefile.am used to build the shared lib libRootWrapper that contains RootReader and links to the ROOT libs is included at the end of this post. The Makefile that links libRootWrapper into MySQL is similar.
Here is a stack trace showing the seg fault:
Program received signal SIGSEGV, Segmentation fault.
#0 0x00002aaaac47d72c in G__interpret_func (result7=0x0, funcname=0x0,
libp=0x0, hash=0, p_ifunc=0x0, funcmatch=0, memfunc_flag=1)
at cint/src/v6_ifunc.cxx:4764
#1 0x00002aaaac46dae3 in G__getfunction (
item=0xe9f24c “AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)", known3=0x40a5b408,
memfunc_flag=1) at cint/src/v6_func.cxx:2517
#2 0x00002aaaac54aceb in G__getstructmem (store_var_type=112,
varname=0x40a5a4b0 “”,
membername=0xe9f24c “AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)",
tagname=0x40a5a6b0 “gPluginMgr”, known2=0x40a5b408,
varglobal=0x2aaaac7fbc80, objptr=2) at cint/src/v6_var.cxx:6611
#3 0x00002aaaac53a6e9 in G__getvariable (
item=0xe9f240 “gPluginMgr->AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)",
known=0x40a5b408, varglobal=0x2aaaac7fbc80, varlocal=0x40a6db20)
at cint/src/v6_var.cxx:5242
#4 0x00002aaaac438166 in G__getitem (
item=0xe9f240 “gPluginMgr->AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)")
at cint/src/v6_expr.cxx:1884
#5 0x00002aaaac44b796 in G__getexpr (
expression=0x40a5e1e0 “gPluginMgr->AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)")
at cint/src/v6_expr.cxx:1470
#6 0x00002aaaac4c9c04 in G__exec_function (
statement=0x40a5e1e0 “gPluginMgr->AddHandler(“TArchiveFile”,”.+[.]zip$",“TZIPFile”,“Core”,“TZIPFile(const char*,const char*,TFile*)”)",
pc=0x40a5e96c, piout=0x40a5e968, plargestep=0x40a5e960, presult=0x40a5e8f0)
at cint/src/v6_parse.cxx:600
#7 0x00002aaaac4d296c in G__exec_statement (mparen=0x40a6dd84)
at cint/src/v6_parse.cxx:6997
#8 0x00002aaaac4813f4 in G__interpret_func (result7=0x40a74c10,
funcname=0x40a74610 “P010_TZIPFile”, libp=0x40a6e400, hash=1031,
p_ifunc=0xef9970, funcmatch=1, memfunc_flag=0)
at cint/src/v6_ifunc.cxx:5966
#9 0x00002aaaac46e872 in G__getfunction (item=0x40a77690 “P010_TZIPFile()”,
known3=0x40a750f8, memfunc_flag=0) at cint/src/v6_func.cxx:2728
#10 0x00002aaaac4382c7 in G__getitem (item=0x40a77690 “P010_TZIPFile()”)
at cint/src/v6_expr.cxx:1896
#11 0x00002aaaac44b796 in G__getexpr (expression=0xcc5d30 “P010_TZIPFile()”)
at cint/src/v6_expr.cxx:1470
#12 0x00002aaaac44d0ff in G__calc_internal (
exprwithspace=0x40a7a010 “P010_TZIPFile()”) at cint/src/v6_expr.cxx:1061
#13 0x00002aaaac4e1d5d in G__process_cmd (
line=0x2aaaac2b08fe “.X /etc/root/plugins/TArchiveFile/P010_TZIPFile.C”,
prompt=0xe471e8 “”, more=0xe471e0, err=0x40a7b07c, rslt=0x40a7aff0)
at cint/src/v6_pause.cxx:2231
#14 0x00002aaaabb53418 in TCint::ProcessLine (this=0xe471b0,
line=0x2aaaac2b08fe “.X /etc/root/plugins/TArchiveFile/P010_TZIPFile.C”,
error=0x0) at meta/src/TCint.cxx:333
#15 0x00002aaaabb4c321 in TCint::ProcessLineSynch (this=0xe471b0,
line=0x2aaaac2b08fe “.X /etc/root/plugins/TArchiveFile/P010_TZIPFile.C”,
error=0x0) at meta/src/TCint.cxx:368
—Type to continue, or q to quit—
#16 0x00002aaaaba939b9 in TApplication::ExecuteFile (
file=0xcc6b08 “/etc/root/plugins/TArchiveFile/P010_TZIPFile.C”, error=0x0)
at base/src/TApplication.cxx:924
#17 0x00002aaaabb4fd13 in TCint::ExecuteMacro (this=0xe471b0,
filename=0xcc6b08 “/etc/root/plugins/TArchiveFile/P010_TZIPFile.C”,
error=0x0) at meta/src/TCint.cxx:996
#18 0x00002aaaabaea281 in TROOT::Macro (this=0x2aaaac29cc40,
filename=0xcc2500 “/etc/root/plugins/TArchiveFile/P010_TZIPFile.C”,
error=0x0, padUpdate=false) at base/src/TROOT.cxx:1403
#19 0x00002aaaabac8731 in TPluginManager::LoadHandlerMacros (this=0xe43590,
path=0xe7c6c0 “/etc/root/plugins/TArchiveFile”)
at base/src/TPluginManager.cxx:390
#20 0x00002aaaabac8bdf in TPluginManager::LoadHandlersFromPluginDirs (
this=0xe43590, base=0x2aaaad85d843 “TArchiveFile”)
at base/src/TPluginManager.cxx:462
#21 0x00002aaaabacab74 in TPluginManager::FindHandler (this=0xe43590,
base=0x2aaaad85d843 “TArchiveFile”,
uri=0xcc5648 “petaminer/Egamma0002.root”)
at base/src/TPluginManager.cxx:539
#22 0x00002aaaad7425bb in TArchiveFile::Open (
url=0xeadac8 “file:petaminer/Egamma0002.root”, file=0x40a7bc50)
at io/src/TArchiveFile.cxx:128
#23 0x00002aaaad76c0d9 in TFile (this=0x40a7bc50,
fname1=0xc97518 “petaminer/Egamma0002.root”, option=0x2aaaae6c73af “”,
ftitle=0x2aaaae6c73af “”, compress=1) at io/src/TFile.cxx:315
#24 0x00002aaaae6c6fad in RootReader::isValid (this=0x40a7c100)
at RootReader.cxx:29
Any advice much appreciated!
Thanks -
Paul
-------------- Makefile.am -------------------
Library
lib_LTLIBRARIES = libRootWrapper.la
pkginclude_HEADERS = RootReader.h RootWriter.h
libRootWrapper_la_SOURCES = RootReader.cxx RootWriter.cxx
libRootWrapper_la_LDFLAGS = -version-info 1:0 -R @ROOTLIBDIR@
libRootWrapper_la_LIBADD = -L@ROOTLIBDIR@ @ROOTLIBS@ @ROOTAUXLIBS@
AM_CPPFLAGS = -Wall -I@ROOTINCDIR@
AM_LDFLAGS = -L@ROOTLIBDIR@
Executables
bin_PROGRAMS = testRead testWrite
testRead_SOURCES = testRead.cxx
testRead_LDADD = @ROOTLIBS@ libRootWrapper.la
testWrite_SOURCES = testWrite.cxx
testWrite_LDADD = @ROOTLIBS@ libRootWrapper.la