Strange segmentation violation

Hello,

I’m currently trying to use a third party lib and I’ve figured out a strange conjunction to root’s file IO functions.

The error occurs using the constructor of the third party class:

This throws a segmentation violation depending on the use of TFile before!? The complete error:

[code][size=9]*** Break *** segmentation violation
Using host libthread_db library “/lib/libthread_db.so.1”.
Attaching to program: /proc/20233/exe, process 20233
[Thread debugging using libthread_db enabled]
[New Thread -1250609456 (LWP 20233)]
Failed to read a valid object file image from memory.
0xb7f25410 in ?? ()
#1 0xbfc3e828 in ?? ()
#2 0x00000000 in ?? ()[/size]

[/code]The easiest way to reproduce the segmentation violation is:

[code]
TFile* f;
TTree* tree;

f = new TFile(“first_file”);
tree = (TTree*)f->Get(“tree”);
tree->Delete();
f->Close();
f->Delete();

f = new TFile(“second_file”);
tree = (TTree*)f->Get(“tree”);
tree->Delete();
f->Close();
f->Delete();

// here follows the constructor of the class[/code]

The error can only be reproduced by using two different files! Furthermore, I have found a nasty workaround: if I omit the f->Delete() there is no segmentation violation, but it comes back as soon as I read from the tree before closing it. If I omit all the three delete/close lines, the problem does not occur at all! I’m pretty sure the third party lib uses root functions itself, so maybe it has to do with the way root handles memory. Or is there another function that has to be called before another TFile object can be allocated?

Thanks in advance,
Regards,
Fab

Replace all your statements like

tree->Delete(); f->Delete();by

delete ree; delete f;
Rene

Hello,

Thank you for the idea, but it did not solve the problem. As soon as I remove the comments of one of the tree lines (no matter which), I get the error again.

Regards,
Fab

Could you send the shortest possible script reproducing the problem?

Rene

Of course, I can. It’s just the code I already mentioned:

[code]
void loadrootfile(const char * name)
{
TFile f = new TFile(“first_file”);
TTree tree = (TTree*)f->Get(“tree”);
// read something form tree, but this can also be commented out
// with the effect that I am able to keep the “delete tree” line

// now, as soon as I enable one of these lines, it crashes
// delete tree;
// f->Close();   
// delete f;   

}

int main()
{
loadrootfile(“first_file”);
loadrootfile(“second_file”);

// and thats where it crashes:
classname* thirdpartyclass = new classname("load_from_file");

}[/code]

This file compiled and linked against the root libs + the third party libs can reproduce the error.

Hi,

Since we do not have access to the 3rd party library and do not even know what it is :slight_smile:, we still can not reproduce the problem.

The issue is most like in the code executed by ‘new classname’ …

Cheers,
Philippe

Yes. The package is a commercial package with a poor support/documentation. So that looks like a dead end. I just thought someone has a guess what the constructor might be doing there or why there is connection to the TFile objects.

Greetings,
Fab

Hi,

On which platform are you using this? If it is linux, you could try to run with valgrind to a get better location on the error.

Unless the 3rd party package uses ROOT, I do no see how TFile/TTree would affect it …

… Well unless the ‘new classname(…)’ is somehow using uninitialized memory (making the execution random!).

… Which makes me ask whether there might be some initialization routine than you ought to run before starting to create instance of their objects.

Cheers,
Philippe.

Yes, the platform is linux, so I’ll give it a try.

I’m pretty sure it does use ROOT - at least it has some ROOT export functions. But this conscructor should actually only load the topology of a previously computed neural net. So at that point there is no need for TFile/TTree (the loaded file is plain text).

I thought so, too. But the header files don’t contain anything else than member functions of that class, so I’ll have to start with that constructor.

Again, thank you for your help,
Regards,
Fab