L
L
leanid2013-08-13 11:28:21
C++ / C#
leanid, 2013-08-13 11:28:21

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

The following code gives two memory leaks, one is explicit (for the test), the other I don’t understand from where, apparently in the implementation of the C ++ library from Microsoft.
Tell me how to deal with this. 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 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 all this on visual studio 2012 express

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vScherba, 2013-08-13
@leanid

Known MS CRT bug .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question