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 pasta
parent a170c649b8
commit f425316eed
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -433,9 +433,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
{ {
@ -449,7 +449,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;
} }
} }