Opened 6 years ago

Closed 6 years ago

#12296 closed Bugs (fixed)

boost::container::{deque,string} combine for a memory leak

Reported by: Tavian Barnes <tavianator@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

The following program leaks memory, according to valgrind. Switching either deque or string (or both) to the std:: implementation does not show the leak, so I'm not sure which container has the bug (though I suspect it's deque).

$ cat foo.cpp
#include <boost/container/deque.hpp>
#include <boost/container/string.hpp>
#include <deque>
#include <string>

using boost::container::deque;
using boost::container::string;
// using std::deque;
// using std::string;

int main() {
  deque<string> foo;
  foo.push_back("------------------------");
  foo.push_back("------------------------");
  foo.erase(foo.begin(), foo.begin() + 1);
  return 0;
}
$ g++ -std=c++11 -g -Wall foo.cpp && valgrind --leak-check=full ./a.out
==29864== Memcheck, a memory error detector
==29864== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==29864== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==29864== Command: ./a.out
==29864== 
==29864== 
==29864== HEAP SUMMARY:
==29864==     in use at exit: 72,752 bytes in 2 blocks
==29864==   total heap usage: 5 allocs, 3 frees, 73,368 bytes allocated
==29864== 
==29864== 48 bytes in 1 blocks are definitely lost in loss record 1 of 2
==29864==    at 0x4C2B0D8: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==29864==    by 0x405A12: boost::container::new_allocator<char>::allocate(unsigned long) (new_allocator.hpp:145)
==29864==    by 0x405047: boost::container::container_detail::allocator_version_traits<boost::container::new_allocator<char>, 1u>::allocation_command(boost::container::new_allocator<char>&, unsigned int, unsigned long, unsigned long&, char*&) (allocator_version_traits.hpp:142)
==29864==    by 0x404647: boost::container::container_detail::basic_string_base<boost::container::new_allocator<char> >::allocation_command(unsigned int, unsigned long, unsigned long&, char*&) (string.hpp:276)
==29864==    by 0x403823: boost::container::basic_string<char, std::char_traits<char>, boost::container::new_allocator<char> >::priv_reserve(unsigned long, bool) (string.hpp:2494)
==29864==    by 0x40250B: boost::container::basic_string<char, std::char_traits<char>, boost::container::new_allocator<char> >::reserve(unsigned long) (string.hpp:1088)
==29864==    by 0x401922: boost::container::basic_string<char, std::char_traits<char>, boost::container::new_allocator<char> >::assign(char const*, char const*) (string.hpp:1401)
==29864==    by 0x4011C9: boost::container::basic_string<char, std::char_traits<char>, boost::container::new_allocator<char> >::basic_string(char const*) (string.hpp:707)
==29864==    by 0x400D84: main (foo.cpp:13)
==29864== 
==29864== LEAK SUMMARY:
==29864==    definitely lost: 48 bytes in 1 blocks
==29864==    indirectly lost: 0 bytes in 0 blocks
==29864==      possibly lost: 0 bytes in 0 blocks
==29864==    still reachable: 72,704 bytes in 1 blocks
==29864==         suppressed: 0 bytes in 0 blocks
==29864== Reachable blocks (those to which a pointer was found) are not shown.
==29864== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==29864== 
==29864== For counts of detected and suppressed errors, rerun with: -v
==29864== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

(Ignore the "still reachable" blocks; those are from libstdc++ itself.)

Change History (1)

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

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.