0

I am done with the code but valgrind tells my I still leak memory in my unload-function. I already checked if the code is working, and it does. With help50 I get the information that I leak 56B bytes of memory because of this function. So maybe you can help me, what is probably obvious.

Thanks in advance.

const unsigned int N = 25;
node *table[N];

bool unload(void)

{
    node *cursor = malloc(sizeof(node));
        if (cursor == NULL)
        {
            free(cursor);
            printf("Cursor for unloading could not be allocated");
            return 1;
        }

    node *tmp = malloc(sizeof(node));
        if (tmp == NULL)
        {
            free(tmp);
            printf("Tmp for unloading could not be allocated");
            return 1;
        }


    for (int i = 0; i <= N; i++)
    {
        cursor = table[i];
        while (cursor != NULL)
        {
            tmp = cursor;
            cursor = cursor->next;
            free(tmp);
        }

    }
    free(cursor);
    free(tmp);


    return true;
}


1

You must log in to answer this question.

Browse other questions tagged .