我正在尝试消除以下程序中的内存泄漏
int main (int argc, char **argv) {
node_ref head = NULL;
for (int argi = 0; argi < 5; ++argi) {
node_ref node = malloc (sizeof (struct node));
assert (node != NULL);
node->word = argv[argi];
node->link = head;
head = node;
}
for (node_ref curr = head; curr->link != NULL; curr = curr->link) {
printf ("%p->node {word=%p->[%s], link=%p}\n",
curr, curr->word, curr->word, curr->link);
}
while(head != NULL){
struct node* temp;
temp = head;
head++;
free(temp);
}
return 9;
}
然而,当我运行 valgrind 时,它会因内存泄漏而发疯,这里知道我做错了什么吗?