Opened 9 years ago
Closed 9 years ago
#9185 closed Bugs (duplicate)
boost::container::vector leaks memory
Reported by: | TeXitoi | Owned by: | Ion Gaztañaga |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
boost::container::vector may leak memory with allocation of size 0. For example, on Debian with libboost1.54-dev 1.54.0-2, with this program:
#include <boost/container/vector.hpp> int main() { using namespace boost::container; vector<int> v1; vector<int> v2(v1); return 0; }
I have
$ valgrind --leak-check=full ./test ==15591== Memcheck, a memory error detector ==15591== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==15591== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==15591== Command: ./test ==15591== ==15591== ==15591== HEAP SUMMARY: ==15591== in use at exit: 0 bytes in 1 blocks ==15591== total heap usage: 1 allocs, 0 frees, 0 bytes allocated ==15591== ==15591== 0 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==15591== at 0x4C298F9: operator new(unsigned long) (vg_replace_malloc.c:298) ==15591== by 0x4017F6: __gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*) (new_allocator.h:104) ==15591== by 0x4015FC: boost::container::container_detail::allocator_version_traits<std::allocator<int>, 1u>::allocation_command(std::allocator<int>&, int, unsigned long, unsigned long, unsigned long&, int* const&) (allocator_version_traits.hpp:144) ==15591== by 0x401542: boost::container::container_detail::vector_alloc_holder<std::allocator<int>, boost::container::container_detail::integral_constant<unsigned int, 1u> >::allocation_command(int, unsigned long, unsigned long, unsigned long&, int* const&) (vector.hpp:395) ==15591== by 0x401474: boost::container::container_detail::vector_alloc_holder<std::allocator<int>, boost::container::container_detail::integral_constant<unsigned int, 1u> >::vector_alloc_holder<std::allocator<int> >(std::allocator<int> const&, unsigned long) (vector.hpp:350) ==15591== by 0x401104: boost::container::container_detail::vector_alloc_holder<std::allocator<int>, boost::container::container_detail::integral_constant<unsigned int, 1u> >::vector_alloc_holder<std::allocator<int> >(std::allocator<int> const&, unsigned long) (vector.hpp:351) ==15591== by 0x401007: boost::container::vector<int, std::allocator<int> >::vector(boost::container::vector<int, std::allocator<int> > const&) (vector.hpp:732) ==15591== by 0x400F6C: boost::container::vector<int, std::allocator<int> >::vector(boost::container::vector<int, std::allocator<int> > const&) (vector.hpp:737) ==15591== by 0x400EBB: main (test.cpp:10) ==15591== ==15591== LEAK SUMMARY: ==15591== definitely lost: 0 bytes in 1 blocks ==15591== indirectly lost: 0 bytes in 0 blocks ==15591== possibly lost: 0 bytes in 0 blocks ==15591== still reachable: 0 bytes in 0 blocks ==15591== suppressed: 0 bytes in 0 blocks ==15591== ==15591== For counts of detected and suppressed errors, rerun with: -v ==15591== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
I suspect that
~vector_alloc_holder() BOOST_CONTAINER_NOEXCEPT { if(this->m_capacity){ this->alloc().deallocate(this->m_start, this->m_capacity); } }
should be
~vector_alloc_holder() BOOST_CONTAINER_NOEXCEPT { if(this->m_start){ this->alloc().deallocate(this->m_start, this->m_capacity); } }
(not tested).
Note:
See TracTickets
for help on using tickets.
Thanks for the report, it's a duplicate of #9166 which is fixed on trunk and release branches for Boost 1.55.