TTree related crash

_ROOT Version:6.14/06
_Platform: wsl
_Compiler:g++ 7.3.0

I created a test.C file containing the following code:


class TestClass
      TTree *fTree;

      TestClass() : fTree(0) {};

      TTree* GetTree()
         // the following line causes crash
         // everything is find if it is commented out
         if (fTree!=0) return fTree;

         TTree *fTree = new TTree("t","tree");
         double v, c;

         for (int i=0; i<10; i++) {
            v = gRandom->Gaus();
            c = gRandom->Rndm();
         return fTree;
void test()
   TestClass tc;

With if (fTree!=0) return fTree;:

$ root test.C
root [0]
Processing test.C...
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
*** stack smashing detected ***: <unknown> terminated

Without it, everything is fine.

If I compile it: root test.C++, everything is fine as well.

Did I do something wrong here?

         fTree->ResetBranchAddresses(); // disconnect from local variables
         return fTree;
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.