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

Eric Blake eblake at redhat.com
Mon Jan 24 15:41:39 UTC 2011


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 at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110124/7a5cea91/attachment-0001.sig>


More information about the libvir-list mailing list