This is the mail archive of the cygwin-xfree@cygwin.com mailing list for the Cygwin XFree86 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Memory access error in XWin -multiwindow


Biju,

I just tried my idea of preventing multiple calls to XInitThreads... it didn't seem to make any difference at all. I will have to look at this problem more closely... which means that I won't be able to work on it for a while. I will be out of town this weekend and I am moving across town next week, so I will be pretty busy.

Harold

Harold L Hunt II wrote:

Biju,

I can now reproduce your problem using both Test91 and Test91-DEBUG (with Ralf's patches applied). I reproduce the problem using ssh to login to my home machine which is on an 256 Kbps uplink. When I launch konqueror remotely, XWin.exe dies with the Windows error message. I tried the same thing at home on the local network with no problems. Thus, we are most likely looking at a race condition.

I think that this problem probably doesn't have anything to do with malloc failing... rather, I think the problem is that we call XInitThreads (or whatever it is called) more than once in the same process. I should add protection so that that function is only called once for the entire process.

I don't promise that this will fix the problem, but I at least have a test case now so I can start to do something about it.

Harold

Biju G C wrote:

Harold,

I am facing an issue of Memory access error in XWin -multiwindow mode
see http://www.cygwin.com/ml/cygwin-xfree/2003-06/msg00294.html

So Ralf pointed me to http://cygwin.com/ml/cygwin-xfree/2003-06/msg00162.html

After seeing that patch, I have just gone thru XWin Source and found,
at lot of place we call memory alloc and not testing the return value.
I am attaching the list & extracts from programs
I dont know all of those will make any issue.

I did not checked whether it is properly "free()"-ed
And also I did not checked the functions which receives allocated memory another function as return value or thru a passed argument to the called function.



List of variables:-


in winmultiwindowwm.c
       pXMsgArg        at function winInitWM

in winmultiwindowwindow.c
vlist at function winMoveXWindow vlist at function winResizeXWindow


in winmultiwindowicons.c
iconData at function winScaleXBitmapToWindows image at function winXIconToHICON imageMask at function winXIconToHICON mask at function winXIconToHICON


in winmultiwindowclass.c
*res_name at function winMultiWindowGetClassHint *res_role at function winMultiWindowGetWindowRole


in winconfig.c
       ret             at function winNormalizeName

in winclipboardxevents.c
pszUTF8 at function winClipboardFlushXEvents pszReturnData at function winClipboardFlushXEvents pwszUnicodeStr at function winClipboardFlushXEvents hGlobal at function winClipboardFlushXEvents


in winclipboardtextconv.c
       pszDestBegin / pszDest at function winClipboardUNIXtoDOS



####### EXTRACTS FROM PROGRAMS ##########



####### NEXT FILE ##########

winmultiwindowwm.c

Bool
winInitWM (void **ppWMInfo,
pthread_t *ptWMProc,
pthread_t *ptXMsgProc,
pthread_mutex_t *ppmServerStarted,
int dwScreen)
{
WMProcArgPtr pArg = (WMProcArgPtr) malloc (sizeof(WMProcArgRec));
WMInfoPtr pWMInfo = (WMInfoPtr) malloc (sizeof(WMInfoRec));
XMsgProcArgPtr pXMsgArg = (XMsgProcArgPtr) malloc (sizeof(XMsgProcArgRec));


  /* Bail if the input parameters are bad */
  if (pArg == NULL || pWMInfo == NULL)
    {
      ErrorF ("winInitWM - malloc fail.\n");
      return FALSE;
    }




####### NEXT FILE ##########


winmultiwindowwindow.c

void
winMoveXWindow (WindowPtr pWin, int x, int y)
{
  XID *vlist = malloc(sizeof(long)*2);

  (CARD32*)vlist[0] = x;
  (CARD32*)vlist[1] = y;
  ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin));
  free(vlist);
}


/* * winResizeXWindow - */

void
winResizeXWindow (WindowPtr pWin, int w, int h)
{
  XID *vlist = malloc(sizeof(long)*2);

  (CARD32*)vlist[0] = w;
  (CARD32*)vlist[1] = h;
  ConfigureWindow (pWin, CWWidth | CWHeight, vlist, wClient(pWin));
  free(vlist);
}



####### NEXT FILE ##########

winmultiwindowicons.c


static void winScaleXBitmapToWindows (int iconSize, int effBPP, PixmapPtr pixmap, unsigned char *image) {

........

  iconData = malloc (xStride * pixmap->drawable.height);
  miGetImage ((DrawablePtr) &(pixmap->drawable), 0, 0,
          pixmap->drawable.width, pixmap->drawable.height,
          ZPixmap, 0xffffffff, iconData);






HICON winXIconToHICON (WindowPtr pWin) {

.........
  image = (unsigned char * ) malloc (stride * iconSize);
  imageMask = (unsigned char *) malloc (stride * iconSize);
  mask = (unsigned char *) malloc (maskStride * iconSize);





####### NEXT FILE ##########

winmultiwindowclass.c

int
winMultiWindowGetClassHint (WindowPtr pWin, char **res_name, char **res_class)
{


....

(*res_name) = malloc (len_name + 1);


int winMultiWindowGetWindowRole (WindowPtr pWin, char **res_role) {

....
(*res_role) = malloc (len_role + 1);




####### NEXT FILE ##########


winconfig.c

char *
winNormalizeName (const char *s)
{

......

ret = malloc (strlen (s) + 1);




####### NEXT FILE ##########


winclipboardxevents.c
Bool
winClipboardFlushXEvents (HWND hwnd,
              Atom atomClipboard,
              Atom atomLocalProperty,
              Atom atomUTF8String,
              Atom atomCompoundText,
              Atom atomTargets,
              Atom atomDeleteWindow,
              int iWindow,
              Display *pDisplay,
              Bool fUnicodeSupport)
{

........
          pszUTF8 = (char *) malloc (iUTF8); /* Don't need +1 */
          WideCharToMultiByte (CP_UTF8,



...........


if (iCount > 0) { pszReturnData = malloc (strlen (ppszTextList[0]) + 1); strcpy (pszReturnData, ppszTextList[0]); } else { pszReturnData = malloc (1); pszReturnData[0] = 0; }


........... pwszUnicodeStr = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1)); /* Do the actual conversion */ MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, pwszUnicodeStr, iUnicodeLen);

........

/* Allocate global memory for the X clipboard data */
if (fUnicodeSupport)
hGlobal = GlobalAlloc (GMEM_MOVEABLE,
sizeof (wchar_t) * (iUnicodeLen + 1));
else
hGlobal = GlobalAlloc (GMEM_MOVEABLE, strlen (pszReturnData) + 1);


      /* Obtain a pointer to the global memory */
      pszGlobalData = GlobalLock (hGlobal);
      if (pszGlobalData == NULL)
        {
........




####### NEXT FILE ##########


winclipboardtextconv.c

void
winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength)
{

.......
  /* Allocate a new string */
  pszDestBegin = pszDest = malloc (iLength + iNewlineCount + 1);




________________________________________________________________________ Want to chat instantly with your online friends? Get the FREE Yahoo! Messenger http://uk.messenger.yahoo.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]