Your initDictionary
doesn’t return the pointer dictionary
anywhere.
That means when you do
Dictionary* dictionary = initDictionary();
the value of dictionary
will be indeterminate (seemingly random or garbage), and dereferencing this pointer or passing it to free
will result in undefined behavior.
You solve this by adding a simple
return dictionary;
at the end of the initDictionary
function.
If your compiler doesn’t warn you about not returning anything from the function, you need to enable more verbose warnings. Using gcc
or clang
I recommend the options -Wall -Wextra -Wpedantic
when building. For MSVC use /W4
.
solved Valgrind detects memory leak, can’t find it C