C++ 如何更正*** glibc 检测到*** 程序中的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6175538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:38:10  来源:igfitidea点击:

How to correct *** glibc detected *** error in the program

c++cgnu

提问by newars

Possible Duplicate:
glibc detected error

可能重复:
glibc 检测到错误

Hi, I was executing my project in GNU C++ when i received this error when i pressed an option in the switch case. As rest of the program is executing fine i am left with this error. I don't know what it is and why it occurs. Please explain and guide me as to where i may start to look in my program.

嗨,我正在 GNU C++ 中执行我的项目,当我在 switch case 中按下一个选项时收到此错误。由于程序的其余部分执行良好,我留下了这个错误。我不知道它是什么以及它为什么会发生。请解释并指导我从哪里开始查看我的程序。

Error Details:

错误详情:

*** glibc detected *** ./test.out: free(): invalid pointer: 0xbfb1c874 ***
======= Backtrace: =========
/lib/libc.so.6[0x55c0f1]
/lib/libc.so.6(cfree+0x90)[0x55fbc0]
./test.out[0x809f855]
./test.out[0x804fbc0]
./test.out[0x804f9bb]
./test.out[0x80502bb]
./test.out[0x805084e]
./test.out[0x8050d07]
/lib/libc.so.6(__libc_start_main+0xdc)[0x508e8c]
./test.out[0x8049981]
======= Memory map: ========
004f3000-00631000 r-xp 00000000 08:01 6148422    /lib/libc-2.5.so
00631000-00633000 r-xp 0013e000 08:01 6148422    /lib/libc-2.5.so
00633000-00634000 rwxp 00140000 08:01 6148422    /lib/libc-2.5.so
00634000-00637000 rwxp 00634000 00:00 0 
0078d000-007a7000 r-xp 00000000 08:01 6152013    /lib/ld-2.5.so
007a7000-007a8000 r-xp 00019000 08:01 6152013    /lib/ld-2.5.so
007a8000-007a9000 rwxp 0001a000 08:01 6152013    /lib/ld-2.5.so
007f9000-0081e000 r-xp 00000000 08:01 6148435    /lib/libm-2.5.so
0081e000-0081f000 r-xp 00024000 08:01 6148435    /lib/libm-2.5.so
0081f000-00820000 rwxp 00025000 08:01 6148435    /lib/libm-2.5.so
00b18000-00b23000 r-xp 00000000 08:01 6148439    /lib/libgcc_s-4.1.2-20080825.so.1
00b23000-00b24000 rwxp 0000a000 08:01 6148439    /lib/libgcc_s-4.1.2-20080825.so.1
08048000-080c6000 r-xp 00000000 00:1e 736543     /users/guest10/shashi/Demo/src/test.out
080c6000-080c7000 rwxp 0007e000 00:1e 736543     /users/guest10/shashi/Demo/src/test.out
080c7000-080cc000 rwxp 080c7000 00:00 0 
08d05000-218b1000 rwxp 08d05000 00:00 0          [heap]
b7e00000-b7e21000 rwxp b7e00000 00:00 0 
b7e21000-b7f00000 ---p b7e21000 00:00 0 
b7fab000-b7fac000 rwxp b7fab000 00:00 0 
b7fc4000-b7fc7000 rwxp b7fc4000 00:00 0 
b7fc7000-b7fc8000 r-xp b7fc7000 00:00 0          [vdso]
bfb0b000-bfb21000 rw-p bffe9000 00:00 0          [stack]
Abort

Please Help.. Thanks in Adv

请帮助..感谢Adv

回答by jdehaan

The exact solution can only be provided if you show us the code. The error is however clear. The code frees memory that is not or no longer valid. That means either the address is wrong, because for example of pointer arithmetic being done on the original pointer. Or the pointer has already been freed (double free).

只有向我们展示代码,才能提供确切的解决方案。但是错误很明显。该代码释放无效或不再有效的内存。这意味着地址要么是错误的,因为例如对原始指针进行了指针运算。或者指针已经被释放(double free)。

回答by Piotr Praszmo

You are most likely trying to freea memory that wasn't dynamically allocated. Maybe you have an unnecessary freeor a typo like: free(&buf)instead of free(buf).

您很可能正在尝试free使用未动态分配的内存。也许你有一个不必要的free或错字,比如:free(&buf)而不是free(buf).

Compile your program with -gflag and run it through debuggeror memory debugger. That will show you where the error exactly happens.

使用-g标志编译您的程序并通过调试器内存调试器运行它。这将向您显示错误发生的确切位置。

回答by Sriram

It looks like you are trying to freean invalid pointer. You can run the program with a memory check program like [Valgrind][1]like so:

它看起来像你想freeinvalid pointer。您可以使用内存检查程序运行该程序,如下[Valgrind][1]所示:

valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-reachable=yes --log-file=val.log ./<executable> <parameters>

Look at val.logand you should be able to figure out where your memory leaks occur. Also, you can try and step through the code with gdb/ddd (debuggers). The program will fail at the spot where the segmentation faultoccurs. To make the code debuggable, you will need to re-compile your code with the -gflag.

看一下val.log,您应该能够找出内存泄漏发生的位置。此外,您可以尝试使用gdb/ddd (debuggers). 该程序将在segmentation fault发生的地方失败。要制作代码debuggable,您需要使用-g标志重新编译您的代码。

Alternatively, you could post your code here and let the community see where you are going wrong.

或者,您可以在此处发布您的代码,让社区了解您哪里出错了。