Why exactly should I not call free() on variables not allocated by malloc()?

前端 未结 7 605
我寻月下人不归
我寻月下人不归 2020-12-01 17:32

I read somewhere that it is disastrous to use free to get rid of an object not created by calling malloc, is this true? why?

相关标签:
7条回答
  • 2020-12-01 18:02

    It is undefined behaviour. And logically, if behaviour is undefined, you cannot be sure what has happened, and if the program is still operating properly.

    0 讨论(0)
提交回复
热议问题