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

AddressSanitizer: SEGV in malloc_trim #1721

Open
btomorrowb opened this issue Jan 18, 2024 · 0 comments
Open

AddressSanitizer: SEGV in malloc_trim #1721

btomorrowb opened this issue Jan 18, 2024 · 0 comments

Comments

@btomorrowb
Copy link

The code shown as below:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <malloc.h>

void* thread_function(void* arg) {
char* ptr = (char *)malloc(10);
printf("%p\n", ptr);
free(ptr);
malloc_trim(0);
pthread_exit(NULL);
}

int main() {
pthread_t threads[2];

for (long i = 0; i < 2; ++i) {
    pthread_create(&threads[i], NULL, thread_function, (void*)i);
}
for (int i = 0; i < 2; ++i) {
    pthread_join(threads[i], NULL);
}
return 0;

}
use gcc -pthread -o ASANtest -fsanitize=address -O1 test.c to compile.
I find the error message:
bash-4.4$ ./ASANtest
ASAN:DEADLYSIGNAL
=================================================================
==7076==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7f95439d87d9 bp 0x000000000fff sp 0x7f953f8fde00 T2)
==7076==The signal is caused by a READ memory access.
==7076==Hint: address points to the zero page.
#0 0x7f95439d87d8 in malloc_trim (/lib64/libc.so.6+0x9e7d8)
#1 0x400a8f in thread_function (/workspace/git/ehaauwn/PCPB-22713/2024/eric-pc-routing-engine/raas/product/docker/build/ASANtest+0x400a8f)
#2 0x7f9543d396e9 in start_thread (/lib64/libpthread.so.0+0xa6e9)
#3 0x7f9543a51a8e in clone (/lib64/libc.so.6+0x117a8e)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0x9e7d8) in malloc_trim
Thread T2 created by T0 here:
#0 0x7f9543f8bc80 in pthread_create (/usr/lib64/libasan.so.4+0x39c80)
#1 0x400b32 in main (/workspace/git/ehaauwn/PCPB-22713/2024/eric-pc-routing-engine/raas/product/docker/build/ASANtest+0x400b32)
#2 0x400d13 in _IO_stdin_used (/workspace/git/ehaauwn/PCPB-22713/2024/eric-pc-routing-engine/raas/product/docker/build/ASANtest+0x400d13)

==7076==ABORTING 
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