Skip to content

Catch::LeakDetector::~LeakDetector can throw bad_alloc - destructors should not throw #2634

@Alan-Jowett

Description

@Alan-Jowett

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<ISingleton*>*& {
            static std::vector<ISingleton*>* g_singletons = nullptr;
            if( !g_singletons )
                g_singletons = new std::vector<ISingleton*>();
            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!<lambda_d121dba8a4adeaf3a9819e48611155df>::operator()+0x131 [minkernel\crts\ucrt\src\appcrt\startup\onexit.cpp @ 206] 
23 00000048`f02ff520 00007ffc`c5492547     ucrtbased!__crt_seh_guarded_call<int>::operator()<<lambda_6a47f4c8fd0152770a780fc1d70204eb>,<lambda_d121dba8a4adeaf3a9819e48611155df> &,<lambda_6aaa2265f5b6a89667e7d7630012e97a> >+0x35 [VCCRT\vcruntime\inc\internal_shared.h @ 204] 
24 00000048`f02ff560 00007ffc`c5492e34     ucrtbased!__acrt_lock_and_call<<lambda_d121dba8a4adeaf3a9819e48611155df> >+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!<lambda_ad52fe89635f51ec3b38e9c3ac6dac81>::operator()+0x95 [minkernel\crts\ucrt\src\appcrt\startup\exit.cpp @ 221] 
27 00000048`f02ff660 00007ffc`c5491aa7     ucrtbased!__crt_seh_guarded_call<void>::operator()<<lambda_123965863b7b46a3332720573f9ce793>,<lambda_ad52fe89635f51ec3b38e9c3ac6dac81> &,<lambda_8d528b66de6ae1e796d7f5e3101fca72> >+0x2d [VCCRT\vcruntime\inc\internal_shared.h @ 224] 
28 00000048`f02ff690 00007ffc`c5491e70     ucrtbased!__acrt_lock_and_call<<lambda_ad52fe89635f51ec3b38e9c3ac6dac81> >+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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions