Subject: lib/23791: potential memory leak if pthread_create() fails
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <pat@eyeo.org>
List: netbsd-bugs
Date: 12/18/2003 15:01:33
>Number:         23791
>Category:       lib
>Synopsis:       potential memory leak if pthread_create() fails
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 18 15:02:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Patrick Latifi
>Release:        -current
>Organization:
>Environment:
-current
>Description:
if pthread__stackalloc() fails inside pthread_create(), we may not free memory previously allocated by strdup().
>How-To-Repeat:

>Fix:
--- pthread_c.orig   Thu Dec 18 09:23:29 2003
+++ pthread.c  Thu Dec 18 09:24:58 2003
@@ -322,8 +322,11 @@
      pthread_spinunlock(self, &pthread__deadqueue_lock);
      /* Set up a stack and allocate space for a pthread_st. */
      ret = pthread__stackalloc(&newthread);
-     if (ret != 0)
+     if (ret != 0) {
+        if (name != NULL)
+           free(name);
         return ret;
+     }
   }

   /* 2. Set up state. */
>Release-Note:
>Audit-Trail:
>Unformatted: