From 28fde4831e337e9ba71dec7b314ca3b3e7c51fdf Mon Sep 17 00:00:00 2001 From: jasone Date: Tue, 16 May 2000 22:08:14 +0000 Subject: Fix a memory leak. pthread_set_name_np() allocates space for a name, but was not deallocating space for the previous name, if any. PR: misc/18504 --- lib/libc_r/uthread/uthread_info.c | 8 ++++++-- lib/libkse/thread/thr_info.c | 8 ++++++-- lib/libpthread/thread/thr_info.c | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libc_r/uthread/uthread_info.c b/lib/libc_r/uthread/uthread_info.c index 06b556e..d091ec1 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 06b556e..d091ec1 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 06b556e..d091ec1 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 -- cgit v1.1