threads/79526: A memory leak in pthread_rwlock_init()
Kimmo Mustonen
tzimmo at rommon.com
Mon Apr 4 05:40:13 PDT 2005
>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 at 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 <pthread.h>
/* 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:
More information about the freebsd-threads
mailing list