Motif program crashes when performing Drag and Drop

We have an application which allows user to perform Drag and Drop operations. The problem we are facing now is the application crash. System works fine for some time and allows user to perform many drag drops successfully. But after running for some time and user perform a drag and drop the system crashes.
Following stack trace we are getting while system crashes.

XtDispatchEvent [Event.c]
RemoveAllPMgr [libXm.so.3]
XtCallCallbackList [Callback.c]
Recursive [Destroy.c]
XtPhase2Destroy [Destroy.c]
_XtDoPhase2Destroy [Destroy.c]
XtDestroyWidget [Destroy.c]
DragDropFinish [libXm.so.3]
DropConvertCallback [libXm.so.3]
DoLocalTransfer [Selection.c]

Ours is a 32-Bit application running in the Solaris/Linux. We are using the Motif 2.3.1 Version

We had run a IBM Rational Purify for the application to find memory issues. We could find one memory issue as below. This is similiar to stack trace which we are getting on crash.
SBR(Stack array Bounds Read)
SBR: Stack array bounds read (36 times)
This is occurring while in:
XtDispatchEvent [Event.c]
RemoveAllPMgr [libXm.so.3]
XtCallCallbackList [Callback.c]
Recursive [Destroy.c]
XtPhase2Destroy [Destroy.c]
_XtDoPhase2Destroy [Destroy.c]
XtDestroyWidget [Destroy.c]
DragDropFinish [libXm.so.3]
DropConvertCallback [libXm.so.3]
DoLocalTransfer [Selection.c]
Reading 4 bytes from 0xffbee478.
Frame pointer 0xffbee458
Address 0xffbee478 is 32 bytes above stack pointer in function XtCallCallbackList.
This happens when the Drag Drop completes

Please note that here the XtDestroyWidget is called by MOTIF itself. We believe this is to destroy the DragContext created by us using the XmDragStart. Since the XtDestroyWidget is called by the MOTIF from DragDropFinish, we cannot stop calling it.
To prevent the SBR(Stack array Bounds Read), we have removed all the XmNdestroyCallback callbacks functions for the DragContext widget using the below command.
XtRemoveAllCallbacks(dc, XmNdestroyCallback);

But even after this removal the SBR(Stack array Bounds Read) is happening same as previous.
Can you please let us know why the call back function is called even after we removed the callbacks ?.

Also i had tried the a sample program from the Motif Programming Manual (Volume 6A). The sample program can be found in the below link.
http://www.ist.co.uk/motif/books/vol6A/ch-22.fm.html#791437
file_manager.c and editor_dnd.c are the example i took.
For these program also when we ran IBM Rational Purify, SBR raised

SBR: Stack array bounds read (117 times)
This is occurring while in:
XtDispatchEvent [Event.c]
RemoveAllPMgr [libXm.so.3]
XtCallCallbackList [Callback.c]
Recursive [Destroy.c]
XtPhase2Destroy [Destroy.c]
_XtDoPhase2Destroy [Destroy.c]
XtDispatchEvent [Event.c]
XtAppMainLoop [Event.c]
Reading 4 bytes from 0xffbeea10.
Frame pointer 0xffbee9f0
Address 0xffbeea10 is 32 bytes above stack pointer in function XtCallCallbackList.

Can you please let me know is there any way to avoid this SBR happening here?.
Also is it possible to check is a Bug in motif?.


sanushchacko

sanushchacko's picture

Please find reason and

Please find reason and solution for the above issue.
As we know the DragDropFinish is the final function called on a drag and drop operation. Motif will do all cleanup operations in this routine. For certain Drag and Drop operations X-server will delay the calling of DragDropFinish. By this time other drag and drop operations can happen. Later when all the other X-events from the queue are processed, X-server will call the pending DragDrop. The DragContext will become invalid by that time and cleanup activities in the DragDropFinish can result in crash. This happens because X-requests are executed asynchronously on the X server. If we use XSync and make it synchronous, it can lead to performance issues.

The solution adopted here is to check whether the previous Drag and Drop finished before another Drag and Drop is initiated. If the previous operation is still underway, wait for 10 secs. If the first operation is not finished even after 10 secs, use XmDragCancel to finish it. Since DragDropFinish will be the only pending function call in previous Drag Drop and all the other business operations might have completed by this time.


rabi1785

rabi1785's picture

Hi, I have a problem with

Hi,

I have a problem with the motif function, XmTargetsAreCompatible.
Here is the details:
I am trying to drag an object to another object(i.e,Drag and Drop functionality) in 64 bit Linux. The problem is, out of 10, 2 times it is getting dropped to the particular location.But it is getting failed in rest of the cases where it is working perfectly on 32 bit platforms.

I debugged my code and found the following:
Before getting dropped to the particular location it checks the compatibility of source and target by using a function "XmTargetsAreCompatible(XtDisplay(w),exportTargets,numExportTargets,importTargets,numImportTargets)".
This function should return TRUE if they are compatible and FALSE for incompatible.

So it is returning 0 in most of the cases though it is compatible(in 64 bit Linux). And returning 1 for one or two times out of 10.
When it is returning 1 it is getting dropped(it is working).
Actually I want to make it work for all the cases like 32 bit platforms.

It would be great if you can help in XmTargetsAreCompatible function to make it return 1 :)

Thanks in advance,
Rabi