【发布时间】:2016-04-21 22:21:40
【问题描述】:
我在尝试运行此程序时收到此错误:
* 检测到 glibc * ./a.out: double free or corruption (fasttop): 0x0000000001926070 ***
我试图在 C 中创建我自己的 pop 函数,它给了我上面的错误。我不确定我哪里出错了。
struct node *pop(struct node *top, int *i)
{
struct node *new_node = top;
int count = 0;
if ( new_node == NULL) {
return top;
}
while ( new_node != NULL && (count < 1)) {
*i = new_node->value;
free(new_node);
new_node = new_node->next;
count++;
}
return new_node;
}
【问题讨论】:
-
你从哪里得到错误?你从调试器中得到什么?你试图找出自己的什么?
-
1) 需要更新调用方
top。 2)free(new_node); new_node = new_node->next;:发布后请勿使用。
标签: c linked-list runtime-error glibc