diff options
author | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-14 15:08:43 +0000 |
---|---|---|
committer | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-14 15:08:43 +0000 |
commit | d399cb062b063ae5a44e60581d995533a767f98b (patch) | |
tree | 3fac84cb3ee44adfff05d17f6ecf42c590f6a580 /threadproc | |
parent | 47b0d7e2a40038da47543fdfaceeff104bfd5efd (diff) | |
download | libapr-d399cb062b063ae5a44e60581d995533a767f98b.tar.gz |
* threadproc/unix/thread.c (threadattr_cleanup): New function.
(apr_threadattr_create): Register cleanup for threadattr object, fix
possible memory leak.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65195 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r-- | threadproc/unix/thread.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c index d906e0954..68faebeaa 100644 --- a/threadproc/unix/thread.c +++ b/threadproc/unix/thread.c @@ -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 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, 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 |