老师,我运行:$ /usr/share/bcc/tools/memleak -a -p $(pidof app) 并没有看到内存泄漏的问题。之后还看了app的源码。源码内的确没有调用free()函数。请问这可能是什么情况?
root@ubuntu:/# /usr/share/bcc/tools/memleak -p $(pidof app) -a
Attaching to pid 84307, Ctrl+C to quit.
[02:42:22] Top 10 stacks with outstanding allocations:
[02:42:27] Top 10 stacks with outstanding allocations:
[02:42:32] Top 10 stacks with outstanding allocations:
[02:42:37] Top 10 stacks with outstanding allocations:
[02:42:43] Top 10 stacks with outstanding allocations:
[02:42:48] Top 10 stacks with outstanding allocations:
[02:42:53] Top 10 stacks with outstanding allocations:
[02:42:58] Top 10 stacks with outstanding allocations:
[02:43:03] Top 10 stacks with outstanding allocations:
^Croot@ubuntu:/# docker exec app cat /app.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
long long *fibonacci(long long *n0, long long *n1)
{
long long *v = (long long *) calloc(1024, sizeof(long long));
*v = *n0 + *n1;
return v;
}
void *child(void *arg)
{
long long n0 = 0;
long long n1 = 1;
long long *v = NULL;
for (int n = 2; n > 0; n++) {
v = fibonacci(&n0, &n1);
n0 = n1;
n1 = *v;
printf("%dth => %lld\n", n, *v);
sleep(1);
}
}
int main(void)
{
pthread_t tid;
pthread_create(&tid, NULL, child, NULL);
pthread_join(tid, NULL);
printf("main thread exit\n");
return 0;
展开