gpt4 book ai didi

c - *** 检测到 glibc *** ./a.out : double free or corruption (top): 0x08901d70 *** while attempting to free a BST

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:09 25 4
gpt4 key购买 nike

我确实知道有一些“检测到 glibc”的帖子,但如果您能为此提出解决方案,我将不胜感激:

*** glibc detected *** ./a.out: double free or corruption (top): 0x08901d70 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c501)[0x17c501]
/lib/libc.so.6(+0x6dd70)[0x17dd70]
/lib/libc.so.6(cfree+0x6d)[0x180e5d]
/lib/libc.so.6(fclose+0x14a)[0x16c81a]
./a.out[0x8048998]
/lib/libpthread.so.0(+0x5cc9)[0xc1fcc9]
/lib/libc.so.6(clone+0x5e)[0x1e069e]
======= Memory map: ========

这似乎发生在我尝试释放二叉搜索树时:

void freetree(BNODEPTR *root)
{
if(root!=NULL)
{
freetree(root->left);
freetree(root->right);
free(root);
}
}

结构类型定义为 BNODEPTR

struct bnode{
int info;
int count;
struct bnode* left;
struct bnode* right;
};

我正在使用 freetree(root) 从 main() 调用函数。

这棵树似乎被正确地实现了,因为中序遍历产生了一个排序的输出。

完整代码在:

http://pastebin.com/Eieu3xDa

http://pastebin.com/jtGN6XKj

最佳答案

我可以筛选您的源代码,但正如他们所说,“喂人鱼...”

  1. 使用调试符号编译您的代码(将 -g 传递给编译器)。如果这样做,您可以获得一个函数名称,而不是回溯中的 ./a.out[0x8048998]

  2. 使用 Valgrind 的 memcheck 工具(默认工具)运行您的代码。这可能会让您更好地了解错误所在。对于初学者,您可以只安装 Valgrind 并运行 valgrind ./a.out

特别是,我认为整个二叉树是一条红鲱鱼。您的程序在其他地方还有另一个问题。从回溯中,我可以看到 (1) freetree 中未触发错误消息,以及 (2) 您正在使用容易被滥用的线程。

关于c - *** 检测到 glibc *** ./a.out : double free or corruption (top): 0x08901d70 *** while attempting to free a BST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876087/

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