<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - leak in std/thread/futures/futures.shared_future/get.pass.cpp"
   href="http://llvm.org/bugs/show_bug.cgi?id=22606">22606</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>leak in std/thread/futures/futures.shared_future/get.pass.cpp
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>earthdok@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>eric@efcs.ca, kcc@google.com, llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com, samsonov@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13879" name="attach_13879" title="reproducer">attachment 13879</a> <a href="attachment.cgi?id=13879&action=edit" title="reproducer">[details]</a></span>
reproducer

LeakSanitizer reports a flaky leak of __thread_struct + __thread_struct_impl in
this test:

<a href="http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-asan/builds/175/steps/test.libcxx/logs/libc%2B%2B%3A%3Aget.pass.cpp">http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-asan/builds/175/steps/test.libcxx/logs/libc%2B%2B%3A%3Aget.pass.cpp</a>

I've attached a reduced test case. To build:

../build/bin/clang++ -std=c++11 -nostdinc++
-I../llvm/projects/libcxx/test/support -include
../llvm/projects/libcxx/test/support/nasty_macros.hpp
-I../llvm/projects/libcxx/include -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS  -nodefaultlibs  -Llib/
-Wl,-rpath,/usr/local/google/home/earthdok/san/build-libcxx/lib -lc++ -lc++abi
-lgcc_eh -lc -lm -lpthread -lrt -lgcc_s -ldl -fsanitize=address -g
-fno-omit-frame-pointer repro.cpp


After adding some logging output, I believe that this is *not* an LSan issue.
Normally __thread_struct is allocated here:

    #0 0x4c1e6b in operator new(unsigned long) _asan_rtl_:35
    #1 0x4cee23 in void* std::__1::__thread_proxy<std::__1::tuple<void
(*)(std::__1::promise<void>), std::__1::promise<void> > >(void*)
/usr/local/google/home/earthdok/san/build-libcxx/../llvm/projects/libcxx/include/thread:346:33
    #2 0x4ab00e in __asan::AsanThread::ThreadStart(unsigned long,
__sanitizer::atomic_uintptr_t*) _asan_rtl_:25

and deleted from a TSD destructor here:

    #0 0x4c24eb in operator delete(void*) _asan_rtl_:3
    #1 0x7fbaca476ad5 in
std::__1::__thread_specific_ptr<std::__1::__thread_struct>::__at_thread_exit(void*)
/usr/local/google/home/earthdok/san/llvm/projects/libcxx/include/thread:146:5
    #2 0x7fbac95a5f81 in __nptl_deallocate_tsd
/build/buildd/eglibc-2.19/nptl/pthread_create.c:158:0


However, in those cases when there is a leak, the TSD destructor call doesn't
happen. Looks like there's a race between the global __thread_specific_ptr
destructor which runs on the main thread and calls pthread_key_delete(), and
the TSD destructor. If the pthread_key_delete() call happens first, the TSD
destructor is not run.

Now, we can probably work around this in LSan, but I'm not convinced this is
good behavior on part of libc++. Another option would be to hold
__thread_struct in a special kind of __thread_specific_ptr which wouldn't call
pthread_key_delete() on destruction.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>