[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] libxl: fix mutex initialization



Roger Pau Monne writes ("[Xen-devel] [PATCH] libxl: fix mutex initialization"):
> +    pthread_mutexattr_t attr;
> +
> +    if (pthread_mutexattr_init(&attr) != 0) {
> +        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
> +                         "Failed to init mutex attributes\n");
> +        return ERROR_FAIL;
> +    }
> +    if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
> +        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
> +                         "Failed to set mutex attributes\n");
> +        return ERROR_FAIL;
> +    }
> +    if (pthread_mutex_init(lock, &attr) != 0) {
> +        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 
> +                         "Failed to init mutex\n");
> +        return ERROR_FAIL;
> +    }
> +    return 0;

This leaks the contents of attr.  You need to call
pthread_mutexattr_destroy on all the exit paths (except the one where
_init failed).

What a horrible API for passing in some trivial flags!

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.