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 】【Bug】【MemLeak】【12.1 and earlier gcc versions】There is a MemLeak problem in __interceptor__pthread_create function #1762

Open
langewin opened this issue Jun 4, 2024 · 0 comments

Comments

@langewin
Copy link

langewin commented Jun 4, 2024

In my demo code, Receive a user input parameter time microsecond, create an infinite loop, create a thread inside the loop, print the current time in the thread, and sleep the user input parameter time.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>

void *print_time(void *arg) {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    printf("Current time: %ld.%06ld", tv.tv_sec, tv.tv_usec);
    return NULL;
}

int main(int argc, char **argv) {
    if (argc != 2) {
        printf("Usage: %s <time in microseconds>", argv[0]);
        return -1;
    }
    long time_micro = atol(argv[1]);
    while (1) {
        pthread_t tid;
        pthread_create(&tid, NULL, print_time, NULL);
        usleep(time_micro);
    }
    return 0;
}

No matter how long I set the sleep interval, such as 200 microseconds, 1 second, 10 seconds, etc., the RssAnno physical memory of the program has a regular memory leak.
For the first time, 56 KB of physical memory is added to the AsanThread::Create application. Then, the memory is released in AsanThread::Destroy. An additional 60 KB memory is applied for the second time, but AsanThread::Destroy releases only 56 KB memory each time. As a result, 4 KB physical memory is leaked each time a thread is created twice.
This problem occurs in libasan.so of gcc10.3 and gcc12.1 of arm64 version.
Do you have a description and fix?
image
image

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