Function free() in C isn't working for me

前端 未结 5 674
无人共我
无人共我 2020-12-18 17:25

I have been trying to free memory allocated via malloc() using free().

Some of the structs it does free but leaves some the way they were a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 18:06

    The function free takes a pointer to allocated memory, it does not however set that pointer to NULL, in fact there is no way it could do so (it would need to take the address of a pointer for that).

    Typical use case in this scenario is:

    free(myptr);
    myptr = NULL;
    

提交回复
热议问题