Root 5.24 crashing with valgrind

Dear Rooters I found a strange behaviour of ROOT when using it with valgrind.

I use the following binary (main.cxx, see below) to call the root interpreter, from which i initialise and run my analysis code (which is partly in libraries, but called from macros). I use this construction , because i found the root executable doesn’t like to be profiled or gdb’ed directly. When trying to use valgrind on my main executable, it crashed somewhere in the core libraries: TUnixSystem::GetLinkedLibraries() (TUnixSystem.cxx:2656).

After investigating what’s going on i found, that ldd is called to find out which libraries are linked to the executable, but the call fails (only from within valgrind) and produces a zero pointer. by just adding a query for p to be zero, i could get valgrind running.

Maybe you want to add the same query to the svn code?

kind regards
dirk

----- main.cxx:

#include "TROOT.h" #include "TRint.h" #include <iostream> using std::ios; int main(int argc, char **argv) { ios::sync_with_stdio(); //synch c/fortran and c++ out! TRint TheApp("ciproot", &argc, argv); TheApp.Run(true); return 0; }

---- fixed TUnixSystem::GetLinkedLibraries() around line 2650

[code] FILE *p = OpenPipe(TString::Format("%s %s", cLDD, exe), “r”);
TString ldd;
while (p!=0&&ldd.Gets§) { //<-----------------
cout << ldd << endl;
TString delim(" \t");
TObjArray *tok = ldd.Tokenize(delim);

  // expected format:
  //    libCore.so => /home/rdm/root/lib/libCore.so (0x40017000)
  TObjString *solibName = (TObjString*)tok->At(2);
  if (!solibName) {
     // case where there is only one name of the list:
     //    /usr/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
     solibName = (TObjString*)tok->At(0);
  }
  if (solibName) {
     TString solib = solibName->String();
     if (solib.EndsWith(cSOEXT)) {
        if (!linkedLibs.IsNull())
           linkedLibs += " ";
        linkedLibs += solib;
     }
  }
  delete tok;

}
if (p!=0) {ClosePipe§;} //<-----------------[/code]

[quote]. I use this construction , because i found the root executable doesn’t like to be profiled or gdb’ed directly.[/quote]Actually, all you need to do is to use the executable named root.exe (rather than root) when using valgrind or gdb.

Cheers,
Philippe

PS. I am not quite sure what this call fails for you with valgrind … however the protection you propose is good idea and was added to the repository.