我想在 C 中释放一个链表。一切正常,但 Valgrind 告诉我
Conditional jump or move depends on uninitialised value(s)
at 0x401400: mtf_destroy
这是代码:
list_elt *head;
void mtf_init() {
list_elt *current;
head = malloc(sizeof(list_elt));
current = head;
for (int i = 0; i < LIST_SIZE-1; i++) {
current->value = (BYTE) i;
current->next = malloc(sizeof(list_elt));
current = current->next;
}
current->value = LIST_SIZE-1;
}
void mtf_destroy(list_elt *elt) {
if (elt->next != NULL)
mtf_destroy(elt->next);
free(elt);
}
我该如何解决这个问题?谢谢!