That's a critical problem that took me several hours to pinpoint to TDM-GCC, and looks like the root cause is in the same place as the problem from my previous bug report.
It's easy to reproduce: Create several threads with code that uses exceptions, and check the amount of handles that the process uses. For example:
The handle is created by Winpthreads by using DuplicateHandle in a function called pthread_getspecific, and is never closed. By looking at the source code, the handle is closed in two scenarios:
When pthread_exit is called.
Inside __dyn_tls_pthread which is a hook for TLS-based deregistration/registration of thread.
Neither of them are executed, and so the thread handle is left dangling forever. This causes a handle leak, and a memory leak of non-paged memory, which gets worse with time as more threads are created and destroyed.
That's a critical problem that took me several hours to pinpoint to TDM-GCC, and looks like the root cause is in the same place as the problem from my previous bug report.
It's easy to reproduce: Create several threads with code that uses exceptions, and check the amount of handles that the process uses. For example:
The handle is created by Winpthreads by using
DuplicateHandle
in a function calledpthread_getspecific
, and is never closed. By looking at the source code, the handle is closed in two scenarios:pthread_exit
is called.__dyn_tls_pthread
which is a hook for TLS-based deregistration/registration of thread.Neither of them are executed, and so the thread handle is left dangling forever. This causes a handle leak, and a memory leak of non-paged memory, which gets worse with time as more threads are created and destroyed.