Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::thread memory leaks #12988

Closed
emaxx-google opened this issue Dec 7, 2020 · 2 comments
Closed

std::thread memory leaks #12988

emaxx-google opened this issue Dec 7, 2020 · 2 comments

Comments

@emaxx-google
Copy link

Sample program:

#include <thread>
int main() {
  std::thread([]{}).detach();
}

Compilation flags:

emcc main.cc -pthread -fsanitize=address -s INITIAL_MEMORY=134217728 -s EXIT_RUNTIME=1

Result (Emscripten 2.0.9):

=================================================================
==42==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x22f9f in wasm-function[675]+0x22f9f (a.out.wasm+0x22f9f)
    #1 0x1840 in wasm-function[57]+0x1840 (a.out.wasm+0x1840)
    #2 0x166d in wasm-function[56]+0x166d (a.out.wasm+0x166d)
    #3 0x3b9a in wasm-function[123]+0x3b9a (a.out.wasm+0x3b9a)
    #4 0x80000510  (JavaScript+0x510)
    #5 0x80001bd0 in callMain a.out.js:7120:13
    #6 0x80001bf6 in doRun a.out.js:7158:21
    #7 0x80001c02 in run a.out.js:7170:3

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x22f9f in wasm-function[675]+0x22f9f (a.out.wasm+0x22f9f)
    #1 0x8dd4 in wasm-function[225]+0x8dd4 (a.out.wasm+0x8dd4)
    #2 0x182c in wasm-function[57]+0x182c (a.out.wasm+0x182c)
    #3 0x166d in wasm-function[56]+0x166d (a.out.wasm+0x166d)
    #4 0x3b9a in wasm-function[123]+0x3b9a (a.out.wasm+0x3b9a)
    #5 0x80000510  (JavaScript+0x510)
    #6 0x80001bd0 in callMain a.out.js:7120:13
    #7 0x80001bf6 in doRun a.out.js:7158:21

Indirect leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x22f9f in wasm-function[675]+0x22f9f (a.out.wasm+0x22f9f)
    #1 0x1825 in wasm-function[57]+0x1825 (a.out.wasm+0x1825)
    #2 0x166d in wasm-function[56]+0x166d (a.out.wasm+0x166d)
    #3 0x3b9a in wasm-function[123]+0x3b9a (a.out.wasm+0x3b9a)
    #4 0x80000510  (JavaScript+0x510)
    #5 0x80001bd0 in callMain a.out.js:7120:13
    #6 0x80001bf6 in doRun a.out.js:7158:21
    #7 0x80001c02 in run a.out.js:7170:3

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 3 allocation(s).
@emaxx-google
Copy link
Author

emaxx-google commented Dec 7, 2020

Symbolized traces (obtained with -O0 -g3):

=================================================================
==42==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x22f62 in operator new(unsigned long)+0x22f62 (a.out.wasm+0x22f62)
    #1 0x1803 in std::__2::thread::thread<main::$_0, void>(main::$_0&&) ../emsdk/upstream/emscripten/system/include/libcxx/thread:297:13
    #2 0x1630 in __original_main main-thread.cc:3:3
    #3 0x3b5d in main+0x3b5d (a.out.wasm+0x3b5d)
    #4 0x80000510  (JavaScript+0x510)
    #5 0x80001c53 in callMain a.out.js:7251:13
    #6 0x80001c79 in doRun a.out.js:7289:21
    #7 0x80001c85 in run a.out.js:7301:3

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x22f62 in operator new(unsigned long)+0x22f62 (a.out.wasm+0x22f62)
    #1 0x8d97 in std::__2::__thread_struct::__thread_struct()+0x8d97 (a.out.wasm+0x8d97)
    #2 0x17ef in std::__2::thread::thread<main::$_0, void>(main::$_0&&) ../emsdk/upstream/emscripten/system/include/libcxx/thread:294:22
    #3 0x1630 in __original_main main-thread.cc:3:3
    #4 0x3b5d in main+0x3b5d (a.out.wasm+0x3b5d)
    #5 0x80000510  (JavaScript+0x510)
    #6 0x80001c53 in callMain a.out.js:7251:13
    #7 0x80001c79 in doRun a.out.js:7289:21

Indirect leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x22f62 in operator new(unsigned long)+0x22f62 (a.out.wasm+0x22f62)
    #1 0x17e8 in std::__2::thread::thread<main::$_0, void>(main::$_0&&) ../emsdk/upstream/emscripten/system/include/libcxx/thread:294:18
    #2 0x1630 in __original_main main-thread.cc:3:3
    #3 0x3b5d in main+0x3b5d (a.out.wasm+0x3b5d)
    #4 0x80000510  (JavaScript+0x510)
    #5 0x80001c53 in callMain a.out.js:7251:13
    #6 0x80001c79 in doRun a.out.js:7289:21
    #7 0x80001c85 in run a.out.js:7301:3

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 3 allocation(s).

@emaxx-google
Copy link
Author

Can't reproduce this on 2.0.16 anymore, so presumably this got fixed in the meantime (maybe by the same fix as #12985).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant