From owner-freebsd-threads@FreeBSD.ORG Tue Apr 5 09:20:06 2005 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0F33216A4D0 for ; Tue, 5 Apr 2005 09:20:06 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6A3343D1F for ; Tue, 5 Apr 2005 09:20:05 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j359K5CS069487 for ; Tue, 5 Apr 2005 09:20:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j359K5l0069486; Tue, 5 Apr 2005 09:20:05 GMT (envelope-from gnats) Date: Tue, 5 Apr 2005 09:20:05 GMT Message-Id: <200504050920.j359K5l0069486@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Kimmo Mustonen Subject: Re: threads/79526: A memory leak in pthread_rwlock_init() X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Kimmo Mustonen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2005 09:20:06 -0000 The following reply was made to PR threads/79526; it has been noted by GNATS. From: Kimmo Mustonen To: Craig Rodrigues Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: threads/79526: A memory leak in pthread_rwlock_init() Date: Tue, 5 Apr 2005 12:14:17 +0300 (EEST) On Mon, 4 Apr 2005, Craig Rodrigues wrote: > Can you try this patch? > prwlock was being allocated by malloc inside pthread_rwlock_init(), > but never freed. > *rwlock = prwlock; > + free(prwlock); First, this patch is broken. It sets the pointer to a datastructure but frees the contents of the structure immediately after that, later causing referencing to deallocated memory and crashing. The valgrind version did not crash but still leaked memory after this (broken) patch. I didn't realise valgrind has its own pthread library. Thus, the problem is most probably in the valgrind implementation of pthread library and the actual pthread library does not leak. So I don't think there's a need for a patch in pthread. I hope this problem will disappear when the new valgrind using native pthread library is ported to FreeBSD. Regards, Kimmo Mustonen