Catch::LeakDetector::~LeakDetector can throw bad_alloc - destructors should not throw
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
The Catch::LeakDetector::~LeakDetector can throw bad_alloc, which is a violation implicit noexcept qualifier on destructors.
**Expected behavior**
Destructors should not throw exceptions.
**Reproduction steps**
Instrument global new/delete.
Fail the allocation in:
```
namespace {
static auto getSingletons() -> std::vector*& {
static std::vector* g_singletons = nullptr;
if( !g_singletons )
g_singletons = new std::vector();
return g_singletons;
}
}
```
**Platform information:**
Windows 11, build 25290.1001.amd64fre.rs_onecore_liof1.230129-1700
**Additional context**
Call stack
```
1b 00000048`f02ff260 00007ff7`9d54245c VCRUNTIME140D!CxxThrowException+0x120
1c 00000048`f02ff2f0 00007ff7`9d3f9dca unit_tests!operator new+0x3c [E:\ebpf-for-windows\libs\platform\user\ebpf_platform_user.cpp @ 458]
1d 00000048`f02ff340 00007ff7`9d3f9c0b unit_tests!Catch::`anonymous namespace'::getSingletons+0x1a [E:\ebpf-for-windows\external\Catch2\src\catch2\internal\catch_singletons.cpp @ 18]
1e 00000048`f02ff380 00007ff7`9d3f824b unit_tests!Catch::cleanupSingletons+0xb [E:\ebpf-for-windows\external\Catch2\src\catch2\internal\catch_singletons.cpp @ 29]
1f 00000048`f02ff400 00007ff7`9d6f6ecf unit_tests!Catch::cleanUp+0xb [E:\ebpf-for-windows\external\Catch2\src\catch2\catch_registry_hub.cpp @ 97]
20 00000048`f02ff430 00007ff7`9d7ac002 unit_tests!Catch::LeakDetector::~LeakDetector+0xf [E:\ebpf-for-windows\external\Catch2\src\catch2\internal\catch_leak_detector.cpp @ 37]
21 00000048`f02ff460 00007ffc`c5492c21 unit_tests!Catch::`dynamic atexit destructor for 'leakDetector''+0x12
22 00000048`f02ff490 00007ffc`c54923f5 ucrtbased!::operator()+0x131 [minkernel\crts\ucrt\src\appcrt\startup\onexit.cpp @ 206]
23 00000048`f02ff520 00007ffc`c5492547 ucrtbased!__crt_seh_guarded_call::operator()<, &, >+0x35 [VCCRT\vcruntime\inc\internal_shared.h @ 204]
24 00000048`f02ff560 00007ffc`c5492e34 ucrtbased!__acrt_lock_and_call< >+0x57 [minkernel\crts\ucrt\inc\corecrt_internal.h @ 974]
25 00000048`f02ff5c0 00007ffc`c5491cc5 ucrtbased!_execute_onexit_table+0x34 [minkernel\crts\ucrt\src\appcrt\startup\onexit.cpp @ 231]
26 00000048`f02ff610 00007ffc`c5491a2d ucrtbased!::operator()+0x95 [minkernel\crts\ucrt\src\appcrt\startup\exit.cpp @ 221]
27 00000048`f02ff660 00007ffc`c5491aa7 ucrtbased!__crt_seh_guarded_call::operator()<, &, >+0x2d [VCCRT\vcruntime\inc\internal_shared.h @ 224]
28 00000048`f02ff690 00007ffc`c5491e70 ucrtbased!__acrt_lock_and_call< >+0x57 [minkernel\crts\ucrt\inc\corecrt_internal.h @ 974]
29 00000048`f02ff6f0 00007ffc`c54921f6 ucrtbased!common_exit+0x70 [minkernel\crts\ucrt\src\appcrt\startup\exit.cpp @ 253]
2a 00000048`f02ff750 00007ff7`9d5a5f57 ucrtbased!exit+0x16 [minkernel\crts\ucrt\src\appcrt\startup\exit.cpp @ 288]
2b 00000048`f02ff780 00007ff7`9d5a5dfe unit_tests!__scrt_common_main_seh+0x147 [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 297]
2c 00000048`f02ff7f0 00007ff7`9d5a605e unit_tests!__scrt_common_main+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331]
2d 00000048`f02ff820 00007ffd`928d163d unit_tests!mainCRTStartup+0xe [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp @ 17]
2e 00000048`f02ff850 00007ffd`941bd878 kernel32!BaseThreadInitThunk+0x1d
2f 00000048`f02ff880 00000000`00000000 ntdll!RtlUserThreadStart+0x28
```
Contributor guide
Research direction
Start in external/Catch2/src/catch2/internal/catch_leak_detector.cpp and trace the destructor into catch_singletons.cpp and catch_registry_hub.cpp, especially cleanupSingletons and cleanUp shown in the call stack. Reproduce the failure with the global new/delete instrumentation described in the issue. Done means the LeakDetector destructor no longer allows bad_alloc to escape when singleton cleanup performs the allocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100