[libvirt] [PATCH] Fix leak of mutex attributes in POSIX threads impl

* src/util/threads-pthread.c: Fix mutex leak --- src/util/threads-pthread.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c index ea71589..f812045 100644 --- a/src/util/threads-pthread.c +++ b/src/util/threads-pthread.c @@ -47,7 +47,9 @@ int virMutexInit(virMutexPtr m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) { + ret = pthread_mutex_init(&m->lock, &attr); + pthread_mutexattr_destroy(&attr); + if (ret != 0) { errno = ret; return -1; } @@ -60,7 +62,9 @@ int virMutexInitRecursive(virMutexPtr m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) { + ret = pthread_mutex_init(&m->lock, &attr); + pthread_mutexattr_destroy(&attr); + if (ret != 0) { errno = ret; return -1; } -- 1.7.3.4

On 01/24/2011 08:35 AM, Daniel P. Berrange wrote:
* src/util/threads-pthread.c: Fix mutex leak --- src/util/threads-pthread.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c index ea71589..f812045 100644 --- a/src/util/threads-pthread.c +++ b/src/util/threads-pthread.c @@ -47,7 +47,9 @@ int virMutexInit(virMutexPtr m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) { + ret = pthread_mutex_init(&m->lock, &attr); + pthread_mutexattr_destroy(&attr); + if (ret != 0) {
ACK. However, since we reuse the same attributes, would it be more efficient to statically create a static pthread_mutexattr_t once, and reuse it, rather than constantly recreating it on every call? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake