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

标签 c pointers linked-list free double-free

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/

相关文章:

arrays - Bash 间接引用关联数组

c - 如何停止读取输入并分析C中的数据

c# - 查找特定子文件夹

c++ - 作为类成员管理指针 vector

c - 在 C 中实现无输入大小的链表

java - 在 Java 中声明一个 LinkedList

c++ - deleteNode 函数出现中断连接列表

ios - C/XCode : sh: ./child : No such file or directory. 命令在终端中运行,但不在 XCode 中运行

将 uint64_t 转换为 FILETIME

c++ - 检查指针是否指向数组