From dfbb81bff616f7df97f5d3a3c88da86f0f7bdf8d Mon Sep 17 00:00:00 2001 From: xdustinface Date: Tue, 14 Jul 2020 13:06:37 +0200 Subject: [PATCH] util: Change TraceThread's "name" type: "const char*" -> "const std::string" Having "const char*" leads to undefined behaviour if the "const char*" is deallocated before the thread used it. Co-Authored-By: UdjinM6 --- src/util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.h b/src/util.h index 5ead5633a2e3..dfcdd37e2914 100644 --- a/src/util.h +++ b/src/util.h @@ -434,9 +434,9 @@ void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName); /** * .. and a wrapper that just calls func once */ -template void TraceThread(const char* name, Callable func) +template void TraceThread(const std::string name, Callable func) { - std::string s = strprintf("dash-%s", name); + std::string s = "dash-" + name; RenameThread(s.c_str()); try { @@ -450,7 +450,7 @@ template void TraceThread(const char* name, Callable func) throw; } catch (...) { - PrintExceptionContinue(std::current_exception(), name); + PrintExceptionContinue(std::current_exception(), name.c_str()); throw; } }