Fix illegal memory reference problem

This commit is contained in:
tino247 2024-02-06 16:40:20 +00:00 committed by ob-robot
parent 0713bad3c7
commit 46faad3ae7
2 changed files with 7 additions and 5 deletions

View File

@ -2457,10 +2457,10 @@ OB_INLINE char* ob_get_tname()
return tname;
}
OB_INLINE const char*& ob_get_origin_thread_name()
OB_INLINE char* ob_get_origin_thread_name()
{
thread_local const char* tname = nullptr;
return tname;
thread_local char ori_tname[oceanbase::OB_THREAD_NAME_BUF_LEN] = {0};
return ori_tname;
}
static const char* PARALLEL_DDL_THREAD_NAME = "DDLPQueueTh";

View File

@ -32,7 +32,8 @@ inline void set_thread_name(const char* type, uint64_t idx)
{
char *name = ob_get_tname();
uint64_t tenant_id = ob_get_tenant_id();
ob_get_origin_thread_name() = type;
char *ori_tname = ob_get_origin_thread_name();
STRNCPY(ori_tname, type, oceanbase::OB_THREAD_NAME_BUF_LEN);
if (tenant_id == 0) {
snprintf(name, OB_THREAD_NAME_BUF_LEN, "%s%ld", type, idx);
} else {
@ -45,7 +46,8 @@ inline void set_thread_name(const char* type)
{
char *name = ob_get_tname();
uint64_t tenant_id = ob_get_tenant_id();
ob_get_origin_thread_name() = type;
char *ori_tname = ob_get_origin_thread_name();
STRNCPY(ori_tname, type, oceanbase::OB_THREAD_NAME_BUF_LEN);
if (tenant_id == 0) {
snprintf(name, OB_THREAD_NAME_BUF_LEN, "%s", type);
} else {