This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/63698] New: std::set leaks nodes on assignement


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63698

            Bug ID: 63698
           Summary: std::set leaks nodes on assignement
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adl at lrde dot epita.fr

Compiling a project of mine with the latest gcc-snapshot distributed by Debian
(g++ (Debian 20141016-1) 5.0.0 20141016 (experimental) [trunk revision
216349]), I started to get memory leaks.

I reduced the problem to this small scenario:

% cat foo.cc
#include <set>

int main()
{
  std::set<int> v{2,1};   // The order of 2 and 1 is important.
  std::set<int> w{6,5,4};
  v = w;
  return v.size();
}
% g++ -std=c++11 foo.cc -g -Wall
% valgrind --leak-check=yes -q ./a.out
==30757== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==30757==    at 0x4C29180: operator new(unsigned long)
(vg_replace_malloc.c:324)
==30757==    by 0x40277D: __gnu_cxx::new_allocator<std::_Rb_tree_node<int>
>::allocate(unsigned long, void const*) (new_allocator.h:104)
==30757==    by 0x4026F8:
std::allocator_traits<std::allocator<std::_Rb_tree_node<int> >
>::allocate(std::allocator<std::_Rb_tree_node<int> >&, unsigned long)
(alloc_traits.h:360)
==30757==    by 0x402668: std::_Rb_tree<int, int, std::_Identity<int>,
std::less<int>, std::allocator<int> >::_M_get_node() (stl_tree.h:485)
==30757==    by 0x40238D: std::_Rb_tree_node<int>* std::_Rb_tree<int, int,
std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_create_node<int
const&>(int const&) (stl_tree.h:539)
==30757==    by 0x4021BE: std::_Rb_tree_node<int>* std::_Rb_tree<int, int,
std::_Identity<int>, std::less<int>, std::allocator<int>
>::_Alloc_node::operator()<int const&>(int const&) const (stl_tree.h:453)
==30757==    by 0x401D82: std::_Rb_tree_iterator<int> std::_Rb_tree<int, int,
std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_insert_<int
const&, std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>,
std::allocator<int> >::_Alloc_node>(std::_Rb_tree_node_base*,
std::_Rb_tree_node_base*, int const&, std::_Rb_tree<int, int,
std::_Identity<int>, std::less<int>, std::allocator<int> >::_Alloc_node&)
(stl_tree.h:1381)
==30757==    by 0x401324: std::_Rb_tree_iterator<int> std::_Rb_tree<int, int,
std::_Identity<int>, std::less<int>, std::allocator<int>
>::_M_insert_unique_<int const&, std::_Rb_tree<int, int, std::_Identity<int>,
std::less<int>, std::allocator<int>
>::_Alloc_node>(std::_Rb_tree_const_iterator<int>, int const&,
std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>,
std::allocator<int> >::_Alloc_node&) (stl_tree.h:1850)
==30757==    by 0x400EF3: void std::_Rb_tree<int, int, std::_Identity<int>,
std::less<int>, std::allocator<int> >::_M_insert_unique<int const*>(int const*,
int const*) (stl_tree.h:2096)
==30757==    by 0x400D0B: std::set<int, std::less<int>, std::allocator<int>
>::set(std::initializer_list<int>, std::less<int> const&, std::allocator<int>
const&) (stl_set.h:225)
==30757==    by 0x400A6A: main (foo.cc:5)


I suspect this is related to what was implemented for
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29988


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]