Opened 8 years ago

Closed 6 years ago

#10696 closed Bugs (fixed)

boost::container::flat_map copy constructor appears to leak

Reported by: dave@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

The following sandbox.cpp program:

#include <boost/container/flat_map.hpp>

int main(int argc, char** argv)
{
    boost::container::flat_map<int, int> myMap;
    boost::container::flat_map<int, int> myCopiedMap(myMap);

    return 0;
}

causes valgrind 3.9.0 to produce the following:

$ valgrind --tool=memcheck --leak-check=full --show-reachable=no --undef-value-errors=no --track-origins=no --child-silent-after-fork=yes --trace-children=no ./sandbox 
==12648== Memcheck, a memory error detector
==12648== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==12648== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==12648== Command: ./sandbox
==12648== 
==12648== 
==12648== HEAP SUMMARY:
==12648==     in use at exit: 3,287 bytes in 86 blocks
==12648==   total heap usage: 122 allocs, 36 frees, 56,978 bytes allocated
==12648== 
==12648== 0 bytes in 1 blocks are definitely lost in loss record 1 of 86
==12648==    at 0x4C27965: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==12648==    by 0x40410F: __gnu_cxx::new_allocator<boost::container::container_detail::pair<int, int> >::allocate(unsigned long, void const*) (new_allocator.h:104)
==12648==    by 0x40400B: boost::container::container_detail::allocator_version_traits<std::allocator<boost::container::container_detail::pair<int, int> >, 1u>::allocation_command(std::allocator<boost::container::container_detail::pair<int, int> >&, int, unsigned long, unsigned long, unsigned long&, boost::container::container_detail::pair<int, int>* const&) (allocator_version_traits.hpp:144)
==12648==    by 0x403F0D: boost::container::container_detail::vector_alloc_holder<std::allocator<boost::container::container_detail::pair<int, int> >, boost::container::container_detail::integral_constant<unsigned int, 1u> >::allocation_command(int, unsigned long, unsigned long, unsigned long&, boost::container::container_detail::pair<int, int>* const&) (vector.hpp:395)
==12648==    by 0x403D72: boost::container::container_detail::vector_alloc_holder<std::allocator<boost::container::container_detail::pair<int, int> >, boost::container::container_detail::integral_constant<unsigned int, 1u> >::vector_alloc_holder<std::allocator<boost::container::container_detail::pair<int, int> > const&>(std::allocator<boost::container::container_detail::pair<int, int> > const&, unsigned long) (vector.hpp:350)
==12648==    by 0x403BF2: boost::container::vector<boost::container::container_detail::pair<int, int>, std::allocator<boost::container::container_detail::pair<int, int> > >::vector(boost::container::vector<boost::container::container_detail::pair<int, int>, std::allocator<boost::container::container_detail::pair<int, int> > > const&) (vector.hpp:732)
==12648==    by 0x403B34: boost::container::container_detail::flat_tree<int, boost::container::container_detail::pair<int, int>, boost::container::container_detail::select1st<boost::container::container_detail::pair<int, int> >, std::less<int>, std::allocator<boost::container::container_detail::pair<int, int> > >::Data::Data(boost::container::container_detail::flat_tree<int, boost::container::container_detail::pair<int, int>, boost::container::container_detail::select1st<boost::container::container_detail::pair<int, int> >, std::less<int>, std::allocator<boost::container::container_detail::pair<int, int> > >::Data const&) (flat_tree.hpp:119)
==12648==    by 0x403A42: boost::container::container_detail::flat_tree<int, boost::container::container_detail::pair<int, int>, boost::container::container_detail::select1st<boost::container::container_detail::pair<int, int> >, std::less<int>, std::allocator<boost::container::container_detail::pair<int, int> > >::flat_tree(boost::container::container_detail::flat_tree<int, boost::container::container_detail::pair<int, int>, boost::container::container_detail::select1st<boost::container::container_detail::pair<int, int> >, std::less<int>, std::allocator<boost::container::container_detail::pair<int, int> > > const&) (flat_tree.hpp:207)
==12648==    by 0x40399A: boost::container::flat_map<int, int, std::less<int>, std::allocator<std::pair<int, int> > >::flat_map(boost::container::flat_map<int, int, std::less<int>, std::allocator<std::pair<int, int> > > const&) (flat_map.hpp:209)
==12648==    by 0x4037BE: main (sandbox.cpp:6)
==12648== 
==12648== LEAK SUMMARY:
==12648==    definitely lost: 0 bytes in 1 blocks
==12648==    indirectly lost: 0 bytes in 0 blocks
==12648==      possibly lost: 0 bytes in 0 blocks
==12648==    still reachable: 3,287 bytes in 85 blocks
==12648==         suppressed: 0 bytes in 0 blocks
==12648== Reachable blocks (those to which a pointer was found) are not shown.
==12648== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==12648== 
==12648== For counts of detected and suppressed errors, rerun with: -v
==12648== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Change History (3)

comment:1 by viboes, 8 years ago

Component: Nonecontainer
Owner: set to Ion Gaztañaga

comment:2 by Ion Gaztañaga, 8 years ago

I can't see the problem in current versions. And your example does not seem to allocate any memory (you create empty maps).

comment:3 by Ion Gaztañaga, 6 years ago

Resolution: fixed
Status: newclosed

An modified example allocating memory does not show any leak in the copy constructor in recent versions, so closing this bug as fixed.

Note: See TracTickets for help on using tickets.