aboutsummaryrefslogtreecommitdiff
path: root/thirdparty
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty')
-rw-r--r--thirdparty/doctest/doctest/doctest.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/thirdparty/doctest/doctest/doctest.h b/thirdparty/doctest/doctest/doctest.h
index f297fa0b2..5299d9c1a 100644
--- a/thirdparty/doctest/doctest/doctest.h
+++ b/thirdparty/doctest/doctest/doctest.h
@@ -3337,7 +3337,8 @@ namespace {
} // namespace
namespace detail {
- DOCTEST_THREAD_LOCAL class
+ // Leaked heap allocation - see g_infoContexts comment above.
+ class ThreadLocalStringStream
{
std::vector<std::streampos> stack;
std::stringstream ss;
@@ -3358,7 +3359,12 @@ namespace detail {
ss.rdbuf()->pubseekpos(pos, std::ios::in | std::ios::out);
return String(ss, sz);
}
- } g_oss;
+ };
+ static ThreadLocalStringStream& g_oss_ref() {
+ DOCTEST_THREAD_LOCAL auto* p = new ThreadLocalStringStream();
+ return *p;
+ }
+ #define g_oss g_oss_ref() // NOLINT
std::ostream* tlssPush() {
return g_oss.push();
@@ -4600,7 +4606,14 @@ namespace detail {
getExceptionTranslators().push_back(et);
}
- DOCTEST_THREAD_LOCAL std::vector<IContextScope*> g_infoContexts; // for logging with INFO()
+ // Use a leaked heap allocation for thread-local state to avoid calling destructors
+ // during shutdown. With static CRT linking, thread-local destructors can run after
+ // the CRT has already been torn down on secondary threads, causing crashes.
+ static std::vector<IContextScope*>& g_infoContexts_ref() {
+ DOCTEST_THREAD_LOCAL auto* p = new std::vector<IContextScope*>();
+ return *p;
+ }
+ #define g_infoContexts g_infoContexts_ref() // NOLINT
ContextScopeBase::ContextScopeBase() {
g_infoContexts.push_back(this);
@@ -6440,13 +6453,18 @@ namespace {
#ifdef DOCTEST_PLATFORM_WINDOWS
struct DebugOutputWindowReporter : public ConsoleReporter
{
- DOCTEST_THREAD_LOCAL static std::ostringstream oss;
+ // Leaked heap allocation - see g_infoContexts comment in detail namespace.
+ static std::ostringstream& oss_ref() {
+ DOCTEST_THREAD_LOCAL auto* p = new std::ostringstream();
+ return *p;
+ }
DebugOutputWindowReporter(const ContextOptions& co)
- : ConsoleReporter(co, oss) {}
+ : ConsoleReporter(co, oss_ref()) {}
#define DOCTEST_DEBUG_OUTPUT_REPORTER_OVERRIDE(func, type, arg) \
void func(type arg) override { \
+ auto& oss = oss_ref(); \
bool with_col = g_no_colors; \
g_no_colors = false; \
ConsoleReporter::func(arg); \
@@ -6470,7 +6488,6 @@ namespace {
DOCTEST_DEBUG_OUTPUT_REPORTER_OVERRIDE(test_case_skipped, const TestCaseData&, in)
};
- DOCTEST_THREAD_LOCAL std::ostringstream DebugOutputWindowReporter::oss;
#endif // DOCTEST_PLATFORM_WINDOWS
// the implementation of parseOption()