my speller code works very well with all texts but when i ran valgrind there was heap leak in load() specifically in new_node malloc can you help me figure out why? there is my code for load() and unload()
bool load(const char *dictionary)
{
FILE *dic = fopen(dictionary ,"r");
if ( dic != NULL)
{
while( fscanf(dic, "%s" , wordy ) != EOF)
{
node *new_node = malloc(sizeof (node));
if (new_node == NULL)
{
unload();
return false;
}
strcpy (new_node ->word , wordy);
//hashing
int index = hash(new_node -> word);
//inserting the new node in the link list
new_node ->next = hashtable[index];
hashtable[index] = new_node;
//count number of words
count ++;
}
fclose(dic);
return true;
}else
{
return false;
}
}
unload code
bool unload(void)
{
for( int i =0; i< HASH_MAX; i++)
{
***node *pointer = hashtable[i];***
while (pointer != NULL)
{
node *temp = pointer;
pointer = pointer->next;
free(temp);
}
free(pointer);
}
return true;
}