Is free() zeroing out memory?

后端 未结 7 1574
庸人自扰
庸人自扰 2020-12-03 06:24

Until today I lived in belief that calling free() on memory space releases it for further allocation without any other modifications. Especially, considering th

7条回答
  •  孤城傲影
    2020-12-03 07:04

    is there a better explanation?

    There is. Dereferencing a pointer after it has been free()d results in undefined behavior, so the implementation has the permission to do anything it pleases, including the act of tricking you into believing that the memory region has been filled with zeroes.

提交回复
热议问题