1

我使用 g++ 来编译我的程序。在我执行程序的 80% 的时间里,我都会得到一个内存映射。我无法弄清楚内存映射的含义或如何解决它。这是输出:

*** glibc detected *** ./main: double free or corruption (!prev): 0x0881fdc8 ***
======= Backtrace: =========
[0x80da7f8]
[0x80dec69]
[0x80a5441]
[0x80a546d]
[0x8059227]
[0x8058b2f]
[0x8058f41]
[0x80567ec]
[0x80c075f]
[0x8048191]
======= Memory map: ========
00149000-0014a000 r-xp 00000000 00:00 0          [vdso]
08048000-08165000 r-xp 00000000 08:02 2101716    /home/armandmaree/Desktop/Projek_Fase2 (copy)/main
08166000-08168000 rw-p 0011d000 08:02 2101716    /home/armandmaree/Desktop/Projek_Fase2 (copy)/main
08168000-08170000 rw-p 00000000 00:00 0 
09a45000-09a67000 rw-p 00000000 00:00 0          [heap]
b7600000-b7621000 rw-p 00000000 00:00 0 
b7621000-b7700000 ---p 00000000 00:00 0 
b77e2000-b77e3000 rw-p 00000000 00:00 0 
bfc35000-bfc4a000 rw-p 00000000 00:00 0          [stack]
Aborted

如果您知道我如何找出问题所在,或者至少向我解释内存映射的含义,那就太好了。提前致谢。

4

1 回答 1

2

The memory map is telling you your process crashed. The [Backtrace:] part tells you the stack back trace (which function called which function) when the crash happened. The memory map is telling you what data is at what addresses in your process.

Like others suggested in comments, compile with -g and run your program under a debugger (gdb) to get better information. Since your crash is caused by heap corruption, using the valgrind tool will help because it specializes in that type of problem.

于 2013-05-02T16:57:20.700 回答