Subject: [Boost-bugs] [Boost C++ Libraries] #9185: boost::container::vector leaks memory
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-10-01 13:00:12
#9185: boost::container::vector leaks memory
------------------------------+------------------------
Reporter: TeXitoi | Owner: igaztanaga
Type: Bugs | Status: new
Milestone: To Be Determined | Component: container
Version: Boost 1.54.0 | Severity: Problem
Keywords: |
------------------------------+------------------------
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).
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9185> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC