Free NULL Pointer

Possible duplicate:
Is there any free (ptr) where ptr is NULL corrupted memory?
Is it good practice to free NULL pointer in C?

I have a question regarding freeing a null pointer.

char *p = NULL; free(p); 

Can free(NULL) cause a crash?

Or does it depend on the compiler?

-2
source share
1 answer

From the free man page

 void free(void *ptr); 

The free () function frees the memory allocation pointed to by PTR. If ptr is a NULL pointer, the operation is not performed.

If you want to receive confirmation directly from the C manual

A free function forces the space indicated by ptr to be freed, i.e. available for further distribution. If ptr is a null pointer, no action occurs.

See page 313 of this document.

+3
source

All Articles