Irreproducible crash after termination of application

Dear Rooters

I have the weird problem that my application crashes sporadically after
it has terminated successfully.

This is my main function:

int main(int argc, char **argv)
{
   TApplication theApp("App", &argc, argv);

   if (gROOT->IsBatch()) {
      fprintf(stderr, "%s: Cannot run in batch mode\n", argv[0]);
      return 1;
   }

   XPSFrame *xpsApp = new XPSFrame(0, 400, 220);
   theApp.Run(kTRUE);  //kTRUE needed in order to delete xpsApp!
   delete xpsApp;

   cout << "XPSApp successfully terminated." << endl;
   return 0;
}//main

Usually, it exits normally, but sometimes I get:

XPSApp successfully terminated.

*** Break *** segmentation violation

[1]+ Abort trap ./XPSApp

This means that it crashes after termination!
Below I add the output of the crash reporter of MacOS X.
It shows that the crash occurs at TGPicturePool::FreePicture()

Since my application uses TShutter, there are two methods calling a picture:
1, CreateShutter() contains:

   fDefaultPic = gClient->GetPicture("folder_s.xpm");

which I delete in DeleteShutter()

2, AddShutterItem() contains the following code fragment:

   for (Int_t i=0; data[i].sPixmapName != 0; i++) {
      buttonpic = gClient->GetPicture(data[i].sPixmapName);
      if (!buttonpic) {
         printf("Shutter: missing pixmap \"%s\", using default",
                data[i].sPixmapName);
         buttonpic = fDefaultPic;
      }//if

      button = new TGPictureButton(container, buttonpic, data[i].sId);
      fTrash->Add(button);
      button->Connect("Clicked()", "XPSFrame", this, "DoShutter()");
      button->SetToolTipText(data[i].sTipText);
      data[i].sButton = button;
      container->AddFrame(button, hint);
   }//for_i

I am not sure if there is an error in this code. Remember, that in most
cases my application terminates without any problem.

Does anybody have a hint?

Best regards
Christian

Here is the output of the CrashReporter:

Host: m1398p012.adsl.highway.telekom.at
Date/Time: 2005-05-23 22:41:09 +0200
OS Version: 10.3.1 (Build 7C107)

Command: XPSApp (./XPSApp)
PID: 663
Thread: 0

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0xd3000000

Thread 0 Crashed:
#0 0xd3000000 in 0xd3000000
#1 0x04ea22e0 in TGPicturePool::FreePicture(TGPicture const*) (TGPicturePool::FreePicture(TGPicture const*) + 48)
#2 0x04e83894 in TGListTreeItem::~TGListTreeItem unified (TGListTreeItem::~TGListTreeItem unified + 60)
#3 0x04e85be8 in TGListTree::PDeleteChildren(TGListTreeItem*) (TGListTree::PDeleteChildren(TGListTreeItem*) + 120)
#4 0x04e85bb8 in TGListTree::PDeleteChildren(TGListTreeItem*) (TGListTree::PDeleteChildren(TGListTreeItem*) + 72)
#5 0x04e85bb8 in TGListTree::PDeleteChildren(TGListTreeItem*) (TGListTree::PDeleteChildren(TGListTreeItem*) + 72)
#6 0x04e83c70 in TGListTree::~TGListTree unified (TGListTree::~TGListTree unified + 116)
#7 0x02c520c8 in TList::Delete(char const*) (TList::Delete(char const*) + 152)
#8 0x02c4fc34 in THashList::Delete(char const*) (THashList::Delete(char const*) + 32)
#9 0x04e530b0 in TGClient::~TGClient unified (TGClient::~TGClient unified + 96)
#10 0x04eca408 in TRootApplication::~TRootApplication unified (TRootApplication::~TRootApplication unified + 92)
#11 0x02bcc4d4 in TApplication::~TApplication unified (TApplication::~TApplication unified + 168)
#12 0x0008fa94 in main (main + 328)
#13 0x00002254 in _start (crt.c:267)
#14 0x000020c8 in start (start + 48)

PPC Thread State:
srr0: 0xd3000000 srr1: 0x4000d930 vrsave: 0x00000000
cr: 0x44004242 xer: 0x00000004 lr: 0x02c507c0 ctr: 0xd3000000
r0: 0x02c507a4 r1: 0xbffff820 r2: 0x055a991b r3: 0x04a21740
r4: 0x030cb69c r5: 0x04a21740 r6: 0x031a5680 r7: 0x00000001
r8: 0x0000001f r9: 0xa00011ac r10: 0x00001897 r11: 0x05602004
r12: 0xd3000000 r13: 0x00000000 r14: 0x00000000 r15: 0x00000000
r16: 0x00000000 r17: 0x00000000 r18: 0x00000000 r19: 0x00000000
r20: 0x00000000 r21: 0x00000000 r22: 0x00000000 r23: 0x00000000
r24: 0x00000000 r25: 0x00000000 r26: 0xbffffd98 r27: 0x00000000
r28: 0x04871ee0 r29: 0x04853fc0 r30: 0x04a21740 r31: 0x02c5077c

Hi Christian,

In your message you wrote that you delete the fDefaultPic in DeleteShutter() method. Could you please use gClient->FreePicture(…) instead of and let me know does the crash persists.

I am at ACAT05 in Zeuthen this week and I have no root on my laptop, so I can test this case on Monday.

Best regards, Ilka

Dear Ilka

Thank you for this suggestion. I have changed my code accordingly, but it
will take some time until I can tell you if it works. As I said this error
occurs only sporadically.

Bes regards
Christian

Hi Christian,

Just keep us informed.

Thank you, Ilka

Dear Ilka

Meanwhile I could finally identify when the crash occurs:
I have a TGListTree and use the root icon to display root files.
When I doubleclick to open system directories and their subdirectories
which do not contain a root file I can quit my program w/o crash.
However, once I open a directory containing root files and the respective
icons, my program crashes when terminated, as described before.

Here are the corresponding code fragments which are similar to guitest.C:

//______________________________________________________________________________
XDataFrame::XDataFrame(TGCompositeFrame *parent, XPSFrame *main, UInt_t w, UInt_t h)
{
   fTreeFrame = new TGVerticalFrame(fSubFrame, 10, 10, kFixedWidth);
   fTreeView  = new TGCanvas(fTreeFrame, 10, 10, kSunkenFrame | kDoubleBorder);
   fListTree  = new TGListTree(fTreeView->GetViewPort(), 10, 10, kHorizontalFrame,
                               parent->GetWhitePixel());

   fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "XDataFrame",
                      this, "DoTreeClicked(TGListTreeItem*, Int_t)");
   fListTree->Connect("DoubleClicked(TGListTreeItem*, Int_t)", "XDataFrame",
                      this, "DoTreeDoubleClicked(TGListTreeItem*, Int_t)");

   fListTree->Associate(parent);
   fTreeView->SetContainer(fListTree);
   fListTree->SetCanvas(fTreeView);
   hint = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
   fTreeFrame->AddFrame(fTreeView, hint);
   fTreeFrame->Resize(fTreeView->GetDefaultWidth()+100, fTreeFrame->GetDefaultHeight());
   fTrash->Add(hint);

   fListLevel = 0;
   fRootIcon  = gClient->GetPicture("rootdb_t.xpm");

#ifdef G__WIN32
   TString dir("c:\\");
#else
   TString dir("/");
#endif

   fListLevel = fListTree->AddItem(fListLevel, dir.Data());
}//Constructor

//______________________________________________________________________________
XDataFrame::~XDataFrame()
{
//   delete fRootIcon;
   gClient->FreePicture(fRootIcon);

//NOT necessary??
   fListTree->RemoveAll();
//PROBLEM: delete fListTree crashes program
//   delete fListTree;

   delete fTreeView;
   delete fTreeFrame;
}//Destructor

//______________________________________________________________________________
void XDataFrame::DoTreeDoubleClicked(TGListTreeItem *item, Int_t btn)
{
   if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return;

   // use  UserData to indicate that item was already browsed
   item->SetUserData((void*)1);

   TSystemDirectory dir(item->GetText(),fXPSFrame->DirName(item).Data());

   TList *files = dir.GetListOfFiles();
   if (files) {
      TIter next(files);
      TSystemFile *file;
      TString fname;

      while ((file=(TSystemFile*)next())) {
         fname = file->GetName();
         if (file->IsDirectory()) {
            if ((fname!="..") && (fname!=".")) { // skip it
               fListTree->AddItem(item,fname.Data());
            }//if
         } else if (fname.EndsWith(".root")) {   // add root files
            fListTree->AddItem(item,fname.Data(), fRootIcon, fRootIcon);      
         }//if
      }//while

      delete files;
   }//if
}//DoTreeDoubleClicked

It is not clear why my program crashes in the destructor when I
call “delete fListTree”. When I do not delete fListTree then my
program crashes only after termination. However, in both cases I
get the same message from the crash reporter!
Since the crash only occurs when I display a directory containing
a root file and its icon fRootIcon this must be the reason. Even
when I do not delete fRootIcon I get the crash.

Do you have any hint?

Best regards
Christian

Dear Christian,

Beside what you report I saw a side effect in TGListTree class after some cvs changes submitted after 18-May. We are currently working on these problems. I will keep you informed.

Sorry for the delay of my answer.

Best regards, Ilka

Dear Ilka

Thank you for this information, I am looking forward to the cvs changes.

Best regards
Christian

Hi Christian,

I can reproduce the case you have reported on my computer. In fact, there is no deletion of the TGListTree object in the example given in guitest.C. Once this statement is included, the same back trace can be seen. I will keep you informed about the fix.

Cheers, Ilka

Dear Ilka

Thank you, I am glad that you can reproduce my problem.
BTW, I thought that deletion of TGListTree in guitest.C is covered by:
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);

Best regards
Christian

Hi Christian,

Indeed you are right - there is a hierarchical cleaning set. Without this setting if I delete the list tree I see the same back trace. I will continue my investigation next week.

Thank you, Ilka

Hi Christian,

Investigating the problem you have reported I found out that despite of fMain->SetCleanup(kDeepCleanup); there is no deep cleanning made in TestDirList and some other classes in the guitest. I will provide the necessary changes in cvs shortly to avoid the existing memory leak. In fact the code goes via TGMainFrame::CloseWindow(), gVirtualX->DestroyWindow(fId) and all widgets remain in the memory for those classes.

Cheers, Ilka

Hi Christian,

A fix in TGListTree is provided in cvs head - could you please test your program and let us know how it ends.

Thank you, Ilka

Dear Ilka

I have just tested my application with the new cvs version, and everything
works fine, there is no crash after quitting the application.
BTW, I have deleted RemoveAll() as you suggested, it seems not to be
necessary.

Thank you very much for your help.
Best regards
Christian