Re: Memory access error in XWin -multiwindow

2003-07-08 Thread Harold L Hunt II
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
   pXMsgArgat function winInitWM 

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

in winmultiwindowicons.c
   iconDataat function winScaleXBitmapToWindows 
   image   at function winXIconToHICON 
   imageMask   at function winXIconToHICON 
   maskat 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));
  XMsgProcArgPtrpXMsgArg = (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, 0x, 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

Re: Memory access error in XWin -multiwindow

2003-07-08 Thread Harold L Hunt II
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
   pXMsgArgat function winInitWM
in winmultiwindowwindow.c
   vlist   at function winMoveXWindow
vlist   at function winResizeXWindow

in winmultiwindowicons.c
   iconDataat function winScaleXBitmapToWindows
image   at function winXIconToHICONimageMask   at 
function winXIconToHICONmaskat 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)
{
  WMProcArgPtrpArg = (WMProcArgPtr) malloc 
(sizeof(WMProcArgRec));
  WMInfoPtrpWMInfo = (WMInfoPtr) malloc (sizeof(WMInfoRec));
  XMsgProcArgPtrpXMsgArg = (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, 0x, 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

RE: Memory access error in XWin -multiwindow

2003-07-07 Thread Ralf Habacker
Ralf Habacker wrote:

 After installing this package, relink the Xserver with the following line:

 $ make LDFLAGS=-Wl,--whole-archive -Wl,-lmemwatch -Wl,--no-whole-archive

I just noticed two little issue with linking xwin:

1. The above link line is a link line using default Makefiles, but unfortunally
Xwin uses not this standard. So you have to use the following.

make
EXTRA_LOAD_FLAGS=-Wl,--whole-archive -Wl,-lmemwatch -Wl,--no-whole-archive -Wl,
-debug XWin.exe

2. I have overseeen, that Xwin does not support stderr output, so there are not
results for xwin. I've uploaded an updated mem_watch (release 1.1) to
http://sourceforge.net/project/showfiles.php?group_id=27249.

MEMWATCH_OUTPUT=/c/temp/test.log ./test

Ralf





Re: Memory access error in XWin -multiwindow

2003-07-06 Thread Harold L Hunt II
Both of these approaches look interesting.

Thanks Biju and Ralf.

Harold

Ralf Habacker wrote:

Hi Biju,


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


You can try the mem_watch library on
http://sourceforge.net/project/showfiles.php?group_id=27249.
It allows checking of memory related calls on cygwin with minimal effort.
After installing this package, relink the Xserver with the following line:

$ make LDFLAGS=-Wl,--whole-archive -Wl,-lmemwatch -Wl,--no-whole-archive

Then start Xwin and you can see all memory related calls and there calling
address.
See an example output below (you can get more informations through the INSTALL
file of the memwatch release).
$ ./test
MemWatch hooks installed (set MEMWATCH=1 env var to enable debugging)
Memory Checker report
=
number of calls:
malloc   : 3
calloc   : 1
realloc  : 0
free : 1
used memory  : 350

unfree'd memory areas

  address sizecalladdr

 0a040488  30000401afc
 0a040448   2000401ac7
 0a040460   3000401ad9
==
   350
compile this application with debugging symbols and try
addr2line to get the source line of the relating call
addr2line -e ./test.exe calladdr

May be that helps.

Cheers
Ralf



Memory access error in XWin -multiwindow

2003-07-04 Thread Biju G C
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
   pXMsgArgat function winInitWM 


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


in winmultiwindowicons.c
   iconDataat function winScaleXBitmapToWindows 
   image   at function winXIconToHICON 
   imageMask   at function winXIconToHICON 
   maskat 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));
  XMsgProcArgPtrpXMsgArg = (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, 0x, 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

RE: Memory access error in XWin -multiwindow

2003-07-04 Thread Ralf Habacker
Hi Biju,

 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

You can try the mem_watch library on
http://sourceforge.net/project/showfiles.php?group_id=27249.
It allows checking of memory related calls on cygwin with minimal effort.

After installing this package, relink the Xserver with the following line:

$ make LDFLAGS=-Wl,--whole-archive -Wl,-lmemwatch -Wl,--no-whole-archive

Then start Xwin and you can see all memory related calls and there calling
address.

See an example output below (you can get more informations through the INSTALL
file of the memwatch release).

$ ./test
MemWatch hooks installed (set MEMWATCH=1 env var to enable debugging)

Memory Checker report
=
number of calls:
malloc   : 3
calloc   : 1
realloc  : 0
free : 1

used memory  : 350

unfree'd memory areas

  address sizecalladdr

 0a040488  30000401afc
 0a040448   2000401ac7
 0a040460   3000401ad9
==
   350

compile this application with debugging symbols and try
addr2line to get the source line of the relating call

addr2line -e ./test.exe calladdr

May be that helps.

Cheers
Ralf