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

前端 未结 5 665
无人共我
无人共我 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 17:54

    That check won't check if the variable is freed. Note that free(pointer) does not set that pointer to NULL. If you want that to be the case, you have to set it yourself, and it is a common idiom in C:

    free(pointer);
    pointer = NULL;
    

    to signal that you already freed that pointer.

提交回复
热议问题