开发者

"glibc detected - free(): invalid pointer - Program received signal SIGABRT, Aborted"

Here's a minimal code that puzzles me :

#include <list>

class A;

class A {
private:
    std::list<A*> a_list;
//  int a_list;
public:
    A() : a_list() {}
};

int main() {
    A* a_tab = new A[1];
//  A* a_tab = new A();

    delete a_tab;

    return 0;
}

At execution, I got :

*** glibc detected *** ./main: free(): invalid pointer: 0x0000000000f6d018 ***
======= Backtrace: =========
/lib/libc.so.6(+0x774b6)[0x7f706f2914b6]
/lib/libc.so.6(cfree+0x73)[0x7f706f297c83]
./main[0x4007d2]
/lib/libc.so.6(__libc_start_main+0xfe)[0x7f706f238d8e]
./main[0x400649]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:03 108600                             /DELL/Users/Lucas/Desktop/Lifebeam/minimal/main
00601000-00602000 r--p 00001000 08:03 108600                             /DELL/Users/Lucas/Desktop/Lifebeam/minimal/main
00602000-00603000 rw-p 00002000 08:03 108600                             /DELL/Users/Lucas/Desktop/Lifebeam/minimal/main
00f6d000-00f8e000 rw-p 00000000 00:00 0                                  [heap]
7f7068000000-7f7068021000 rw-p 00000000 00:00 0 
7f7068021000-7f706c000000 ---p 00000000 00:00 0 
7f706f21a000-7f706f394000 r-xp 00000000 08:07 400996                     /lib/libc-2.12.1.so
7f706f394000-7f706f593000 ---p 0017a000 08:07 400996                     /lib/libc-2.12.1.so
7f706f593000-7f706f597000 r--p 00179000 08:07 400996                     /lib/libc-2.12.1.so
7f706f597000-7f706f598000 rw-p 0017d000 08:07 400996                     /lib/libc-2.12.1.so
7f706f598000-7f706f59d000 rw-p 00000000 00:00 0 
7f706f59d000-7f706f5b2000 r-xp 00000000 08:07 391760                     /lib/libgcc_s.so.1
7f706f5b2000-7f706f7b1000 ---p 00015000 08:07 391760                     /lib/libgcc_s.so.1
7f706f7b1000-7f706f7b2000 r--p 00014000 08:07 391760                     /lib/libgcc_s.so.1
7f706f7b2000-7f706f7b3000 rw-p 00015000 08:07 391760                     /lib/libgcc_s.so.1
7f706f7b3000-7f706f835000 r-xp 00000000 08:07 401151                     /lib/libm-2.12.1.so
7f706f835000-7f706fa34000 ---p 00082000 08:07 401151                     /lib/libm-2.12.1.so
7f706fa34000-7f706fa35000 r--p 00081000 08:07 401151                     /lib/libm-2.12.1.so
7f706fa35000-7f706fa36000 rw-p 00082000 08:07 401151                     /lib/libm-2.12.1.so
7f706fa36000-7f706fb1e000 r-xp 00000000 08:07 1048147                    /usr/lib/libstdc++.so.6.0.14
7f706fb1e000-7f706fd1d000 ---p 000e8000 08:07 1048147                    /usr/lib/libstdc++.so.6.0.14
7f706fd1d000-7f706fd25000 r--p 000e7000 08:07 1048147                    /usr/lib/libstdc++.so.6.0.14
7f706fd25000-7f706fd27000 rw-p 000ef000 08:07 1048147                    /usr/lib/libstdc++.so.6.0.14
7f706fd27000-7f706fd3c000 rw-p 00000000 00:00 0 
7f706fd3c000-7f706fd5c000 r-xp 00000000 08:07 401152                     /lib/ld-2.12.1.so
7f706ff3b000-7f706ff40000 rw-p 00000000 00:00 0 
7f706ff5a000-7f706ff5c000 rw-p 00000000 00:00 0 
7f706ff5c000-7f706ff5d000 r--p 00020000 08:07 401152                     /lib/ld-2.12.1.so
7f706ff5d000-7f706ff5e000 rw-p 00021000 08:07 401152                     /lib/ld-2.12.1.so
7f706ff5e000-7f706ff5f000 rw-p 00000000 00:00 0 
7fffdf34a000-7fffdf36b000 rw-p 00000000 00:00 0                          [stack]
7fffdf3da000-7fffdf3db000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Abandon

There are two commented lines : they are both (independently) an alternative that work fine to the line that precede them.

Do you have an开发者_如何转开发y clue why it behaves this way ?

I compile with g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5.


You use wrong deletion. You have allocated an array of one element using operator new[], but you delete as a single object using operator delete. Use delete[] a_tab; instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜