Freeing NULL Pointers Should Be A Harmless Noop

I see that Blender’s “guardedalloc” memory-management system treats a call to MEM_freeN with a NULL pointer as a programming error. This leads to a lot of places in the code where a pointer first has to be checked that it is not NULL before disposing of it.

I would say this is contrary to established programming practice. For example, the standard POSIX/C free(3) call explicitly allows the passing of a NULL pointer, whereupon “no operation is performed”.

This is also the semantics of the C++ delete statement.

I think that changing MEM_freeN to behave the same way would allow a lot of simplification of code throughout Blender. And less code means less chance for bugs to get in!

1 Like