I've been on the speller problem for a while and I don't understand where i'm going wrong. Any help would be much appreciated. I'm getting the following error from valgrind when i run it alongside --log
(the --log
CL is used because if i just run valgrind, i am not shown any errors yet my code doesn't pass the check50);
==1460== HEAP SUMMARY:
==1460== in use at exit: 280 bytes in 5 blocks
==1460== total heap usage: 11 allocs, 6 frees, 6,564 bytes allocated
==1460==
==1460== 280 bytes in 5 blocks are still reachable in loss record 1 of 1
==1460== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1460== by 0x401226: load (dictionary.c:110)
==1460== by 0x400964: main (speller.c:40)
==1460==
==1460== LEAK SUMMARY:
==1460== definitely lost: 0 bytes in 0 blocks
==1460== indirectly lost: 0 bytes in 0 blocks
==1460== possibly lost: 0 bytes in 0 blocks
==1460== still reachable: 280 bytes in 5 blocks
==1460== suppressed: 0 bytes in 0 blocks
==1460==
==1460== For counts of detected and suppressed errors, rerun with: -v
==1460== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Also, my unload funtion is given below
// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
// loop through hash table
for (int i = 0; i < N; i++)
{
// No linked list at that address
if (table[i] == NULL)
{
break;
}
else
{
// Traverse node
node *n = table[i];
while (n->next != NULL)
{
//temporary node for freeing
node *tmp = n;
n = tmp->next;
free(tmp);
}
free(n);
table[i] = NULL; //optional
}
}
free(wordCount);
return true;
}
Thank you.