iovisor / iovisor/bcc

Bcc tools memleak can not identify memory leaks by new operator under tcmalloc library?

Open
#4,777 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

I used tcmalloc as a memory allocator, and then after new memory, it was not reclaimed and was not recognized by the bcc tool `memleak`.

```c++
// leak_lib.cpp
namespace LeakLib {
void slowMemoryLeak() {
int oneMbSize = 262144;
while (true) {
int* p = new int[262144];
for (int i = 0; i < 262144; ++i) {
p[i] = i; // Assign values to occupy physical memory
}
sleep(1); // wait for 1 second
}
}
}
```

```c++
// main.cpp
#include

namespace LeakLib {
void slowMemoryLeak();
}

int caller() {
std::cout << "In caller" << std::endl;
LeakLib::slowMemoryLeak();
return 0;
}
int main() {
std::cout << "Starting slow memory leak program..." << std::endl;
caller();
return 0;
}
```

Makefile:

```
all: main

main: main.o libLeak.a
g++ -o main main.o -L. -lLeak -ltcmalloc -Wl,-rpath,/usr/local/lib -fno-omit-frame-pointer

main.o: main.cpp
g++ -c main.cpp -fno-omit-frame-pointer -g

libLeak.a: leak_lib.o
ar rcs libLeak.a leak_lib.o

leak_lib.o: leak_lib.cpp
g++ -c leak_lib.cpp -o leak_lib.o -fno-omit-frame-pointer -g

clean:
rm -f *.o *.a main
```

Here's the output of memleak

```shell
$ memleak -p $(pgrep main) --combined-only
Attaching to pid 1118961, Ctrl+C to quit.
[19:28:55] Top 10 stacks with outstanding allocations:

[19:29:00] Top 10 stacks with outstanding allocations:

[19:29:05] Top 10 stacks with outstanding allocations:

[19:29:10] Top 10 stacks with outstanding allocations:
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the supplied leak_lib.cpp/main.cpp program and Makefile with tcmalloc, then run the memleak entry point using the shown command. Done means the bcc memleak tool identifies the outstanding allocations in this reproducer; the payload names no repository file or test, so the relevant implementation and regression coverage still need to be located.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
observability, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.