我正在使用Trie开发CS50 pset4拼写器。尽管卸载了字典(但没有segfault即可完成),但在卸载字典时,我无法运行valgrind()。
尽管当我给出一个小词典时valgrind()可以工作,但是当我使用默认的大词典时,valgrind()只是停止工作并且弹出没有连接的消息,我返回到仪表板。所以我尝试使用log标志运行check50,然后弹出此消息:
checking for valgrind errors...
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 77)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 152)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 144)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 114)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 105)
Conditional jump or move depends on uninitialised value(s): (file: dictionary.c, line: 166)
32 bytes in 1 blocks are still reachable in loss record 1 of 1
我知道最后一行并尝试对其进行修复,但是其他几行是什么。我正在按以下代码卸载。
bool func_unload(node *unloader)
{
node *temp = unloader;
for(int i = 0; i < N; i++)
{
temp = unloader;
if(unloader -> children[i] != NULL)
{
func_unload(unloader -> children[i]);
}
}
free(unloader);
unloader = temp;
return true;
}
// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
func_unload(root);
return true;
}