gpt4 book ai didi

c - *** 错误 : double free or corruption (out): 0x00007fffe3465010 ***. 警告 : Corrupted shared library list: 0x7ffea4000920 ! = 0x7ffff7ffd9d8

转载 作者:太空宇宙 更新时间:2023-11-04 02:30:06 29 4
gpt4 key购买 nike

void *insert_rear_node(void *arg)
{
int *argument=(int *)arg;
int value=*argument;
//Assume that allocation is happening fine (Just like malloc , it is a custom heap allocator)

struct Node *head=(struct Node *) RTallocate(RTpointers, sizeof(struct Node));
struct Node *temp;
setf_init(temp,head);

while(value>0)
{
if(temp==NULL)
{
RTwrite_barrier(&(temp), new_node(value,NULL));
RTwrite_barrier(&(head),temp);
printf("Inserted %d into the list\n",head->data);
}
else
{
RTwrite_barrier(&(temp),head);
while(temp->next!=NULL)
{
RTwrite_barrier(&(temp),temp->next);
}
RTwrite_barrier(&(temp->next),new_node(value,NULL));
printf("Inserted %d into the list\n",temp->next->data);
}
value=value-1;

}
free(head);

}

int main(int argc, char *argv[])
{
long heap_size = (1L << 28);
long static_size = (1L << 26);
printf("heap_size is %ld\n", heap_size);
RTinit_heap(heap_size, static_size, 0);
pthread_t thread1;
int limit=1000;
RTpthread_create(&thread1,NULL,insert_rear_node,(void *)&limit);
}

假设 RTallocate 和 RTwrite_barrier 是 2 个工作正常的自定义函数。RTallocate - 在堆上分配内存RTwrite_barrier 相当于一个赋值语句。

这个程序简单地将节点插入到链表中。然后尝试删除头部。

I get this error:
Error in `/home/test/RT-Test/InMul': double free or corruption (out): 0x00007fffe3465010
warning: Corrupted shared library list: 0x7ffea4000920 != 0x7ffff7ffd9d8
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff77f97e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7ffff7801e0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7ffff780598c]
/home/test/RT-Test/InMul[0x400b98]
/lib/x86_64-linux-gnu/librtgc.so(rtalloc_start_thread+0x1ef)[0x7ffff7b4fa2c] /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7ffff756c6ba] /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7ffff788882d]


我只释放一次头部。为什么我会遇到这个问题?
0x00007fffe3465010是head的地址。

最佳答案

当您没有为 head 使用 malloc() 时,您不能使用 free()。使用与 RTallocate 等效的免费工具。

关于c - *** 错误 : double free or corruption (out): 0x00007fffe3465010 ***. 警告 : Corrupted shared library list: 0x7ffea4000920 ! = 0x7ffff7ffd9d8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574765/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com