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
This commit is contained in:
Jason Evans 2000-05-16 22:08:14 +00:00
parent 9ee6ec34ef
commit ccb3a748f4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=60658
3 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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