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

LeakSanitizer not working in gcc 4.8.2 #699

Closed
yyh-graphsql opened this issue Jul 22, 2016 · 14 comments
Closed

LeakSanitizer not working in gcc 4.8.2 #699

yyh-graphsql opened this issue Jul 22, 2016 · 14 comments

Comments

@yyh-graphsql
Copy link

yyh-graphsql commented Jul 22, 2016

First I just hard code a memory leak in the program. After I compiled the binary with -fsanitize=address. It showed nothing. Is it normal situation or Did I miss something?

@yugr
Copy link

yugr commented Jul 22, 2016

It's hard to say without an example. Note that leak detector is disabled on 32-bit platforms as it's considered to not be reliable there.

@yyh-graphsql
Copy link
Author

@yugr The platform of our system is 64bits. It's centos 7.1.(Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux). And the hacked leak code is just "int *a = new int (4);" in a function definitely will invoked

@yugr
Copy link

yugr commented Jul 22, 2016

Just to check, could you try with

volatile int *a = new int (4);
a = 0;

?

@yyh-graphsql
Copy link
Author

yyh-graphsql commented Jul 22, 2016

The code:
#include
int main() {
volatile int *a = new int(3);
a = 0;
return 0;
}

compile: g++ -fsanitize=address -o 1 /tmp/1.cpp
run: ASAN_OPTIONS='detect_leaks=1' ./1
output: 'nothing'

@yyh-graphsql
Copy link
Author

Is it related to the libasan's version ?

@chefmax
Copy link

chefmax commented Jul 22, 2016

Yes, AFAIK LSan is available in GCC 4.9+.

@chefmax
Copy link

chefmax commented Jul 22, 2016

gcc-4_8-branch doesn't even contain libsanitizer/lsan/ directory. Please try more recent GCC versions.

@yyh-graphsql
Copy link
Author

Let me try gcc 4.9. Thanks a lot!

@chefmax
Copy link

chefmax commented Jul 22, 2016

Closing then.

@chefmax chefmax closed this as completed Jul 22, 2016
@rootkea
Copy link

rootkea commented Mar 30, 2017

I'm using gcc 4.9.2 and no. -fsanitizer=address doesn't report memory leak. You need -fsanitizer=leak for that.

Here is an interesting bit (bug?) with gcc 4.9.2 though. -fsanitizer=leak doesn't work with -fsanitizer=address. Yes! Weird!

@kcc
Copy link
Contributor

kcc commented Mar 30, 2017

@rootkea lsan is enabled as part of asan, so if you have -fsanitizer=address leak detection is enabled.
(not sure about 4.9.2, maybe it's too old).
-fsanitizer=leak is a way to enable just lsan, w/o asan.
You can not pass both -fsanitizer=leak and -fsanitizer=address

@chefmax
Copy link

chefmax commented Mar 30, 2017

Hm, it seems that for gcc 4.9 LSan is disabled by default when using with ASan. Use ASAN_OPTIONS=detect_leaks=1 to enable leak detection.

@rootkea
Copy link

rootkea commented Mar 30, 2017

Use ASAN_OPTIONS=detect_leaks=1 to enable leak detection

I did ASAN_OPTIONS=detect_leaks=1. Then gcc foo.c -fsanitize=address -o foo. After which ./foo gets executed smoothly. It's only when I use -fsanitize=leak it shows memory leak.

@hyyeah
Copy link

hyyeah commented Sep 15, 2017

I have the same problem with rootkea

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

6 participants