[英]Valgrind detects memory leak, can't find it C
Your initDictionary
doesn't return the pointer dictionary
anywhere.您的
initDictionary
不会在任何地方返回指针dictionary
。
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 . dictionary
的值将是不确定的(看似随机或垃圾),并且取消引用此指针或将其传递给free
将导致未定义的行为。
You solve this by adding a simple你通过添加一个简单的来解决这个问题
return dictionary;
at the end of the initDictionary
function.在
initDictionary
函数的末尾。
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.使用
gcc
或clang
我建议在-Wall -Wextra -Wpedantic
时使用选项-Wall -Wextra -Wpedantic
。 For MSVC use /W4
.对于 MSVC 使用
/W4
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.