Should one really set pointers to `NULL` after freeing them?

前端 未结 10 1061
庸人自扰
庸人自扰 2020-11-28 03:27

There seem to be two arguments why one should set a pointer to NULL after freeing them.

Avoid crashing when double-freeing pointers.

Short

10条回答
  •  渐次进展
    2020-11-28 03:38

    There's no guarantee that the program crashes when accessing the NULL pointer.

    Maybe not by the standard, but you'd be hard-pressed to find an implementation which does not define it as an illegal operation that causes a crash or exception (as appropriate to the runtime environment).

提交回复
热议问题