0

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

prbiswas
  • 3
  • 1
  • 2
    Welcome to SO! A [mcve] would be great. What's line 137? – ggorlen May 06 '20 at 05:33
  • 1
    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: [ask]. – Jabberwocky May 06 '20 at 05:41
  • 2
    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 May 06 '20 at 06:13
  • 1
    https://stackoverflow.com/questions/2612447/pinpointing-conditional-jump-or-move-depends-on-uninitialized-values-valgrin Refer this. – SRIDHARAN May 06 '20 at 07:05
  • 1
    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 May 06 '20 at 07:06
  • And sorry, what's in your program in lines 137 and 143? If you post just a snippet, the valgrind message is useless... please, post a [minimal, reproducible **and complete example**](https://stackoverflow.com/help/minimal-reproducible-example) in order for us to be able to get the same information you get at your place. A complete example is one that can be tested **without having to add, delete or change anything** to the example. – Luis Colorado May 06 '20 at 09:29

1 Answers1

0

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

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

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53