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

The program compiled and run with lsan alone reports an error. #1710

Closed
chengkexincccccck opened this issue Nov 30, 2023 · 7 comments
Closed

Comments

@chengkexincccccck
Copy link

I have written some test programs for memory leaks as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[]) {
char s = (char)malloc(100);
strcpy(s, "Hello world!");
printf("string is: %s\n", s);
return 0;
}
And I compiled it using 'g++ test_asan.cpp -o testasan -fsanitize=leak'. However, I got the following error message:

==2691129==Sanitizer CHECK failed: ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:53 ((!lsan_init_is_running)) != (0) (0, 0)

What could be the reason for this error? Some online resources suggest that it could be due to a lower version of g++, but my g++ version is ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0.‘

@sT331h0rs3
Copy link

sT331h0rs3 commented Dec 11, 2023

I also encountered the same, but with GCC version 11.4:

#include <stdio.h>
int main() {
    printf("Hello world!!!");
}
$ gcc -fsanitize=leak hello.c -o hello
$ ./hello
==15193==Sanitizer CHECK failed: ../../../../libsanitizer/lsan/lsan_interceptors.cpp:55 ((!lsan_init_is_running)) != (0) (0, 0)

Similar issue: magma/magma#15279.

@qianfei11
Copy link

Same on ubuntu 20.04:

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

code:

int main()
{
    int a = 1;
    while (1) {
    }
    return 0;
}

result:

$ gcc  1.c -fsanitize=leak -o 1
$ ./1 
==118723==Sanitizer CHECK failed: ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:53 ((!lsan_init_is_running)) != (0) (0, 0)

@whateverforever
Copy link

Same issue

g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@Zard-C
Copy link

Zard-C commented Apr 17, 2024

With installation with g++-11, it works

$ g++-11 test_lsan.cpp -o test_lsan -fsanitize=leak
$ ./test_lsan 
string is: Hello world!

=================================================================
==8638==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 100 byte(s) in 1 object(s) allocated from:
    #0 0x7f589f51b3e2 in __interceptor_malloc ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:75
    #1 0x564f46478185 in main (/root/test_lsan+0x1185) (BuildId: b09a28a290e7752830e73c6d1988d7c99c13d25e)
    #2 0x7f589ef57082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: eebe5d5f4b608b8a53ec446b63981bba373ca0ca)

SUMMARY: LeakSanitizer: 100 byte(s) leaked in 1 allocation(s).

Maybe we can close this issue.

@Zard-C
Copy link

Zard-C commented Apr 17, 2024

$ gcc -fsanitize=leak hello.c -o hello

I am not sure that if you are really using gcc-11, try using gcc-11 -fsanitize=leak hello.c -o hello

@sonulohani
Copy link

gcc-9 has the issue, gcc-11 doesn't

@ramosian-glider
Copy link
Member

Does not reproduce for me on Godbolt: https://godbolt.org/z/bnvjGov9T (with neither GCC 9.4, nor any newer version)

Closing per the above comments.

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

7 participants