[Bug c++/91184] New: memory leak with enable_shared_from_this and pthread
adl at gnu dot org
gcc-bugzilla@gcc.gnu.org
Tue Jul 16 20:12:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91184
Bug ID: 91184
Summary: memory leak with enable_shared_from_this and pthread
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: adl at gnu dot org
Target Milestone: ---
Created attachment 46604
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46604&action=edit
preprocessed source
% gcc --version
gcc (Debian 20190706-1) 10.0.0 20190706 (experimental) [trunk revision 273162]
This is the gcc-snapshot package from Debian, running on amd64. Since this
update, I have been observing memory leaks when enable_shared_from_this is used
with -pthread.
% cat foo.cc
#include <memory>
struct foo: std::enable_shared_from_this<foo>
{
~foo() { }
};
int main()
{
std::make_shared<foo>();
}
% g++ -W -Wall -g -o foo foo.cc -pthread
% valgrind -q --leak-check=yes ./foo
==27467== 32 bytes in 1 blocks are definitely lost in loss record 1 of 1
==27467== at 0x4835DEF: operator new(unsigned long)
(vg_replace_malloc.c:334)
==27467== by 0x401C59:
__gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<foo, std::allocator<foo>,
(__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*)
(new_allocator.h:111)
==27467== by 0x401AB0:
std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<foo,
std::allocator<foo>, (__gnu_cxx::_Lock_policy)2> >
>::allocate(std::allocator<std::_Sp_counted_ptr_inplace<foo,
std::allocator<foo>, (__gnu_cxx::_Lock_policy)2> >&, unsigned long)
(alloc_traits.h:444)
==27467== by 0x40189B:
std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<foo,
std::allocator<foo>, (__gnu_cxx::_Lock_policy)2> > >
std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<foo,
std::allocator<foo>, (__gnu_cxx::_Lock_policy)2> >
>(std::allocator<std::_Sp_counted_ptr_inplace<foo, std::allocator<foo>,
(__gnu_cxx::_Lock_policy)2> >&) (allocated_ptr.h:97)
==27467== by 0x40172C:
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<foo,
std::allocator<foo>>(foo*&, std::_Sp_alloc_shared_tag<std::allocator<foo> >)
(shared_ptr_base.h:677)
==27467== by 0x401691: std::__shared_ptr<foo,
(__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<foo>>(std::_Sp_alloc_shared_tag<std::allocator<foo>
>) (shared_ptr_base.h:1368)
==27467== by 0x40162A:
std::shared_ptr<foo>::shared_ptr<std::allocator<foo>>(std::_Sp_alloc_shared_tag<std::allocator<foo>
>) (shared_ptr.h:408)
==27467== by 0x401425: std::shared_ptr<foo> std::allocate_shared<foo,
std::allocator<foo>>(std::allocator<foo> const&) (shared_ptr.h:844)
==27467== by 0x401344: std::shared_ptr<foo> std::make_shared<foo>()
(shared_ptr.h:860)
==27467== by 0x4011C2: main (foo.cc:10)
==27467==
Removing the std::enable_shared_from_this<foo> inheritance, or the -pthread
option makes the leak disappear.
More information about the Gcc-bugs
mailing list