I know that an invalid pointer leads to undefined behaviour but how does free know whether a pointer is valid or not?
Is there kind of a checksum at the beginning of each block in free list? something like:
if((*ptr) == 'CHECKSUM'))
free
else
do something undefined
malloc
.