motif application crashes while calling XtDestroyWidget
We have a 32bit Motif Gui application. Now we ported the application from Solaris to Linux and the system is crashing very frequently. On our analysis we could find that this issue happened when we are closing the forms in our application. When the forms are closed we will delete the forms and will call the function XtDestroyWidget() to remove the widgets. We ran a purify for the application and we could found that the Stack Array Bounds Read (SBR) is happening when we close the form.
I had downloaded a sample motif program from the internet which is using XtDestroyWidget() to destroy the object. When i ran purify for this sample program also, i could found the same SBR.
SBR: Stack array bounds read (54 times): * This is occurring while in: XtDispatchEvent [libXt.so.4] RemoveAllPMgr [libXm.so.3] XtCallCallbackList [libXt.so.4] XtPhase2Destroy [libXt.so.4] _XtDoPhase2Destroy [libXt.so.4] XtDispatchEvent [libXt.so.4] XtAppMainLoop [libXt.so.4] main [popup.cc:49] _start [crt1.o] * Reading 4 bytes from 0xffbfe4f0. * Frame pointer 0xffbfe4d0 * Address 0xffbfe4f0 is 32 bytes above stack pointer in function XtCallCallbackList.
This SBR is happening in the XtAppMainLoop(). From these facts i assume that this SBR is a common one and related to motif rather than to our application.
Can you please add some thoughts to the following questions. 1) Why SBR is happening when we use XtDestroyWidget(). Is this SBR a severe one.
2) I had removed the XtDestroyWidget and used XtUnrealizeWidget(). This will help me to remove the SBR and hence crash is not happening. Also all normal forms will be removed normally. But the problem i am facing in this approach is the POP_UP forms are NOT removed in this method. Can any one please suggest a work around for removing POP_UP forms also other than the HIDE option.
It will be very helpful for me if anyone can answer or add some thoughts for this issue.
Thanks in advance, Sanush Chacko
-----Adding Sample Program.. Hi Please find the sample program from where i got the SBR.
include X11/StringDefs.h include Xm/Xm.h include Xm/PushB.h
Widget toplevel;
void close_window(Widget w, XtPointer client_data, XtPointer event_data) { Widget popup = (Widget)client_data; XtDestroyWidget(popup); }
void pop(Widget w开发者_StackOverflow, XtPointer client_data, XtPointer event_data) { Widget a, button, popup;
popup = XtVaCreatePopupShell("Popup", transientShellWidgetClass, toplevel, NULL);
button = XtVaCreateManagedWidget("Close", xmPushButtonWidgetClass, popup,
NULL);
XtAddCallback(button, XmNactivateCallback, close_window, (XtPointer)popup);
XtPopup(popup, XtGrabNone);
}
main(int argc, char *argv[]) { Widget button; XtAppContext app; XmString label;
toplevel = XtVaAppInitialize(&app, "Popup", NULL, 0,
&argc, argv, NULL, NULL);
label = XmStringCreateSimple("Make popup");
button = XtVaCreateManagedWidget("pushme", xmPushButtonWidgetClass, toplevel,
XmNlabelString, label,
NULL);
XmStringFree(label);
XtAddCallback(button, XmNactivateCallback, pop, NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
}
You should not destroy the widget within a callback called by the widget.
Instead of creating a new popup every time you click a button, create a popup at the start of the program when you create the button, show and hide the popup as required, and then destroy it after XtAppMainLoop() returns.
This is more efficient in terms of performance (but slightly less efficient in terms of memory).
I'm a bit rusty, but I believe you can also manage/unmanage the widget rather than just hide/show it.
精彩评论