Memory leak when using std::thread in visual studio 2012?

The following code gives two memory leaks, one explicit(for the dough), the other I do not understand how, apparently in the implementation of the C++ libraries from Microsoft.

Tell me, how to deal with it. Thank you in advance.

#include <thread>
#include <iostream>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

void func(int param)
{
 std::cout << param << "\n";
}

int main()
{
 int tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
 // always perform a leak check just before the app exits.
 tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(tmpDbgFlag);

 int* ptr_leak = new int(0xF0F0F0F0);

{
 std::thread t(&func, 1); // second memory leak! WHY? Can I do something?
 if (t.joinable())
{
t.join();
}
}
 return 0;
}



The result of running the debug version:

Detected memory leaks!
Dumping objects ->
{302} normal block at 0x0046AED0, 44 bytes long.
Data: < > 01 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00
{150} normal block at 0x0046AE48, 4 bytes long.
Data: < > F0 F0 F0 F0
Object dump complete.
The program '[1576] test_thread.exe' has exited with code 0 (0x0).


I try this on visual studio 2012 express
October 3rd 19 at 04:19
2 answers
October 3rd 19 at 04:21
Solution
Known bug in the MS CRT.
How to fight: in the current version of the compiler does (fixed in next), in loop leakage should not increase, check it out in practice. Should flow the same 44 bytes. But it's not really a leak:
The leak is the "static _Mtx_t at_thread_exit_mutex" declared in "crt\src\thr\xnotify.c", which is allocated once for the first created std::thread but never freed. So it's not a leak per say, more of a "skipped cleaning up after me"-issue.
© Andreas Magnusson - Frederick23 commented on October 3rd 19 at 04:24
Thank you, I also then found the link, the explanation of the thing, and have installed the 2013 preview. Can't work, when after each run, see the message about the leak. Moreover, it is always easier to fix what you just wrote, so for me, a memory leak in normal use is unacceptable. But there was a problem with Boston, he's not going (1.54) 2013 under the Studio, and now shake extreme version from the repository, with the patch it should already be 2013 Studio. - joe.Crist commented on October 3rd 19 at 04:27
October 3rd 19 at 04:23
std::thread

Find more questions by tags C++Visual Studio