About Xalloc()/Xfree() function used in liblbxutil library.

Tadashi Koike t-koike at pop01.odn.ne.jp
Sun Sep 16 22:01:21 PDT 2007


I'm sorry for late a reply , and I thank for some suggestions
about Xalloc()/Xfree() dependence. And I thank Mr. Carsten to
try to test an allocation of Big size memory.

(Again, I am weak in English, so please forgive the error of
the English sentence)

After received suggestions, I researched Xalloc()/Xfree() defined in
libXdmcp.  That code are in lib/libXdmcp/Alloc.c . I quote these
in the last of this mail.

On this research, I understood that Xalloc()/Xfree() are same as
malloc()/free() except that an memory allocation size be specified
as ZERO  by caller. But sorry I couldn't understand a difference of
behavior on failure.

In a library liblbxutil, Xalloc() calls at 3 parts, and 2 case of
these an allocation size was specified non ZERO (using sizeof()).
I think this number of times a little impact to rewrite the source code.
# Xrealloc() was not used in liblbxutil.

After this research, I agree with Mr. Bernardo's offer (Xalloc/Xfree
are able to replace malloc/free). In fact Xmalloc/Xfree defined in
<X11/Xlibint.h> are better to use in replacement.

I am anxious how other X developers think.

Thank you for Mr. Carsten and Mr. Bernardo. I am happy to heard
  other people's suggestions.

Sincerely yours,

  - Tadashi Koike, Japan

-- Xalloc,Xrealloc,Xfree at lib/libXdmcp/Alloc.c -------------
void *
Xalloc (unsigned long amount)
{
     if (amount == 0)
         amount = 1;
     return malloc (amount);
}

void *
Xrealloc (void *old, unsigned long amount)
{
     if (amount == 0)
         amount = 1;
     if (!old)
         return malloc (amount);
     return realloc ((char *) old, amount);
}

void
Xfree (void *old)
{
     if (old)
         free ((char *) old);
}
--------------------------------------------




More information about the xorg mailing list