Std::list causes “glibc detected - free(): invalid pointer - Program received signal SIGABRT, Aborted?

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.

Up vote 1 down vote favorite share g+ share fb share tw.

Here's a minimal code that puzzles me : #include class A; class A { private: std::list a_list; // int a_list; public: A() : a_list() {} }; int main() { A* a_tab = new A1; // 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" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6(+0x774b6)0x7f706f2914b6 /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6(cfree+0x73)0x7f706f297c83 . /main0x4007d2 /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6(__libc_start_main+0xfe)0x7f706f238d8e .

/main0x400649 ======= 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-11.1. '11.1. So 7f706f394000-7f706f593000 ---p 0017a000 08:07 400996 /lib/libc-11.1. '11.1. So 7f706f593000-7f706f597000 r--p 00179000 08:07 400996 /lib/libc-11.1. '11.1. So 7f706f597000-7f706f598000 rw-p 0017d000 08:07 400996 /lib/libc-11.1. '11.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-11.1. '11.1. So 7f706f835000-7f706fa34000 ---p 00082000 08:07 401151 /lib/libm-11.1. '11.1. So 7f706fa34000-7f706fa35000 r--p 00081000 08:07 401151 /lib/libm-11.1. '11.1. So 7f706fa35000-7f706fa36000 rw-p 00082000 08:07 401151 /lib/libm-11.1. '11.1. So 7f706fa36000-7f706fb1e000 r-xp 00000000 08:11.1. 27 '117 /usr/lib/libstdc++.so.6.0.14 7f706fb1e000-7f706fd1d000 ---p 000e8000 08:11.1. 27 '117 /usr/lib/libstdc++.so.6.0.14 7f706fd1d000-7f706fd25000 r--p 000e7000 08:11.1. 27 '117 /usr/lib/libstdc++.so.6.0.14 7f706fd25000-7f706fd27000 rw-p 000ef000 08:11.1. 27 '117 /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-11.1. '11.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-11.1. '11.1. So 7f706ff5d000-7f706ff5e000 rw-p 00021000 08:07 401152 /lib/ld-11.1. '11.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 any clue why it behaves this way? I compile with g++ (Ubuntu/Linaro 11.1. 11.1.ubuntu5) 11.1..

C++ arrays stl free link|improve this question edited 11.1. at 11:22Juraj Blaho3,078317 asked 11.1. at 10:55Lucas Georges Francis1113.

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.

Or allocate using A* a_tab = new A; @Lucas: Always pair new with delete, new with delete. – David Hammen Jul 27 '11 at 11:32 Thanks, it worked fine. Silly error.

– Lucas Georges Francis Oct 4 '11 at 23:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions