so I have been straggling pset5 for some time and I end up getting double free or corruptionand don't now how to fix it. Here's my code :
/* inside load() */
// some code
if(head->children[b] == NULL)
{
node* n ;
n = (node *)malloc(sizeof(node));
for(int i = 0; i < 27; i++)
n->children[i] = NULL;
n->is_word=false;
head->children[b] = n;
head = n;
free(n);
}
// some code
bool unload(void)
{
freenode(root);
return true;
}
void freenode(node *n)
{
for(int i = 0; i < 27; i++)
{
if(n->children[i] != NULL)
freenode(n->children[i]);
else
break;
}
if(n != NULL)
free(n);
}
Here's valgrind :
WORDS MISSPELLED: 7052
WORDS IN DICTIONARY: 143091
WORDS IN TEXT: 19190
TIME IN load: 3.49
TIME IN check: 0.19
TIME IN size: 0.00
TIME IN unload: 0.00
TIME IN TOTAL: 3.69
==3086==
==3086== HEAP SUMMARY:
==3086== in use at exit: 0 bytes in 0 blocks
==3086== total heap usage: 367,084 allocs, 367,260 frees, 82,227,504 bytes allocated
==3086==
==3086== All heap blocks were freed -- no leaks are possible
==3086==
==3086== For counts of detected and suppressed errors, rerun with: -v
==3086== ERROR SUMMARY: 2559314 errors from 15 contexts (suppressed: 0 from 0)