[PATCH v2 2/4] Free the data returned by XGetWindowProperty()

Eirik Byrkjeflot Anonsen eirik at eirikba.org
Fri May 22 02:03:14 PDT 2015


walter harms <wharms at bfs.de> writes:

> Am 21.05.2015 22:42, schrieb Alan Coopersmith:
>> On 05/21/15 10:13 AM, walter harms wrote:
>>> maybe this was the case in older versions.
>>> a current free() should accept NULL.
>>>
>>> Xfree is onyl a wrapper for free()
>>> #define Xfree(ptr) free((ptr))
>> 
>> That's Xfree(), not XFree().   X11 has both, because it loves you and
>> wants you to learn that case sensitivity matters.
>> 
>
> int
> XFree (void *data)
> {
>         Xfree (data);
>         return 1;
> }
>
> i hesitate to ask if anyone ever check the return code of XFree().
> Unfortunately i promised to spend time for an other project
> but it would be nice if someone could cleanup to this mess at least
> fix the documentation.

Checking the return value of XFree() (or free() for that matter) usually
doesn't make much sense. What would you do if it fails?

As I said in my previous reply to this point though, I believe the
documentation of the XFree() function is correct. what do you want the
documentation to say? Maybe something like:

   The XFree() function of Xlib does not necessarily handle NULL values
   safely. However, X.org's current implementation of XFree() ignores
   NULL values. Thus, if you know your application will only be used
   with X.org's implementation, you can safely use NULL values.

That doesn't really seem like a good idea to me. On the other hand, if
all implementations of X11 now handle NULL values, it might make sense
to consider the de-facto behaviour to be "correct". And then change the
documentation to something like:

   Current implementations of X11 all ignore NULL values passed to
   XFree(). Thus if you do not need your application to be compatible
   with Xlib implementations older than <some suitable date>, you can
   safely pass NULL to XFree().

I don't know how true such a statement would be, though.

eirik


More information about the xorg-devel mailing list