libbpf: Fix memory leak and optimize BTF sanitization

Coverity's static analysis helpfully reported a memory leak introduced by
0f0e55d8247c ("libbpf: Improve BTF sanitization handling"). While fixing it,
I realized that btf__new() already creates a memory copy, so there is no need
to do this. So this patch also fixes misleading btf__new() signature to make
data into a `const void *` input parameter. And it avoids unnecessary memory
allocation and copy in BTF sanitization code altogether.

Fixes: 0f0e55d8247c ("libbpf: Improve BTF sanitization handling")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200710011023.1655008-1-andriin@fb.com
This commit is contained in:
Andrii Nakryiko
2020-07-09 18:10:23 -07:00
committed by Andrii Nakryiko
parent 8b5e81a17a
commit 5255eb2799
3 changed files with 5 additions and 10 deletions

View File

@@ -397,7 +397,7 @@ void btf__free(struct btf *btf)
free(btf);
}
struct btf *btf__new(__u8 *data, __u32 size)
struct btf *btf__new(const void *data, __u32 size)
{
struct btf *btf;
int err;