Open joyhou-hw opened 1 year ago
With std::thread
, you should either call std::thread::join
or std::thread::detach
, otherwise the runtime may invoke std::terminate
when the thread's destructor is called. Depending on the particular mechanism used to manage threads, this may or may not lead to leaks (or crashes!).
static near longTimeObj let compiler to eliminate that as global, so you have a leak report. Works as intended to me.
I did a simple analysis on Glibc OS. That 8-bit pointer addr exists in the stack space of the child thread. This causes asan to mark the content as reachable when scaning for stack space addresses. And, when only use the pthread interface to create a thread(in c, not c++), that leak will not reported in the MUSL OS.
Currently, May be only the std::thread and MUSL libraries report this leak. The leak pointer address is not found during stack scanning.
Looks likestd::thread
uses some features I don't know about?
The code use
std::thread
create a non return thread. while the main funciton not join this thread, and return directly.Compile with
-fsanitize=address
will report an 8-bit and 48-bit leak, that isthread_struct
and pointer, on musl Linux system. But will OK on glibc OS. I am not sure this is an issue in ASan or in musl libc.