【发布时间】:2022-01-11 07:21:19
【问题描述】:
这是我的卸载函数:
for (int i = 0; i < N; i++)
{
//line 116
while (table[i] != NULL)
{
node *tmp = table[i]->next;
free(table[i]);
table[i] = tmp;
}
return true;
}
check50 说我的代码正在泄漏内存。
这就是我的 malloc
while(fscanf(file, "%s", word) != EOF)
{
node *newNode = malloc(sizeof(node));
Help50 Valgrind 说: ==166== 条件跳转或移动取决于未初始化的值
看起来您正在尝试使用可能没有值的变量?仔细看看dictionary.c的第116行。
【问题讨论】:
-
它说在哪里?还有其他信息吗?
-
你是如何为这个表分配内存的?
-
一般写成
while table[i] != NULL) { node *tmp = table[i]; table[i] = table[i]->next; free (tmp); } -
如果 check50 说它正在泄漏内存,请务必自己运行 valgrind 以获取更多详细信息。