The programme compiles fine but when i run help50 for leaks i get the following, though i have freed the children. i appreciate the help:
==11548== For counts of detected and suppressed errors, rerun with: -v
==11548== ERROR SUMMARY: 29 errors from 4 contexts (suppressed: 0 from 0)
Helping with...
==11548== 82,217,184 (107,744 direct, 82,109,440 indirect) bytes in 481
blocks are definitely lost in loss record 3 of 3
==11548== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11548== by 0x401053: gnew_node (dictionary.c:32)
==11548== by 0x4011C3: load (dictionary.c:82)
==11548== by 0x4008CD: main (speller.c:40)
Looks like your program leaked 82,217,184 bytes of memory. Did you forget to
free memory that you allocated via malloc? Take a closer look
at line 32 of dictionary.c.
my gnew_node is:
struct node*gnew_node(void)
{
children=(struct node*)malloc(sizeof(struct node));
if(children)
children->is_word=false;
for(int i=0;i<27;i++)
children->next_char[i]=NULL;
return children;
}
this is how i used it in load:
if(!trav->next_char[INDEX])
{
trav->next_char[INDEX]=gnew_node();
}
trav=trav->next_char[INDEX];
}
my unload:
bool unload(void)
{
// TODO
struct node* Pnode;
for(int k=0;k<27;k++)
{
Pnode=children;
if(Pnode->next_char[k]!=NULL)
free(children->next_char[k]);
}
free(children);
for(int k=0;k<27;k++)
{
Pnode=root_ptr;
if(Pnode->next_char[k]!=NULL)
free(Pnode->next_char[k]);
}
free(root_ptr);
return true;
}
this my full code https://pastebin.com/XicAwNuK