Skip to content

Commit

Permalink
Fixes asan's detected tbb leak in osrm-partition
Browse files Browse the repository at this point in the history
Here's all I could get out of a instrumented `osrm-partition`; debug build,
with all the bells and whistles I could think of to make it more verbose:

```
==17928==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1560 byte(s) in 3 object(s) allocated from:
    #0 0x7f4244185b30 in operator new[](unsigned long) ../../../../libsanitizer/asan/asan_new_delete.cc:62
    #1 0x7f4242a788b3  (/usr/lib/libtbb.so.2+0x208b3)

SUMMARY: AddressSanitizer: 1560 byte(s) leaked in 3 allocation(s).<Paste>
``

Symbolizing the address results in

```
echo "/usr/lib/libtbb.so 0x7f4242a788b3" | llvm-symbolizer
_fini
```

Looks like a crt finalizer => static global dtor "leaking" from tbb.

Which turned out to be a missing `tbb::task_scheduler_init` on our end:

> Using task_scheduler_init is optional in Intel® Threading Building
> Blocks (Intel® TBB) 2.2. By default, Intel TBB 2.2 automatically creates
> a task scheduler the first time that a thread uses task scheduling
> services and destroys it when the last such thread exits.

https://www.threadingbuildingblocks.org/docs/help/hh_goto.htm?index.htm#reference/task_scheduler/task_scheduler_init_cls.html

Without an explicit instanz the first call to a tbb algorithm seem to initialize
a global scheduler singleton which then "leaks" until the program exits.

Phew.
  • Loading branch information
daniel-j-h committed Feb 14, 2017
1 parent 7a61617 commit dfbe7ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/partition/partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include <boost/assert.hpp>

#include <tbb/task_scheduler_init.h>

#include "util/geojson_debug_logger.hpp"
#include "util/geojson_debug_policies.hpp"
#include "util/json_container.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ int main(int argc, char *argv[]) try
return EXIT_FAILURE;
}

tbb::task_scheduler_init init(partition_config.requested_num_threads);

auto exitcode = partition::Partitioner().Run(partition_config);

util::DumpMemoryStats();
Expand Down

0 comments on commit dfbe7ba

Please sign in to comment.