diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c index 06b556e69b18..d091ec12113c 100644 --- a/lib/libc_r/uthread/uthread_info.c +++ b/lib/libc_r/uthread/uthread_info.c @@ -304,8 +304,12 @@ void pthread_set_name_np(pthread_t thread, char *name) { /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == PTHREAD_MAGIC) + if (thread != NULL && thread->magic == PTHREAD_MAGIC) { + if (thread->name != NULL) { + /* Free space for previous name. */ + free(thread->name); + } thread->name = strdup(name); - return; + } } #endif diff --git a/lib/libkse/thread/thr_info.c b/lib/libkse/thread/thr_info.c index 06b556e69b18..d091ec12113c 100644 --- a/lib/libkse/thread/thr_info.c +++ b/lib/libkse/thread/thr_info.c @@ -304,8 +304,12 @@ void pthread_set_name_np(pthread_t thread, char *name) { /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == PTHREAD_MAGIC) + if (thread != NULL && thread->magic == PTHREAD_MAGIC) { + if (thread->name != NULL) { + /* Free space for previous name. */ + free(thread->name); + } thread->name = strdup(name); - return; + } } #endif diff --git a/lib/libpthread/thread/thr_info.c b/lib/libpthread/thread/thr_info.c index 06b556e69b18..d091ec12113c 100644 --- a/lib/libpthread/thread/thr_info.c +++ b/lib/libpthread/thread/thr_info.c @@ -304,8 +304,12 @@ void pthread_set_name_np(pthread_t thread, char *name) { /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == PTHREAD_MAGIC) + if (thread != NULL && thread->magic == PTHREAD_MAGIC) { + if (thread->name != NULL) { + /* Free space for previous name. */ + free(thread->name); + } thread->name = strdup(name); - return; + } } #endif