Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Göran_W_
Beginner
35 Views

Memory leaks in ITT included with TBB 4.4 U2

Hi! In TBB 4.4 U2, the version of ITT included (in the tools_api folder) will leak two small chunks of memory for every worker thread created.

The following simple call is enough to reproduce the leaks (tested on x64 build using VS2015 Update 1) :

tbb::parallel_invoke([] {}, [] {});

(To avoid false positives due to process exit before worker threads are shutdown, we should use tbb::task_scheduler_init and TBB_PREVIEW_WAITING_FOR_WORKERS.)

The leaks in ITT happen when market::create_one_job() calls thread_set_name (via macros). The latter function is implemented in tools_api/ittnotify_static.c and leaks twice for each call:

* Each itt_thread_info node on the global .thread_list is malloc'ed via NEW_THREAD_INFO() but never freed.

* The name member inside each itt_thread_info node is malloc'ed via strdup / wcsdup but never freed.

This should be high prio since it may produce a large number of memory leaks from TBB, making it hard to locate other mem-leaks in client code.

A possible workaround is to rebuild tbb_debug.dll + .lib with DO_ITT_NOTIFY undefined.

Here is a complete example to reproduce the leaks:

#include <windows.h>
#include <tchar.h>
#include <assert.h>

#define TBB_PREVIEW_WAITING_FOR_WORKERS 1
#include "tbb/parallel_invoke.h"
#include "tbb/task_scheduler_init.h"
#include "tbb/tbb_allocator.h"

int _tmain(int argc, _TCHAR* argv[])
{
  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  assert(tbb::tbb_allocator<int>::allocator_type() != tbb::tbb_allocator<int>::scalable);

  {
    tbb::task_scheduler_init scope(tbb::task_scheduler_init::automatic, 0, true);
    tbb::parallel_invoke([] {}, [] {});
  }

  return 0;
}

Thanks,

Göran Wallgren
 

0 Kudos
1 Reply
35 Views

Thanks for digging into this.

we are looking for a fix.

--Vladimir