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

No leak report on this usage: static int &a = *(new int); #1806

Open
lijh8 opened this issue Oct 17, 2024 · 0 comments
Open

No leak report on this usage: static int &a = *(new int); #1806

lijh8 opened this issue Oct 17, 2024 · 0 comments

Comments

@lijh8
Copy link

lijh8 commented Oct 17, 2024

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).
$ 
@lijh8 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 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
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