> Not that long ago we saw a lot of commits related to null checks being
> not needed before free() calls.

[...]

> So how should I interpret this in relation to the above commit messages?
> 
>  1) double free is safe, no need for null checks
>  2) double free is detected by OpenBSD, no need for null checks we will
>  kill your program
>  3) double free is unsafe, avoid double free
> 
> I would like to think that (2) is true. Though reading the man page
> makes an initial impression (at least for me) that (3) is true and could
> lead to people following the rule of null checking before a free call?
> 
> Should the man page be altered to discouraged the use of null checks
> before calls to free?

I am not sure I can understand the state of confusion you are in to ask
such a question.

The act of freeing a pointer, whichever value it has, will not change
the value of the pointer variable. It will not magically become NULL
after your first call to free().

Double free() are never safe, and some of them are caught by OpenBSD's
malloc, but not all of them. But free(NULL) is actually a no-op because
nothing has been allocated, so you can call free(NULL) as many times as
you want.

Miod

Reply via email to