您initDictionary不会在dictionary任何地方返回指针。
这意味着当你做
Dictionary* dictionary = initDictionary();
Run Code Online (Sandbox Code Playgroud)
的值dictionary将是不确定的(看似随机或垃圾),并且取消引用此指针或将其传递给free将导致未定义的行为。
你通过添加一个简单的来解决这个问题
return dictionary;
Run Code Online (Sandbox Code Playgroud)
在initDictionary函数的最后。
如果您的编译器没有警告您不要从函数返回任何内容,您需要启用更详细的警告。在构建时使用gcc或clang我推荐的选项-Wall -Wextra -Wpedantic。对于 MSVC 使用/W4.