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
int main() {
// static
int &a = *(new int);
// delete &a;
}
Hi, if i add the static keyword for the declaration
static int &a = *(new int);
it will not report memory leak.
Is this usage c++ standard conformant behavior?
Thanks
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$
$ make
g++ -fsanitize=address -std=c++23 -g -MMD -MP -c -o main.o main.cpp
g++ -fsanitize=address main.o -o main
$
$ src/main/main
==2864==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1 byte(s) in 1 object(s) allocated from:
#0 0x7f25158f84b8 in operator new(unsigned long) (/lib64/libasan.so.8+0xf84b8) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)
#1 0x40117f in Foo::fun() /home/ljh/Documents/hello_cpp/src/main/main.cpp:6
#2 0x401152 in main /home/ljh/Documents/hello_cpp/src/main/main.cpp:12
#3 0x7f2515239087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#4 0x7f251523914a in __libc_start_main_alias_1 (/lib64/libc.so.6+0x2a14a) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#5 0x401084 in _start (/home/ljh/Documents/hello_cpp/src/main/main+0x401084) (BuildId: cddb8fb48744ed0ccb7673c7537b966fe25c3d5c)
SUMMARY: AddressSanitizer: 1 byte(s) leaked in 1 allocation(s).
$
The text was updated successfully, but these errors were encountered:
lijh8
changed the title
No leak report on this usage static Foo &fun = *(new Foo());
No leak report on this usage: static Foo &fun = *(new Foo()); Oct 17, 2024
lijh8
changed the title
No leak report on this usage: static Foo &fun = *(new Foo());
No leak report on this usage: static int &a = *(new int); Oct 18, 2024
Hi, if i add the static keyword for the declaration
it will not report memory leak.
Is this usage c++ standard conformant behavior?
Thanks
The text was updated successfully, but these errors were encountered: