jorton 2004/06/14 08:08:43
Modified: threadproc/unix thread.c
Log:
* threadproc/unix/thread.c (threadattr_cleanup): New function.
(apr_threadattr_create): Register cleanup for threadattr object, fix
possible memory leak.
Revision Changes Path
1.59 +18 -2 apr/threadproc/unix/thread.c
Index: thread.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/thread.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -d -w -u -r1.58 -r1.59
--- thread.c 10 Jun 2004 10:57:25 -0000 1.58
+++ thread.c 14 Jun 2004 15:08:43 -0000 1.59
@@ -19,9 +19,23 @@
#if APR_HAS_THREADS
-/* XXX: missing a cleanup, pthread_attr_destroy is never called! */
-
#if APR_HAVE_PTHREAD_H
+
+/* Destroy the threadattr object */
+static apr_status_t threadattr_cleanup(void *data)
+{
+ apr_threadattr_t *attr = data;
+ apr_status_t rv;
+
+ rv = pthread_attr_destroy(&attr->attr);
+#ifdef PTHREAD_SETS_ERRNO
+ if (rv) {
+ rv = errno;
+ }
+#endif
+ return rv;
+}
+
APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
apr_pool_t *pool)
{
@@ -32,6 +46,8 @@
stat = pthread_attr_init(&(*new)->attr);
if (stat == 0) {
+ apr_pool_cleanup_register(pool, *new, threadattr_cleanup,
+ apr_pool_cleanup_null);
return APR_SUCCESS;
}
#ifdef PTHREAD_SETS_ERRNO