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

ASAN detected memory leaks at strange position. #789

Closed
yangluoshen opened this issue Mar 27, 2017 · 3 comments
Closed

ASAN detected memory leaks at strange position. #789

yangluoshen opened this issue Mar 27, 2017 · 3 comments

Comments

@yangluoshen
Copy link

Hello everybody,I'm new for ASAN and I get some trouble while using ASAN. Could anybody give me a hand? Thanks a lot!!!

My machine infomation:

# uname -a
Linux SZX1000064851 3.0.76-0.11-default #1 SMP Fri Jun 14 08:21:43 UTC 2013 (ccab990) x86_64 x86_64 x86_64 GNU/Linu
# cat /proc/version
Linux version 3.0.76-0.11-default (geeko@buildhost) (gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ) #1 SMP Fri Jun 14 08:21:43 UTC 2013 (ccab990)

and I installed gcc-6.2.0 on /opt/gcc-6.2.0/
I set the LD_LIBRARY_PATH and LD_PRELOAD like following:

# echo $LD_LIBRARY_PATH
:/opt/gmp-6.1.1/lib/:/opt/mpfr-3.1.5/lib/:/opt/mpc-1.0.3/lib/:/opt/gcc-6.2.0/lib64/:/opt/gcc-6.2.0/lib/
# echo $LD_PRELOAD
/opt/gcc-6.2.0/lib64/libasan.so.3
# ulimit -v
unlimited

Then I make the main.c

# cat main.c
int main()
{
int a[2] = {0, 1};
int b = a[2];
return 0;
}

compile like this:

#/opt/gcc-6.2.0/bin/gcc -fsanitize=address -ggdb -o main main.c

And finally I GOT:

# /opt/gcc-6.2.0/bin/gcc -fsanitize=address -ggdb -o main main.c

=================================================================
==27977==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 120 byte(s) in 8 object(s) allocated from:
#0 0x7f7037c9edd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x108f3a7 in xmalloc ../../libiberty/xmalloc.c:148

Direct leak of 32 byte(s) in 4 object(s) allocated from:
#0 0x7f7037c9edd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x108f3a7 in xmalloc ../../libiberty/xmalloc.c:148
#2 0x1ffffffffffffff ()

Direct leak of 14 byte(s) in 2 object(s) allocated from:
#0 0x7f7037c9edd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x108f3a7 in xmalloc ../../libiberty/xmalloc.c:148
#2 0x60800000289f ()

Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x7f7037c9edd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x108f3a7 in xmalloc ../../libiberty/xmalloc.c:148
#2 0x60400000ac0f ()

Direct leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x7f7037c9edd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x108f3a7 in xmalloc ../../libiberty/xmalloc.c:148
#2 0x10001ffff ()

SUMMARY: AddressSanitizer: 181 byte(s) leaked in 16 allocation(s).

=================================================================
==27976==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 247 byte(s) in 4 object(s) allocated from:
#0 0x7f9a3c537dd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x466d97 in xmalloc ../../libiberty/xmalloc.c:148

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
#0 0x7f9a3c537dd8 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cc:62
#1 0x466d97 in xmalloc ../../libiberty/xmalloc.c:148

SUMMARY: AddressSanitizer: 263 byte(s) leaked in 5 allocation(s).

@chefmax
Copy link

chefmax commented Mar 27, 2017

This happens because you preload ASan library to GCC and it detects leaks there (AFAIK those are known and ignored in community). Why do you need LD_PRELOAD at all? To run your binary (main) under ASan it's simply enough to compile it with -fsanitize=address flag.

@yangluoshen
Copy link
Author

@chefmax Thanks for response
I unset LD_PRELOAD, I get the error following:

# export LD_PRELOAD=
# echo $LD_PRELOAD

# /opt/gcc-6.2.0/bin/gcc  -fsanitize=address -ggdb -o main main.c
# ./main
==92213==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

@yangluoshen
Copy link
Author

Ha~ I found I works while I set LD_PRELOAD before run ./main and after compile main.c, like following:

# export LD_PRELOAD=
# /opt/gcc-6.2.0/bin/gcc  -fsanitize=address -ggdb -o main main.c
# export LD_PRELOAD=/opt/gcc-6.2.0/lib64/libasan.so.3
# ./main
=================================================================
==100519==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff8b699c38 at pc 0x000000400967 bp 0x7fff8b699bf0 sp 0x7fff8b699be8
READ of size 4 at 0x7fff8b699c38 thread T0
    #0 0x400966 in main /usr1/Fizz/up/mycode/workspace/test/gcc/main.c:4
    #1 0x7f66b4788c35 in __libc_start_main (/lib64/libc.so.6+0x1ec35)
    #2 0x400768  (/usr1/Fizz/up/mycode/workspace/test/gcc/main+0x400768)

Address 0x7fff8b699c38 is located in stack of thread T0 at offset 40 in frame
    #0 0x4008b7 in main /usr1/Fizz/up/mycode/workspace/test/gcc/main.c:2

@chefmax , Thank you really!

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

2 participants