From: Adam C. Emerson Date: Tue, 7 Jul 2020 20:39:57 +0000 (-0400) Subject: common/Thread: Don't store pointer to thread_name X-Git-Tag: v17.0.0~1186^2~14 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4cec019d5efabb340b9e8541dae58f33a2826c50;p=ceph.git common/Thread: Don't store pointer to thread_name Having Thread::create store a pointer to a string that is passed to ceph_pthread_setname in Thread::entry_wrapper can lead to using a pointer in the calling thread's stack that gets freed before use. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/Thread.cc b/src/common/Thread.cc index ccee3bc84d90c..ca8d7a18272de 100644 --- a/src/common/Thread.cc +++ b/src/common/Thread.cc @@ -62,8 +62,7 @@ static int _set_affinity(int id) Thread::Thread() : thread_id(0), pid(0), - cpuid(-1), - thread_name(NULL) + cpuid(-1) { } @@ -84,7 +83,7 @@ void *Thread::entry_wrapper() if (pid && cpuid >= 0) _set_affinity(cpuid); - ceph_pthread_setname(pthread_self(), thread_name); + ceph_pthread_setname(pthread_self(), thread_name.c_str()); #ifdef WITH_SEASTAR crimson::os::AlienStore::configure_thread_memory(); #endif diff --git a/src/common/Thread.h b/src/common/Thread.h index 0ab65fca52f01..5242fb5f30758 100644 --- a/src/common/Thread.h +++ b/src/common/Thread.h @@ -33,7 +33,7 @@ class Thread { pthread_t thread_id; pid_t pid; int cpuid; - const char *thread_name; + std::string thread_name; void *entry_wrapper();