This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Memory leak problem in MSVS6.0 C library when using pthread_create


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
example.

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
compiling/linking.
I have tried using the latest, 2000-09-08 pthreads-win32 but the problem
remains.

Any clue?

Best regards,

//Mattias

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]