From: Ian Jackson Subject: Re: [PATCH] libxl: fix mutex initialization Date: Thu, 26 Jan 2012 17:41:26 +0000 Message-ID: <20257.36934.246893.233669@mariner.uk.xensource.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Roger Pau Monne Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 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.