In C and C++, free(my_pointer) crashes when it is called twice.
Why? There is bookkeeping of every malloc along with the size. When the f
You say:
not understood why. there is bookkeeping of every malloc() along with the size.
Not necesarilly. I'll explain a bit about dlmalloc (used in glibc, uClibc, ...).
Dlmalloc tracks blocks of free space. There cannot be two contiguous free blocks, they are merged immediately. Allocated blocks are not tracked at all! Allocated blocks have some spare space for bookkeeping info (size of this block, size of the preceding block and some flags). When an allocated block is free()'d, dlmalloc inserts it into a doubly-linked list.
Of course, all of this is better explained at this dlmalloc article