0
votes

I have successfully written a code that can spell check from loading a dictionary. To free the memory, I have written the unload() function and valgrind shows no memory leaks. But after submission, I am getting some cryptic errors, i.e.

Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 137)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 143)

Below are my unload() function, valgrind screenshot and submit50 result respectively. Please help.

Thanks.

//unload function

bool unload(void)
{
    for (int i = 0; i < N; i++)
    {
        node* temp = table[i];
        node* cursor = temp;
        while (temp != NULL)
        {
            cursor = temp->next;
            free(temp);
            temp = cursor;
        }
        free(cursor);

    }
    return true;
}

//valgrind result

//submit50 result

1
Welcome to SO! A minimal reproducible example would be great. What's line 137? - ggorlen
What is table and how has it been initialized? What is node? Don't post pictures of text, post text as text. You can edit your question. Read this: How to Ask. - Jabberwocky
The error messages tell you where the uninitialized memory was created (line 101) and where is was accessed (lines 137 and 143). That should give you a good idea where to look. - M Oehm
free(cursor); is not needed in unload function. as you trying to free the null. As per official documentation, it should not cause issue but it depends on actual implementation, better remove that line. - SRIDHARAN

1 Answers

0
votes

It's because temp -> next is uninitialized for some cases.

You could make it the last node in each table bucket point to NULL.