Is this a feature or a bug in ASAN? If I have this code:
class Foo {
int x = 5;
int z = 10;
};
int main() {
void *memory = malloc(sizeof(Foo));
Foo *ptr = new(memory) Foo();
ptr = nullptr;
}
ASAN reports no leaks. If I remove the Foo *ptr = new(memory) Foo(); suddenly I get leak:
Direct leak of 8 byte(s) in 1 object(s) allocated from:
0x7f00b7a80a89 __interceptor_malloc asan_malloc_linux.cpp:69
0x55dfa164d1ca main main.cpp:12
0x7f00b74a72cf (libc.so.6+0x232cf)
Compiler version: c++ (GCC) 12.2.0
Compile commands:
[1/2] /usr/sbin/c++ -g -fsanitize=address -fsanitize=leak -std=gnu++14 -MD -MT CMakeFiles/test.dir/main.cpp.o -MF CMakeFiles/test.dir/main.cpp.o.d -o CMakeFiles/test.dir/main.cpp.o -c /src/self/test/main.cpp
[2/2] : && /usr/sbin/c++ -g -fsanitize=address -fsanitize=leak CMakeFiles/test.dir/main.cpp.o -o test && :
OS: Linux WORKSTATION 5.19.4-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 25 Aug 2022 17:31:19 +0000 x86_64 GNU/Linux