This is the mail archive of the
mailing list for the pthreas-win32 project.
Memory leak problem in MSVS6.0 C library when using pthread_create
- To: "Pthreads Win32 (E-mail)" <pthreads-win32 at sourceware dot cygnus dot com>
- Subject: Memory leak problem in MSVS6.0 C library when using pthread_create
- From: Mattias Ernelli <Mattias dot Ernelli at melody dot se>
- Date: Fri, 22 Dec 2000 10:00:12 +0100
I have encountered a memory leak problem when using pthreads for Win32.
The leak occurs in the Microsfoft MSVS 6.0 C library. The problem is that
the native Win32 Threads API did not provide a method to install cleanup
handlers for the thread like pthread does when using pthread_key_create for
Thus the C library shipped with MSVS 6.0 for Win32 requires that all threads
that uses the C library is created using the library functions beginthread
or beginthreadex, so that memory used for the thread specific C runtime data
can be allocated/deallocated automatically. This data is used for internal
structures used by libc as well as errno, randseed etc.
Now I have discovered when running applications using pthreads through
purify that each terminating thread leaves a memory leak of the C library
thread specific data on the heap.
After examining the source code in pthread_create I noticed that a call to
beginthread is actually made, to ensure that endthread is properly called so
that the thread specific memory allocation made by the C library is freed,
but it doesnt in some strange way work that way. Actually, by the way the
leak appears it seems as if beginthreadex is not called at all.
Now since the source in pthread indicates that the C library memory
allocation is considered, otherwise a call to CreateThread could be issued
directly instead, I do belive that I am doing something wrong when
I have tried using the latest, 2000-09-08 pthreads-win32 but the problem