If the returned pointer is equal to NULL then this means that the memory was not allocated.
From the description of the function calloc
(C11 Standard)
3 The calloc function returns either a null pointer or a pointer to
the allocated space.
You may call free
for a null-pointer though this does not have an effect.
On the other hand, you may require a memory of zero size. In this case if the returned pointer is not equal to NULL you have to call free
to free the allocated memory.
Here is a demonstrative program
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int *p = calloc( 0, sizeof( int ) );
if ( p != NULL )
{
printf( "p = %p\n", ( void * )p );
}
free( p );
return 0;
}
Using an inline compiler its output
p = 0x55efd9c81260
That is though the required size of memory is equal to 0 nevertheless the system allocated memory that needs to be freed.