From owner-freebsd-threads@FreeBSD.ORG Mon Apr 4 12:40:13 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 E55F516A4CE for ; Mon, 4 Apr 2005 12:40:12 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A4B6B43D55 for ; Mon, 4 Apr 2005 12:40:12 +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 j34CeCWI029084 for ; Mon, 4 Apr 2005 12:40:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j34CeCoV029083; Mon, 4 Apr 2005 12:40:12 GMT (envelope-from gnats) Resent-Date: Mon, 4 Apr 2005 12:40:12 GMT Resent-Message-Id: <200504041240.j34CeCoV029083@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Kimmo Mustonen Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BE90216A4CE for ; Mon, 4 Apr 2005 12:36:05 +0000 (GMT) Received: from i2-138.rommon.fi (i2-138.rommon.fi [195.163.185.138]) by mx1.FreeBSD.org (Postfix) with ESMTP id 093C943D5C for ; Mon, 4 Apr 2005 12:36:05 +0000 (GMT) (envelope-from tzimmo@i2-138.rommon.fi) Received: from i2-138.rommon.fi (localhost [127.0.0.1]) by i2-138.rommon.fi (8.13.1/8.13.1) with ESMTP id j34Ca2GU002334 for ; Mon, 4 Apr 2005 15:36:02 +0300 (EEST) (envelope-from tzimmo@i2-138.rommon.fi) Received: (from tzimmo@localhost) by i2-138.rommon.fi (8.13.1/8.13.1/Submit) id j34Ca2JB002333; Mon, 4 Apr 2005 15:36:02 +0300 (EEST) (envelope-from tzimmo) Message-Id: <200504041236.j34Ca2JB002333@i2-138.rommon.fi> Date: Mon, 4 Apr 2005 15:36:02 +0300 (EEST) From: Kimmo Mustonen To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: 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: Mon, 04 Apr 2005 12:40:13 -0000 >Number: 79526 >Category: threads >Synopsis: A memory leak in pthread_rwlock_init() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 04 12:40:12 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Kimmo Mustonen >Release: FreeBSD 5.3-RELEASE-p6 i386 >Organization: ROMmon Oy >Environment: System: FreeBSD tzimmopassive.rommon.fi 5.3-RELEASE-p6 FreeBSD 5.3-RELEASE-p6 #10: Thu Mar 31 14:43:05 EEST 2005 root@tzimmopassive.rommon.fi:/usr/src/sys/i386/compile/ROMMON-PROBE5 i386 Pentium 4, FreeBSD 5.3, i386, pthread >Description: Calling pthread_rwlock_init() leaks memory each time it is called. Example code ---8<---8<--- #include /* start using valgrind: valgrind --tool=memcheck -v --leak-check=yes --show-reachable=yes \ --num-callers=100 ./leak_pthread_1 */ int main(void) { int i; pthread_rwlock_t lock; for (i = 0; i < 100; i++) { pthread_rwlock_init(&lock, NULL); pthread_rwlock_destroy(&lock); } return 0; } ---8<---8<--- and valgrind report ---8<---8<--- ==801== 2012 bytes in 301 blocks are still reachable in loss record 1 of 1 ==801== at 0x3C033183: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so) ==801== by 0x3C03A8D0: (within /usr/local/lib/valgrind/libpthread.so.1) ==801== by 0x3C03BF49: pthread_mutex_init (in /usr/local/lib/valgrind/libpthread.so.1) ==801== by 0x3C03BFA9: pthread_mutex_lock (in /usr/local/lib/valgrind/libpthread.so.1) ==801== by 0x3C03F174: (within /usr/local/lib/valgrind/libpthread.so.1) ==801== by 0x3C03F2D9: pthread_rwlock_init (in /usr/local/lib/valgrind/libpthread.so.1) ==801== by 0x8048609: main (leak_pthread_1.c:14) ==801== ---8<---8<--- >How-To-Repeat: Run the example code using valgrind. >Fix: Haven't looked at the sources, but probably easy to fix. I suppose pthread_rwlock_destroy() just does not free all the resources pthread_rwlock_init() allocates. >Release-Note: >Audit-Trail: >Unformatted: