checking for NULL before calling free

前端 未结 8 641
终归单人心
终归单人心 2020-12-03 13:45

Many C code freeing pointers calls:

if (p)
  free(p);

But why? I thought C standard say the free function doesn\'t do anything

8条回答
  •  攒了一身酷
    2020-12-03 14:06

    If you rely on that free(0) is OKAY, and it's normal for your pointer to be null at this point, please say so in comment // may be NULL

    This may be merely self-explanatory code, saying yes I know, I also use p as a flag.

提交回复
热议问题