문제

#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;

I have the struct and then i free like this

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);
        }
}

How i can check that its free or not beacuse i dont know the functionfree that i made it right or not.

sorry about my english

Thank you.

도움이 되었습니까?

해결책

To check whether an address is free or not it is enough to check the address equals to NULL.

linkedList == NULL

since you are using free(linkedList) it should be okay.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top