Is free(NULL) OK?

Joel Sherrill joel at rtems.org
Sun Jan 12 06:56:09 UTC 2025


POSIX says free(NULL) is valid and no action.

https://pubs.opengroup.org/onlinepubs/009695399/functions/free.html

--joel

On Sun, Jan 12, 2025, 12:46 AM Hal Murray via devel <devel at ntpsec.org>
wrote:

>
> The Linux man page says
>        If ptr is NULL, no operation is performed.
>
> I'd expect a wrapper if there really was a problem.
>
> This code is in ntpd/ntp_config.c
>         if (NULL == s) {                        /* free() hates NULL */
>                 s = estrdup("");
>         }
>
> Any reason not to nuke that chunk of code?
>
>
> --
> These are my opinions.  I hate spam.
>
>
>
> _______________________________________________
> devel mailing list
> devel at ntpsec.org
> https://lists.ntpsec.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/devel/attachments/20250112/d5239146/attachment.htm>


More information about the devel mailing list