Glibc detected : free(): invalid pointer: with simple boost::ptr_map example?

Tutorial: boost.org/doc/libs/1_39_0/libs/ptr_conta... (found by googling for: boost ptr_map ).

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

I know there are scores of questions with "* glibc detected * free(): invalid pointer", but the following is a minimalist example with boost::ptr_map: #include #include int main() { boost::ptr_map map; int one = 1; int* pone = &one; string un = "one"; map. Insert(un, pone); } The code compiles, but at run time: boost. Library/ptr_container $ .

/run. Ptrmap *** glibc detected *** . /run.

Ptrmap: free(): invalid pointer: 0x00007ffffd5c4578 *** ======= Backtrace: ========= /lib/URL1.60x7fd5e99202f6 /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6(cfree+0x6c)0x7fd5e9924c6c . /run. Ptrmap0x401066 /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6(__libc_start_main+0xfd)0x7fd5e98c8abd .

/run. Ptrmap0x400e79 ======= Memory map: ======== etc.. It's been repeated throughout SO that this kind of error is caused when trying to delete an invalid pointer. However, what changes in the above very simple code would avert this error?

The background of this question is that I am struggling to understand the proper usage of boost::ptr_map. Unfortunately, the official boost documentation is very sparse as far as ptr_map is concerned (no tutorial, no example with ptr_map). No boost::ptr_map tutorial seem to exist on the web.

I have problems retrieving values, and accessing methods to the mapped classes I created. Thus, I tried to create the simplest example I could, but got off on a bad start as evidenced above. Any help with the glibc error above and with ptr_map in general is appreciated.

Thanks. Edit: I have read over 20 times, studied and copied the examples from the official boost tutorial http://www.boost.org/doc/libs/1_46_0/libs/ptr_container/doc/tutorial.html As stated above, the boost tutorial barely covers ptr_map, so linking to it won't make any bit of difference. Basically, I have gone through and through the whole boost ptr container manual many times.

Glibc boost-ptr-container link|improve this question edited Apr 28 '11 at 10:21 asked Apr 28 '11 at 10:00augustin1,2171324 90% accept rate.

Tutorial: boost.org/doc/libs/1_39_0/libs/ptr_conta... (found by googling for: boost ptr_map) ptr_map takes ownership of the pointers it's given, therefore it needs to be given heap allocated (new) objects. You've given it a pointer to a stack-allocated object, so when the ptr_map is cleaned up it tries to delete something that is on the stack.

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