mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-09 19:00:20 +02:00
Same situation as the last stack leak memory fix, this is fairly tricky since it is dealing with stack pivoting. Fixes the memory leak around pthread stack allocations, making memory usage lower for applications that constantly spin-up and destroy threads (Like Steam). We need to let glibc allocate a minimum sized stack (128KB and we can't control it) to work around a race condition with DTV/TLS regions. This means we need to do a stack pivot once the thread starts executing. We also need to be careful because the `PThread` object is deleted inside of the execution thread, which was resulting in a use-after-free bug. There are definitely some more memory leaks that I'm still fighting, and I have noticed in my abusive thread creation program that we might want to change some jemalloc options to more aggressively cut down on residency. This is just one out of many.