So I used a trie to implement speller, and when I run valgrind on my speller.c, it says that around my unload() function and my freeTrie() function I am accessing 8 bytes of memory that isn't mine. I was wondering if you guys had any thoughts on this. Thanks!

bool load(const char *dictionary)

    // open the dictionary

    FILE* dictionary1 = fopen(dictionary, "r");
    <<<snipped code here>>>


    return true;

1 Answer 1


Why are you freeing new_node inside the load function? All of your nodes will be freed in unload so by freeing the last new node in load, unload hits memory that is no longer yours.

  • That was very helpful, thank you! When I ran valgrind after editing that part, however, it says that in my load() function that this statement: "if (current -> children[index] == NULL)" is trying to use a variable that might not have a value. I'm not sure what that means or how my code is wrong. Dec 31, 2018 at 23:44
  • That's a separate issue. malloc gives you garbage memory, so if you try to test it, valgrind will warn you. You should either initialize every node after you malloc a new one, or use calloc instead (which does that for you).
    – curiouskiwi
    Dec 31, 2018 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .