Is free() zeroing out memory?

后端 未结 7 1548
庸人自扰
庸人自扰 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:16

    free() does not zero memory as a general rule. It simply releases it for re-used by a future call to malloc(). Certain implementations may fill the memory with known values but that is purely an implementation detail of the library.

    Microsoft's runtime makes good use of marking freed and allocated memory with useful values (see In Visual Studio C++, what are the memory allocation representations? for more information). I have also seen it filled with values that when executed would cause a well-defined trap.

提交回复
热议问题