https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123378
Bug ID: 123378
Summary: Memory leak in std::barrier with gcc-16
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: stuart.a.hayhurst at gmail dot com
Target Milestone: ---
Created attachment 63205
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63205&action=edit
Reproducer
While checking the status of some other bugs with g++-16, I noticed a whole set
of memory leaks reported by ASan concerning std::barrier.
The reproducer is pretty simple, creating and destroying a std::barrier seems
to leak some memory with g++-16, but not g++-15.
I'm using a build from the 14th of December 2025 since that's what was
available in Debian Experimental, apologies if it's already fixed.
Reproducer attached, compiling with `g++-16 -std=c++23 test.cpp` and running
with valgrind:
```
==3516== Memcheck, a memory error detector
==3516== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3516== Using Valgrind-3.25.1 and LibVEX; rerun with -h for copyright info
==3516== Command: ./a.out
==3516==
==3516==
==3516== HEAP SUMMARY:
==3516== in use at exit: 512 bytes in 1 blocks
==3516== total heap usage: 3 allocs, 2 frees, 74,272 bytes allocated
==3516==
==3516== 512 bytes in 1 blocks are definitely lost in loss record 1 of 1
==3516== at 0x484FC15: operator new[](unsigned long, std::align_val_t)
(vg_replace_malloc.c:789)
==3516== by 0x400150F:
std::__detail::_MakeUniq<std::__tree_barrier_base::__state_t []>::__array
std::make_unique<std::__tree_barrier_base::__state_t []>(unsigned long) (in
/home/stuart/Downloads/a.out)
==3516== by 0x4001428: std::__tree_barrier_base::_M_alloc_state() (in
/home/stuart/Downloads/a.out)
==3516== by 0x4001313: std::__tree_barrier_base::__tree_barrier_base(long)
(in /home/stuart/Downloads/a.out)
==3516== by 0x40016A0:
std::__tree_barrier<std::__empty_completion>::__tree_barrier(long,
std::__empty_completion) (in /home/stuart/Downloads/a.out)
==3516== by 0x4001596: std::barrier<std::__empty_completion>::barrier(long,
std::__empty_completion) (in /home/stuart/Downloads/a.out)
==3516== by 0x40011C5: main (in /home/stuart/Downloads/a.out)
==3516==
==3516== LEAK SUMMARY:
==3516== definitely lost: 512 bytes in 1 blocks
==3516== indirectly lost: 0 bytes in 0 blocks
==3516== possibly lost: 0 bytes in 0 blocks
==3516== still reachable: 0 bytes in 0 blocks
==3516== suppressed: 0 bytes in 0 blocks
==3516==
==3516== For lists of detected and suppressed errors, rerun with: -s
==3516== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```