How does the memory management unit (MMU) detect double pointer-free?
MMU is just a virtual address space β physical memory mapping, it does not know anything about how the heap is organized / how distribution works / ..., that is, a working system / allocator works.
How does the OS detect double free sweat? What is the mechanism?
He looks through the list / bitmap / ... of the selected blocks, sees that there is no allocated block with the address that you gave him, so he discovers that it is double free.
However, if this block is already redistributed, it finds it and correctly releases it =>, but now the code that used the redistributed block will go out, because the memory that it acquired correctly and that it doesnβt get free.
If the allocator protects unallocated memory, marking it as unreadable and not writing / deleting it from fixed pages of the virtual address space, the program will die as soon as this memory is accessed again (but the code that apparently caused the crash will be virtually innocent, because he did nothing wrong).
Otherwise, the application may work for some time until this block of memory is transferred to some other part of the code that would request some memory. At this point, two parts of the same application will try to work with the same memory block with all the unrest that may arise from this.
(Thanks to Pascal Cuoc for pointing out my mistake.)
source share