The GNU manual page for malloc
defines that when free()
called twice with the same pointer (that was previously allocated by malloc()
)
"Undefined behavior" simply means that the implementation isn't required to deal with the situation in any particular way; any behavior or result is considered "correct".
The result of free
-ing a pointer more than once is up to the underlying implementation of malloc
; the result could be a crash and core dump, or it could corrupt the malloc
arena (fouling up future allocations/deallocations), or it could ignore the double free
entirely.