From 4cec019d5efabb340b9e8541dae58f33a2826c50 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 7 Jul 2020 16:39:57 -0400 Subject: [PATCH] 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 --- src/common/Thread.cc | 5 ++--- src/common/Thread.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) 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(); -- 2.39.5