lib: bpf_legacy: avoid to pass invalid argument to close()

In function bpf_obj_open, if bpf_fetch_prog_arg() return an error, we
end up in the out: path with a negative value for fd, and pass it to
close.

Avoid this checking for fd to be positive.

Fixes: 32e93fb7f6 ("{f,m}_bpf: allow for sharing maps")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
This commit is contained in:
Andrea Claudi 2021-05-01 19:05:45 +02:00 committed by David Ahern
parent a2f1f66075
commit 3296d4fe77
1 changed files with 1 additions and 1 deletions

View File

@ -2992,7 +2992,7 @@ static int bpf_obj_open(const char *pathname, enum bpf_prog_type type,
out:
bpf_elf_ctx_destroy(ctx, ret < 0);
if (ret < 0) {
if (fd)
if (fd >= 0)
close(fd);
return ret;
}