Shall we check pointer for NULL before calling free function?added on 2024/02/12 @ 16:46:22 | 5208 views| category: programming
The short answer is no. However, since this question keeps popping up on Reddit, Stack Overflow, and other websites, it's time to address the topic. There are a lot of interesting things to ponder over.
void free( void *ptr );
If ptr is a null pointer, the function does nothing.
So, there's no need to check the pointer before calling free.