Skip to content

Commit 50431b4

Browse files
Wang Haiborkmann
Wang Hai
authored andcommitted
tools, bpftool: Add missing close before bpftool net attach exit
progfd is created by prog_parse_fd() in do_attach() and before the latter returns in case of success, the file descriptor should be closed. Fixes: 04949cc ("tools: bpftool: add net attach command to attach XDP on interface") Signed-off-by: Wang Hai <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9602182 commit 50431b4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/bpf/bpftool/net.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,35 +578,35 @@ static int do_attach(int argc, char **argv)
578578

579579
ifindex = net_parse_dev(&argc, &argv);
580580
if (ifindex < 1) {
581-
close(progfd);
582-
return -EINVAL;
581+
err = -EINVAL;
582+
goto cleanup;
583583
}
584584

585585
if (argc) {
586586
if (is_prefix(*argv, "overwrite")) {
587587
overwrite = true;
588588
} else {
589589
p_err("expected 'overwrite', got: '%s'?", *argv);
590-
close(progfd);
591-
return -EINVAL;
590+
err = -EINVAL;
591+
goto cleanup;
592592
}
593593
}
594594

595595
/* attach xdp prog */
596596
if (is_prefix("xdp", attach_type_strings[attach_type]))
597597
err = do_attach_detach_xdp(progfd, attach_type, ifindex,
598598
overwrite);
599-
600-
if (err < 0) {
599+
if (err) {
601600
p_err("interface %s attach failed: %s",
602601
attach_type_strings[attach_type], strerror(-err));
603-
return err;
602+
goto cleanup;
604603
}
605604

606605
if (json_output)
607606
jsonw_null(json_wtr);
608-
609-
return 0;
607+
cleanup:
608+
close(progfd);
609+
return err;
610610
}
611611

612612
static int do_detach(int argc, char **argv)

0 commit comments

Comments
 (0)