malloc double free behaviour

前端 未结 5 724
甜味超标
甜味超标 2020-12-21 14:19

The GNU manual page for malloc defines that when free() called twice with the same pointer (that was previously allocated by malloc())

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-21 14:32

    "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.

提交回复
热议问题