[xml] Crash/Memory leak in threads.c



Hi,

I beleive there is a problem with threads.c mechanism of cleaning
xmlGlobalState on Win32. The default one i.e. using secondary thread to
clean up fails with crash in the following situation.

1. An application loads libxml explicitly and performs some operations. This
causes libxml to create a watchdog thread with xmlGlobalStateCleanupHelper
that goes to sleep in kernel mode using WaitForSingleObject.
2. The application unloads libxml but continues to run.
3. Any of the threads that "touched" libxml terminates.
4. The watchdog thread's WaitForSingleObject returns from kernel into a
non-valid memory. bang! :-)

I've seen the fix proposed by Stéphane Bidoul that eliminates the watchdog
thread and uses DLL_THREAD_DETACH notification. Unfortunately it doesn't
solve the problem either. Here is the scenario

1. An application creates some threads _before loading libxml_
2. The application loads libxml explicitly and performs some operations from
the threads created in step 1.
3. The application unloads libxml. At this point the DLL_PROCESS_DETACH
notification _will not be sent_ for the threads that existed prior to libxml
loading (i.e. threads from step 1). Result: memory leak.

I belevie that it is impossible to make DLL_PROCESS_DETACH to work
correctly. For myself I solved the problem by storing a list of allocated
xmlGlobalStates and freeing it on DLL_PROCESS_DETACH. I would gladly post
the code if there is an interest in it.

Eugene




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]