Re: Memory Leak in Kpathsea

Jonathan Gruber <[email protected]> Tue, 16 Jun 2026 18:04:31 -0700
Newsgroups gmane.comp.tex.live
Message-ID <CAGKpfjp_WmgdP--xGsz9iA9kUjkO99uwqKt6oLea_rNCuVRxmQ@mail.gmail.com>
That calling free upon a null pointer is a no-op seems to go as far
back as C89 (the first standardized version of C), at least according
to https://port70.net/~nsz/c/c89/c89-draft.html#4.10.3.2, which I got
to from https://cppreference.com/c/links. If I know my C history
correctly, prior to standardization, the authoritative reference to
the language was effectively the first edition of the book The C
Programming Language. I don't have a copy, but from electronic copies
that I was able to find obtain online (completely legally, of course
:) ), calling free upon a null pointer was also a no-op then.


On Tue, Jun 16, 2026 at 2:26=E2=80=AFPM Patrice Dumas <[email protected]> wr=
ote:
>
> On Tue, Jun 16, 2026 at 02:50:29PM -0600, Karl Berry wrote:
> >     calling free upon a null pointer is a no-op.
> >
> > So far as I know, that is not guaranteed. Maybe some standard says so
> > today, but in practice, at least in the past, free(NULL) could cause an
> > abort. I don't remember the systems; maybe they are all gone by
> > now. --best, karl.
>
> It is in POSIX 2001
> https://pubs.opengroup.org/onlinepubs/009695399/functions/free.html
> "If ptr is a null pointer, no action shall occur.".  I think that it is
> pretty normal nowadays to call free on a NULL pointer, as the platforms
> that aborted are probably long gone now, as you say.
>
> --
> Pat