What is XMALLOC and how it compares with malloc?

Kevin Day thekevinday at gmail.com
Thu May 3 22:04:36 UTC 2007


On 5/3/07, David Daney <ddaney at avtrex.com> wrote:
> ehuang at ix.netcom.com wrote:
> > Dear Mike,
> >
> > thanks for quickly getting back to me.
> >
> > The application is RDESKTOP.  It has mess of both malloc and xmalloc.
> > Runs fine on Fedora Core (presumely glibc) but get segfaults under Cirrus ARM
> > linux which uses libcClibc-0.9.28.so    So, I'm trying to understand and
> > trace the memory management.  Whats frustrating is not finding any decent
> > explanation thru google about XMALLOC.  Not even wikipedia!
> >
>
> Wow, not even in wikipedia?!  Have you tried looking at the source code
> of the function?
>
> According to your grep, you should be able to find it in rdesktop.c.
>
> David Daney
>
> >
> > GREP MALLOC
> >
> > cache.c:                text->data = xmalloc(length);
> > nwin.c: uint8 *d2 = xmalloc(width * height);
> > nwin.c: uint8 *d2 = xmalloc(width * height * (depth / 8));
> > nwin.c: bmp = (GR_IMAGE_HDR*)malloc(sizeof(GR_IMAGE_HDR));
> > nwin.c: bmp->palette = (MWPALENTRY*)malloc(2 * sizeof(MWPALENTRY));
> > nwin.c: bmp->imagebits = (MWUCHAR*)malloc(datasize);
> > nwin.c:STATUS("doing malloc - sizeof %d\n",sizeof(GR_PALETTE) );
> > nwin.c:    pal = (GR_PALETTE*)malloc(sizeof(GR_PALETTE));
> > nwin.c:    STATUS("malloc error!\n");
> > nwin.c: pixels = (GR_PIXELVAL*)malloc(cx * cy * depth);
> > orders.c:       d2 = xmalloc(width*height);
> > orders.c:       bmpdata = xmalloc(width * height);
> > orders.c:       map.colours = xmalloc(3 * map.ncolours);
> > orders.c:               rev_data = xmalloc(datasize);
> > rdesktop.c:#include <stdlib.h>  /* malloc realloc free */
> > rdesktop.c:                     char *errormsg = (char *)malloc(500);
> > rdesktop.c:/* malloc; exit if out of memory */
> > rdesktop.c:void *xmalloc2(int l, char *s, int size)
> > rdesktop.c:     void *mem = malloc(size);
> > rdesktop.c:             ERROR("xmalloc %d\n", size);
> > rdesktop.c:/* malloc; exit if out of memory */
> > rdesktop.c:void *xmalloc(int size)
> > rdesktop.c:     void *mem = malloc(size);
> > rdesktop.c:             ERROR("xmalloc %d\n", size);
> > rdp.c:                  rawdata = xmalloc(width * height);
> > rdp.c:                  rawdata = xmalloc(width * height);
> > secure.c:       mcs_data.p = mcs_data.data = xmalloc(mcs_data.size);
> > tcp.c:  in.data = xmalloc(in.size);
> > tcp.c:  out.data = xmalloc(out.size);
> >
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://busybox.net/cgi-bin/mailman/listinfo/uclibc
>


perhaps xmalloc is akin to the rpl_malloc issues that autoconf imposes
when malloc does not return the unsafe glibc live pointer.

however, looking into this myself, the link
http://gcc.gnu.org/ml/gcc-patches/1999-11/msg00025.html
refers to xmalloc as coming from gcc

My next assumption is that xmalloc is some sort of gcc's internal
implementation of malloc

This suggests that the rdesktop program is commiting malpractice of
calling internal gcc functions and no the standard (and by now
probably universal) malloc.

however, considering the application name 'rdesktop' it reminds me of
remote_desktop which ulitmately references Xorg.

I faintly and possibly imaginarily remember seeing xmalloc during Xorg
compilation.
This seems to make more sense than the my gcc assumption above, so I
feel safest to assume that it is calling Xorg's malloc implementation
for some reason. Which seems to explain why it is called "xmalloc" for
Xorg Malloc..

So, there was my entire sequence of thoughts regardding your issue, I
say look into Xorg and find xmalloc.
-- 
Kevin Day



More information about the uClibc mailing list