I finally made my dicitionary.c work. It works all ok. But there are some errors at the end, when checking with valgrind, although it says no memory leaks.
The error summary is:
ERROR SUMMARY: 143091 errors from 1 contexts (suppressed: 0 from 0)
The details are:
==3298== Invalid read of size 4
==3298== at 0x804939C: unload (dictionary.c:161)
==3298== by 0x8048DA4: main (speller.c:157)
==3298== Address 0x4c902b8 is 48 bytes inside a block of size 52 free'd
==3298== at 0x402B3D8: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3298== by 0x8049398: unload (dictionary.c:160)
==3298== by 0x8048DA4: main (speller.c:157)
The problem, as valgrind says is with unload function. But I don't know how to fix it. Here is my unload function (The first line is 149 and last line is 167):
bool unload(void)
{
// go through all of Table
for (int i = 0; i < TABLE_SIZE; i++)
{
if (Table[i] != NULL)
{
node* next = Table[i];
while (next != NULL)
{
node* temp = next;
free(next);
next = temp->next;
}
}
}
return true;
}
node*
, as node seems to be52
bytes in length, while whatever is in there is48
. This is also supported by the fact that readingtemp->next
(probably bytes 48-51 (4b)) is invalid.