mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-29 12:49:07 +08:00
libbpf: Make destructors more robust by handling ERR_PTR(err) cases
Most of libbpf "constructors" on failure return ERR_PTR(err) result encoded as a pointer. It's a common mistake to eventually pass such malformed pointers into xxx__destroy()/xxx__free() "destructors". So instead of fixing up clean up code in selftests and user programs, handle such error pointers in destructors themselves. This works beautifully for NULL pointers passed to destructors, so might as well just work for error pointers. Suggested-by: Song Liu <songliubraving@fb.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20200729232148.896125-1-andriin@fb.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
0466b9833b
commit
2dc7cbd893
@@ -183,7 +183,7 @@ void btf_dump__free(struct btf_dump *d)
|
||||
{
|
||||
int i, cnt;
|
||||
|
||||
if (!d)
|
||||
if (IS_ERR_OR_NULL(d))
|
||||
return;
|
||||
|
||||
free(d->type_states);
|
||||
|
||||
Reference in New Issue
Block a user