Loop crashing, works when unrolled

Hi all,

I am having a strange issue. I am new to using CINT, so this is quite puzzling to me.

I have a script that looks like this:

[code]#include

void test()
{
if(!TClassTable::GetDict(“SimTree”) )
{
gROOT->ProcessLine(".L SimTree.C");
}

TFile* f = new TFile("../data/Sim_dualImager7779.root");
SimTree t;
t.setFile( f );

SimData s;
for( int i = 0; i < 10; ++i )
{
 s = t.loadNext();
}

}
[/code]

The for loop crashes after completing t.loadNext() twice. It then gives the error:

root.exe(90726) malloc: *** error for object 0x102f34468: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

If the loop is unrolled so the script looks like this it works fine:

[code]#include

void test()
{
if(!TClassTable::GetDict(“SimTree”) )
{
gROOT->ProcessLine(".L SimTree.C");
}

TFile* f = new TFile("../data/Sim_dualImager7779.root");
SimTree t;
t.setFile( f );


SimData s;
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();
s = t.loadNext();

}
[/code]

Any clue what’s going on? The unrolled code should be the exact same thing as the loop, so what is the difference?

Thanks
–John

update: I have compiled the same code instead of using CINT and it seems to work.

No ideas?

Hi,

Yes, this is due to the poor support for temporary object in CINT. This is indeed solved by compiling the code.

Philippe.