[PATCH 0/3] Janitorial: remove redundant NULL check before free().

Michael Stefaniuc mstefani at redhat.de
Mon Oct 9 16:33:59 CDT 2006

Hello Alexandre,

here is the research i've done regarding free(NULL) crashing. I hope i
have covered all usefull OSes. Nothing modern where current Wine would
compile and run on crashes when freeing a NULL pointer. If somebody
wants to get Wine compiling and running on a OS where free(NULL) crashes
then writing a short wrapper around free would be his smallest problem.

The patches themselfs do not depend on each other but depend on this
message to be accepted.

ANSI-C Standard:
The ANSI standard ANSI X3.159-1989 "Programming Language C." specifies
that free(NULL) is a no op.
"free deallocates the space pointed to by p: it does nothing if p is NULL."
Quoted from "The C Programming Language" second edition by Kernighan and
Ritchie with the subtitle "ANSI C".

* free(NULL) ==> crash
This version is from March 1980. There was no Wine in sight at that time
and it even predates the PC and MS-DOS so I hope Wine dosn't have to
compile and run on this version ...
Source references:
- http://www.tliquest.net/unix/4BSD/Distributions/`

* free(NULL) == nop
This has seen the light in 1983 and predates Wine.
Source references:
- http://www.tliquest.net/unix/4BSD/Distributions/`

* free(NULL) == nop
Source references:
- http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/lib/libc/stdlib/malloc.c?rev=1.1&content-type=text/plain

* free(NULL) == nop
Source references:
- http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/stdlib/malloc.c?rev=1.1&content-type=text/plain

* free(NULL) == nop
Source references:
- http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/lib/libc/stdlib/malloc.c?rev=1.1&content-type=text/plain

Didn't check this one but it is a late addition to the BSD derivates so
it can be assumed they didn't break the standard.

Old libc-2.2.2 (seems to have been part of gcc before that):
* free(NULL) == nop
Source references:
- http://www.tsfr.org/~orc/Code/libc/
- http://oldlinux.org/Linux.old/libs/libc/

Glibc (older versions only as patches available)
* free(NULL) == nop
Source references:
- http://ftp.gnu.org/gnu/glibc/

Solaris 2.5 aka 5
* free(NULL) == nop
That's the oldest Solaris box I could get my hands on and compile and
run short free(NULL) test program.
According to Robert Lunnon modern Wine can be run on Solaris 9 and 10
and probably made compile on Solaris 8. Everything older dosn't work.
So Solaris is save too as according to Robert free(NULL) dosn't crash on
8,9 and 10 either.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20061009/e292b522/attachment.pgp

More information about the wine-patches mailing list