错误消息glibc检测到Malloc():内存损坏(快)

时间:2015-03-17 08:53:08

标签: c++ vector malloc glibc

我最近遇到了这个错误。奇怪的是,我并不总是得到这个错误信息......

*** glibc detected *** ./a.out: malloc(): memory corruption (fast): 0x0000000002134dc0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x76a16)[0x7fa62b164a16]
/lib/x86_64-linux-gnu/libc.so.6(+0x7a2f8)[0x7fa62b1682f8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x70)[0x7fa62b1698a0]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x1d)[0x7fa62b97607d]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs4_Rep9_S_createEmmRKSaIcE+0x59)[0x7fa62b9d1999]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs4_Rep8_M_cloneERKSaIcEm+0x28)[0x7fa62b9d2708]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs7reserveEm+0x30)[0x7fa62b9d27f0]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs6appendEPKcm+0xb5)[0x7fa62b9d2ab5]
./a.out[0x40758f]
./a.out[0x403279]
./a.out[0x405202]
./a.out[0x406332]
./a.out[0x406c90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7fa62b10cead]
./a.out[0x402189]
======= Memory map: ========
00400000-0040e000 r-xp 00000000 08:05 6166978                            /root/tradingbot/bot2/a.out
0060d000-0060e000 rw-p 0000d000 08:05 6166978                            /root/tradingbot/bot2/a.out
02132000-02153000 rw-p 00000000 00:00 0                                  [heap]
7fa624000000-7fa624021000 rw-p 00000000 00:00 0 
7fa624021000-7fa628000000 ---p 00000000 00:00 0 
7fa62b0ee000-7fa62b270000 r-xp 00000000 08:05 12715768                   /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b270000-7fa62b470000 ---p 00182000 08:05 12715768                   /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b470000-7fa62b474000 r--p 00182000 08:05 12715768                   /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b474000-7fa62b475000 rw-p 00186000 08:05 12715768                   /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b475000-7fa62b47a000 rw-p 00000000 00:00 0 
7fa62b47a000-7fa62b48f000 r-xp 00000000 08:05 12715492                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b48f000-7fa62b68f000 ---p 00015000 08:05 12715492                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b68f000-7fa62b690000 rw-p 00015000 08:05 12715492                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b690000-7fa62b711000 r-xp 00000000 08:05 12715766                   /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b711000-7fa62b910000 ---p 00081000 08:05 12715766                   /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b910000-7fa62b911000 r--p 00080000 08:05 12715766                   /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b911000-7fa62b912000 rw-p 00081000 08:05 12715766                   /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b912000-7fa62b9fa000 r-xp 00000000 08:05 7345862                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62b9fa000-7fa62bbfa000 ---p 000e8000 08:05 7345862                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bbfa000-7fa62bc02000 r--p 000e8000 08:05 7345862                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bc02000-7fa62bc04000 rw-p 000f0000 08:05 7345862                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bc04000-7fa62bc19000 rw-p 00000000 00:00 0 
7fa62bc19000-7fa62bc39000 r-xp 00000000 08:05 12715773                   /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be10000-7fa62be15000 rw-p 00000000 00:00 0 
7fa62be35000-7fa62be38000 rw-p 00000000 00:00 0 
7fa62be38000-7fa62be39000 r--p 0001f000 08:05 12715773                   /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be39000-7fa62be3a000 rw-p 00020000 08:05 12715773                   /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be3a000-7fa62be3b000 rw-p 00000000 00:00 0 
7fffb0149000-7fffb016a000 rw-p 00000000 00:00 0                          [stack]
7fffb019f000-7fffb01a1000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

这就是我在做的事情......

我正在动态创建类的n个对象并将它们存储在向量(C ++)中。然后使用迭代器访问每个对象,并使用它来访问对象的成员。我也在阅读一些文本文件,因此在运行时手动编辑它们。我不知道我应该把这部分代码放在这里,但这就是它完全崩溃的地方:

if( last_op_number == 1 ){

    it = n_bots.end();// Grabs iterator and go to the end of the vector; This is where the last OP1 bot is located
    bot *botop1 = &(*it); // Dereference iterator to have a pointer to that specific bot

    /* 3) Set the real buy and sell prices */
    botop1->real_bpsp(price_ex1,price_ex2);
}

// Clear text files
OKC->clear_pos();
OKC2->clear_pos();
updates_balance(); // Updates balances

green_light = 1; // Tell bot manager that we are good to go!

有关正在发生的事情的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

您应该使用n_bots.back()代替n_bots.end()