2

I am using a boost::ptr_vector to contain a list of class objects.

I add the objects to the ptr_vector in this way:

parent_ptrvector.push_back(new PlanVertex(-1,-1,-1));

I only add objects once, when the class containing the ptr_vector is initialized.

I never copy the vector.

I do not add or remove objects from the vector, but I do call a setCoords function on elements in the ptr_vector in this way:

parent_ptrvector.at(i).setCoords(1,2,3);

My problem is that I seem to get a segmentation fault intermittently when the class containing the ptr_vector is destructed. It seem that the fault is more likely to occur when I have called setCoords on many different elements during a run.

The message I receive is:

munmap_chunk(): invalid pointer: 0x00007fff50016f20 ***

Thank you very much for any help, I have pasted the gdb backtrace below:

#0  0x00007ffff5d6f425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff5d72b8b in __GI_abort () at abort.c:91
#2  0x00007ffff5dad39e in __libc_message (do_abort=2, fmt=0x7ffff5eb7748 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3  0x00007ffff5db7b96 in malloc_printerr (action=3, str=0x7ffff5eb7838 "munmap_chunk(): invalid pointer", ptr=<optimized out>) at malloc.c:5039
#4  0x00000000004cbf8d in void boost::checked_delete<PlanVertex const>(PlanVertex const*) ()
#5  0x00000000004cbf55 in void boost::delete_clone<PlanVertex>(PlanVertex const*) ()
#6  0x00000000004cbf35 in void boost::heap_clone_allocator::deallocate_clone<PlanVertex>(PlanVertex const*) ()
#7  0x00000000004cbf15 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_clone_allocator<false>::deallocate_clone(PlanVertex const*) ()
#8  0x00000000004cbeb5 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_policy_deallocate_clone(PlanVertex const*) ()
#9  0x00000000004cbe69 in void boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove<boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex> >(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>) ()
#10 0x00000000004cbd1b in void boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove<boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex> >(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>, boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>) ()
#11 0x00000000004cbcbb in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove_all() ()
#12 0x00000000004cbc38 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::~reversible_ptr_container() ()
#13 0x00000000004cbc15 in boost::ptr_sequence_adapter<PlanVertex, std::vector<void*, std::allocator<void*> >, boost::heap_clone_allocator>::~ptr_sequence_adapter() ()
#14 0x00000000004cbbf5 in boost::ptr_vector<PlanVertex, boost::heap_clone_allocator, std::allocator<void*> >::~ptr_vector() ()
#15 0x00000000004cbbd5 in boost::ptr_vector<PlanVertex, boost::heap_clone_allocator, std::allocator<void*> >::~ptr_vector() ()
#16 0x00000000004cb8ec in PathPlanData::~PathPlanData() ()
#17 0x00000000004cb825 in PathPlanData::~PathPlanData() ()
  • 1
    Use valgrind. Valgrind is your friend. – n. m. could be an AI Sep 20 '14 at 16:35
  • Thank you very much! You were right, I thought I had already run valgrind but that was on an earlier build. It turned out that I was doing an illegal read/write on a different container stored in the same class. The seg fault reported the last container deleted in the destructor. – John LeTurt Sep 21 '14 at 00:57

0 Answers0