From 0b5fbaad14989b2e59079e19ca940cf084c785ef Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Tue, 14 Feb 2017 16:05:07 +0100 Subject: [PATCH] Fixes asan's detected tbb leak in osrm-partition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). `` 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. --- src/partition/partitioner.cpp | 2 -- src/tools/partition.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/partition/partitioner.cpp b/src/partition/partitioner.cpp index 4706ce7eba9..8719f56a6c4 100644 --- a/src/partition/partitioner.cpp +++ b/src/partition/partitioner.cpp @@ -14,8 +14,6 @@ #include -#include - #include "util/geojson_debug_logger.hpp" #include "util/geojson_debug_policies.hpp" #include "util/json_container.hpp" diff --git a/src/tools/partition.cpp b/src/tools/partition.cpp index 8434a2f6b8b..eecc674f801 100644 --- a/src/tools/partition.cpp +++ b/src/tools/partition.cpp @@ -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();