释放后检查结构体是否释放

标签 c data-structures struct linked-list free

#include <stdio.h>
typedef struct _person
{
    char name[64];
    char gender[2];
    struct _person * pNext;
    struct _person * pPartner;
} PERSON_T;

typedef struct
{
    PERSON_T * head;
    PERSON_T * tail;
    PERSON_T * current;
} LIST_T;

我有了结构,然后我就这样自由了

void freestruct(LIST_T *linkedList)
{
    linkedList->current = linkedList->head;
    if (linkedList != NULL) /* if list has been initialized  */
        {
        PERSON_T * pThisItem = linkedList->head;
        while (pThisItem != NULL)
            {
            PERSON_T * pNext = pThisItem->pNext;
            free(pThisItem);
            pThisItem = pNext;
            }
        free(linkedList);
        }
}

我如何检查它是否免费,因为我不知道我做的是否正确。

对不起我的英语

谢谢。

最佳答案

要检查地址是否空闲,只需检查地址是否为 NULL。

linkedList == NULL

由于您使用的是 free(linkedList) ,所以应该没问题。

关于释放后检查结构体是否释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21324592/

相关文章:

c - Malloc 实现 - 困惑

c - Gradle native c plugin : Add directory with . h/.lib files to look for while compile

database - 帮我把这些数据结构变成数据库表

c++ - 将 vector (在结构中定义时)传递给函数

C 无 EOF 信号

在 C 中动态分配的数组上调用 free() 似乎正在更改存储在另一个数组中的数据?

python - 关于在 Python 中选择数据结构的建议

performance - 为超大数据选择数据结构

ios - 从 json 中提取问题

perl - 在使用 ("Server1"时不能使用字符串 "strict refs") 作为 SCALAR ref