_beginthreadex leaks memory in Windows XP - by Andreas Magnusson - Nexus

Status : 


Sign in
to vote
ID 2810618 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 6/13/2016 8:14:44 AM
Access Restriction Public


_beginthread/_beginthreadex allocates memory per thread that is not properly free:d under Windows XP.
The provided program will report leaks of ~1Kb/thread when built with a statically linked CRT and the v140_xp toolchain (Change the THREAD_COUNT for more threads and leaks).
It does not seem to leak under VS2013.
This seems to be related to the fact that the UCRT (used by VS2015) no longer free:s the memory allocated per thread in _endthread/_endthreadex but instead relies on
DLL_THREAD_DETACH messages to DllMain which doesn't seem to propagate properly with a statically linked CRT in Windows XP.
Sign in to post a comment.
Posted by Andreas Magnusson - Nexus on 6/17/2016 at 1:41 PM
Hi, that's unfortunate.

I understand your reluctance for XP support, I would gladly stop supporting it in our product if it was up to me. Unfortunately it's not up to me, not all developers are in the luxurious position to dictate what kind of OS:es their customers use.

While it would be possible to do #1, #2 is too big a change for a large legacy application and #3 is just plain offensive. A downgrade to MSVC2013 is more probable or using thread pools (which hopefully will work in all our use cases).

Posted by James [MSFT] on 6/17/2016 at 12:21 PM

Thank you for reporting this issue. Unfortunately, given that this problem only occurs on Windows XP, this does not meet our bug triage bar and we do not plan to fix this issue. We would recommend considering the following workarounds:

[1] Use the CRT DLL instead of statically linking the CRT
[2] Move your own code out of the EXE into a DLL that statically links the CRT (and have the EXE that is just a stub that loads and calls into the DLL)
[3] Upgrade to a newer operating system


James McNellis
Visual C++ Libraries
Posted by Microsoft on 6/13/2016 at 7:30 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If you require immediate assistance with this issue, please contact product support at http://support.microsoft.com/oas/default.aspx?prid=15825.