util: Change TraceThread's "name" type: "const char*" -> "const std::string" (#3609)

Having "const char*" leads to undefined behaviour if the "const char*"
is deallocated before the thread used it.

Co-Authored-By: UdjinM6 <UdjinM6@users.noreply.github.com>

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
dustinface 2020-07-14 23:15:05 +02:00 committed by GitHub
parent fc6fe505ca
commit f44dd06eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -434,9 +434,9 @@ void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName);
/** /**
* .. and a wrapper that just calls func once * .. and a wrapper that just calls func once
*/ */
template <typename Callable> void TraceThread(const char* name, Callable func) template <typename Callable> void TraceThread(const std::string name, Callable func)
{ {
std::string s = strprintf("dash-%s", name); std::string s = "dash-" + name;
RenameThread(s.c_str()); RenameThread(s.c_str());
try try
{ {
@ -450,7 +450,7 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
throw; throw;
} }
catch (...) { catch (...) {
PrintExceptionContinue(std::current_exception(), name); PrintExceptionContinue(std::current_exception(), name.c_str());
throw; throw;
} }
} }