On Wed, May 29, 2024 at 04:12:12PM -0700, Andrii Nakryiko wrote: > Guard close(link_fd) with extra link_fd >= 0 check to prevent close(-1). > > Detected by Coverity static analysis. > > Fixes: 04d939a2ab22 ("libbpf: detect broken PID filtering logic for multi-uprobe") > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx> jirka > --- > tools/lib/bpf/features.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c > index 3df0125ed5fa..50befe125ddc 100644 > --- a/tools/lib/bpf/features.c > +++ b/tools/lib/bpf/features.c > @@ -393,7 +393,8 @@ static int probe_uprobe_multi_link(int token_fd) > err = -errno; /* close() can clobber errno */ > > if (link_fd >= 0 || err != -EBADF) { > - close(link_fd); > + if (link_fd >= 0) > + close(link_fd); > close(prog_fd); > return 0; > } > -- > 2.43.0 > >