Skip to content

Commit

Permalink
libbpf: Fix memory leak in btf__dedup()
Browse files Browse the repository at this point in the history
Free btf_dedup if btf_ensure_modifiable() returns error.

Fixes: 919d2b1 ("libbpf: Allow modification of BTF and add btf__add_str API")
Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211022202035.48868-1-mauricio@kinvolk.io
  • Loading branch information
Mauricio Vásquez authored and Andrii Nakryiko committed Oct 22, 2021
1 parent 57385ae commit 1000298
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/lib/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2991,8 +2991,10 @@ int btf__dedup(struct btf *btf, struct btf_ext *btf_ext,
return libbpf_err(-EINVAL);
}

if (btf_ensure_modifiable(btf))
return libbpf_err(-ENOMEM);
if (btf_ensure_modifiable(btf)) {
err = -ENOMEM;
goto done;
}

err = btf_dedup_prep(d);
if (err) {
Expand Down

0 comments on commit 1000298

Please sign in to comment.