id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 13500,Memory leak when using erase on string vectors,anonymous,Ion Gaztañaga,"Consider the following example: {{{ #include #include int main() { boost::container::vector myVec; // myVec.push_back(""Short string""); myVec.push_back(""This is a long string that exceeds a certain threshold (23 in my case)""); myVec.erase(myVec.begin()); return 0; } }}} When running this example and pushing back the long string, valgrind reports a memory leak (see attached file). When using the short string, there is no leak. I assume this has to do with the boost short string optimization, which puts shorter strings into a buffer living in stack instead of allocating a buffer on the heap. Also, when I do not erase(..) the element but let the vector destructor clean up the memory, there is no leak. Looking at the implementation of vector's erase(..): {{{ //! Effects: Erases the element at position pos. //! //! Throws: Nothing. //! //! Complexity: Linear to the elements between pos and the //! last element. Constant if pos is the last element. iterator erase(const_iterator position) { BOOST_ASSERT(this->priv_in_range(position)); const pointer p = vector_iterator_get_ptr(position); T *const pos_ptr = boost::movelib::to_raw_pointer(p); T *const beg_ptr = this->priv_raw_begin(); T *const new_end_ptr = ::boost::container::move(pos_ptr + 1, beg_ptr + this->m_holder.m_size, pos_ptr); //Move elements forward and destroy last this->priv_destroy_last(pos_ptr == new_end_ptr); return iterator(p); } }}} I think the condition passed as argument to priv_destroy_last(const bool moved) has to be negated? pos_ptr == new_end_ptr is fulfilled if ::boost::container::move has NOT moved anything.",Bugs,closed,To Be Determined,container,Boost 1.58.0,Problem,fixed,,