If I use malloc() to allocate myself a block of memory, assign NULL to a memory address which is within but not at the end of this block, and then call free() on this block, will I be successful in freeing the entire block, or only the part of the block up to NULL? In other words, does free() rely on NULL-termination to identify the end of a memory block, or is there some other internal method?
I am aware that this question only really applies to memory allocated for pointers (when NULL actually means something other than all bits zero.)
For example:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char **myBlock = malloc(20 * sizeof(char *));
myBlock[10] = NULL;
free(myBlock);
return 0;
}
Will this code free 10 * sizeof(char *)
or 20 * sizeof(char *)
?
Many thanks in advance!