Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lsan] Fix leaks detected by sanitier
There were some leaks detected when running the test suite. But for `bcc_elf_get_buildid` which did not free the elf object, the rest of the leaks were isolated in the tests themselves which did not free some resources here and there. This diff clears those leaks. This will allow running the tests suite in the future with LSAN enabled, helping in catching possible future leaks earlier. Ran the sanitizer using: ``` docker run --privileged \ --pid=host \ -v $(pwd):/bcc \ -v /sys/kernel/debug:/sys/kernel/debug:rw \ -v /lib/modules:/lib/modules:ro \ -v /usr/src:/usr/src:ro \ -v /usr/include/linux:/usr/include/linux:ro \ bcc-docker \ /bin/bash -c \ 'mkdir -p /bcc/build && cd /bcc/build && \ cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_LLVM_NATIVECODEGEN=OFF -DCMAKE_SANITIZE_TYPE=leak .. && make -j9' ``` followed by tests. Before: ``` docker run -ti \ --privileged \ --network=host \ --pid=host \ -v $(pwd):/bcc \ -v /sys/kernel/debug:/sys/kernel/debug:rw \ -v /lib/modules:/lib/modules:ro \ -v /usr/src:/usr/src:ro \ -e CTEST_OUTPUT_ON_FAILURE=1 \ bcc-docker \ /bin/bash -c \ '/bcc/build/tests/wrapper.sh \ c_test_all sudo /bcc/build/tests/cc/test_libbcc' > /tmp/out grep 'Indirect leak' /tmp/out | wc -l 99 grep 'Direct leak' /tmp/out | wc -l 4 ``` Full out file available in https://gist.github.com/chantra/caa3c6f6a274895d8743fe9e48a7c528 After: ``` docker run -ti \ --privileged \ --network=host \ --pid=host \ -v $(pwd):/bcc \ -v /sys/kernel/debug:/sys/kernel/debug:rw \ -v /lib/modules:/lib/modules:ro \ -v /usr/src:/usr/src:ro \ -e CTEST_OUTPUT_ON_FAILURE=1 \ bcc-docker \ /bin/bash -c \ '/bcc/build/tests/wrapper.sh \ c_test_all sudo /bcc/build/tests/cc/test_libbcc' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test_libbcc is a Catch v1.4.0 host application. Run with -? for options ------------------------------------------------------------------------------- searching for modules in /proc/[pid]/maps ------------------------------------------------------------------------------- /bcc/tests/cc/test_c_api.cc:497 ............................................................................... /bcc/tests/cc/test_c_api.cc:499: FAILED: REQUIRE( dummy_maps != __null ) with expansion: NULL != 0 ------------------------------------------------------------------------------- test bpf table ------------------------------------------------------------------------------- /bcc/tests/cc/test_bpf_table.cc:24 ............................................................................... /bcc/tests/cc/test_bpf_table.cc:24: FAILED: {Unknown expression after the reported line} due to unexpected exception with message: bad_function_call ------------------------------------------------------------------------------- test bpf percpu tables ------------------------------------------------------------------------------- /bcc/tests/cc/test_bpf_table.cc:94 ............................................................................... /bcc/tests/cc/test_bpf_table.cc:94: FAILED: {Unknown expression after the reported line} due to unexpected exception with message: bad_function_call ------------------------------------------------------------------------------- test bpf stack_id table ------------------------------------------------------------------------------- /bcc/tests/cc/test_bpf_table.cc:227 ............................................................................... /bcc/tests/cc/test_bpf_table.cc:268: FAILED: REQUIRE( addrs.size() > 0 ) with expansion: 0 > 0 Parse error: 4@i%ra+1r -------^ =============================================================================== test cases: 51 | 47 passed | 1 failed | 3 failed as expected assertions: 984 | 980 passed | 1 failed | 3 failed as expected Failed ```
- Loading branch information