I am almost done with CS50 (working on the final project now) but one PSET of mine is incomplete. I can get it to compile and run, but Valgrind is not happy. Here's a snipped of the most relevant code and valgrind summary. Here's the full thing: https://pastebin.com/VH0ejUXM
bool load(const char *dictionary)
{
root = malloc(sizeof(node));
if(root == NULL)
return false;
for(int i = 0; i < 26; i++)
{
root->letter[i] = NULL;
}
root->isword = false;
FILE* fp = fopen(dictionary, "r");
// check for an unsuccessful open
if (fp == NULL)
return false;
// set a buffer to store an output word of length = LENGTH + 1 for null terminator
char curline[LENGTH+2];
// loop through the dictionary until a null character
while (fgets(curline, sizeof(curline), fp))
{
char c = '\0';
curline[strlen(curline)-1] = c;
insert(curline);
wordcount++;
}
fclose(fp);
return true;
}
bool unload(void)
{
node *ptr = root;
byebye(ptr);
return true;
}
void byebye(node *delnode)
{
node *ptr = delnode;
for(int i = 0; i < 27; i++)
if(ptr->letter[i] != NULL)
byebye(ptr->letter[i]);
free(delnode);
}
==1859== LEAK SUMMARY:
==1859== definitely lost: 0 bytes in 0 blocks
==1859== indirectly lost: 0 bytes in 0 blocks
==1859== possibly lost: 0 bytes in 0 blocks
==1859== still reachable: 78,291,032 bytes in 349,512 blocks
==1859== suppressed: 0 bytes in 0 blocks
==1859== Reachable blocks (those to which a pointer was found) are not shown.
==1859== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==1859==
==1859== For counts of detected and suppressed errors, rerun with: -v
==1859== ERROR SUMMARY: 349491 errors from 3 contexts (suppressed: 0 from 0)
Thank you!