https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120834
Bug ID: 120834 Summary: Potential memory leak during exception handling Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dorian.haglund at gmail dot com Target Milestone: --- Running the following code with valgrind reports an error: ```cpp struct throwing_dtor_t { ~throwing_dtor_t() noexcept(false) { throw 123; } }; int main() { try { try { throw throwing_dtor_t{}; } catch (throwing_dtor_t const &) { } } catch (int) { } return 0; } ``` ```bash ~ $ 0 valgrind --leak-check=full ./a.out ==143975== Memcheck, a memory error detector ==143975== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==143975== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==143975== Command: ./a.out ==143975== ==143975== ==143975== HEAP SUMMARY: ==143975== in use at exit: 129 bytes in 1 blocks ==143975== total heap usage: 3 allocs, 2 frees, 73,989 bytes allocated ==143975== ==143975== 129 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==143975== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==143975== by 0x492CD4B: __cxa_allocate_exception (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33) ==143975== by 0x1091DE: main (in /home/dorian/a.out) ==143975== ==143975== LEAK SUMMARY: ==143975== definitely lost: 129 bytes in 1 blocks ==143975== indirectly lost: 0 bytes in 0 blocks ==143975== possibly lost: 0 bytes in 0 blocks ==143975== still reachable: 0 bytes in 0 blocks ==143975== suppressed: 0 bytes in 0 blocks ==143975== ==143975== For lists of detected and suppressed errors, rerun with: -s ==143975== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) ``` A leak also appear if you turn both asan and ubsan on (but not only asan) System: ```bash ~ $ 0 uname -a Linux dorian-XPS-15-9510 6.11.0-26-generic #26~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 17 19:20:47 UTC 2 x86_64 x86_64 x86_64 GNU/Linux ```