You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The allocated memory is still reachable from a global variable (static Singleton& instance is a global), hence it is not considered a memory leak.
You can disable this behavior by passing LSAN_OPTIONS=use_globals=false:
$ g++ t.cc -o t -fsanitize=address
$ ./t
$ LSAN_OPTIONS=use_globals=false ./t
=================================================================
==3419665==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 73728 byte(s) in 1 object(s) allocated from:
#0 0x7f5a9b0f4cd7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f5a9acaf7ad (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaf7ad) (BuildId: 69568e25e14544c953a9f79da5e158d0f644ad17)
Direct leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x7f5a9b0f57f8 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
#1 0x5595797f32ad in Singleton::Instance() (/usr/local/google/src/TMP/linux/t+0x12ad) (BuildId: 2e9033784f7ac303257f0b2ef41da0de10472db6)
#2 0x5595797f31e5 in main (/usr/local/google/src/TMP/linux/t+0x11e5) (BuildId: 2e9033784f7ac303257f0b2ef41da0de10472db6)
#3 0x7f5a9aa40c89 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
SUMMARY: AddressSanitizer: 73729 byte(s) leaked in 2 allocation(s).
My program is as follows:
Test environment: WSL2 Ubuntu 20.04.3 x86_64-linux-gnu-g++ 9.3.0
The method I use AddressSanitizer is as follows:
or
The only delete expression
delete (&Singleton::Instance());
has been commented out in my program. So my program should have a memory leak.But, when I run the executable
a.out
, it outputs nothing.Why hasn't AddressSanitizer detected a memory leak in my program?
The text was updated successfully, but these errors were encountered: