tools: bpftool: Add missing close before bpftool net attach exit
Subsystems (4)
PATCH 1/1 tools: bpftool: Add missing close before bpftool net attach exit
progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.
--- tools/bpf/bpftool/net.c | 2 ++ 1 file changed, 2 insertions(+)
tools/bpf/bpftool/net.c +2 -0
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)if (err <0 ) {p_err ("interface %s attach failed: %s" , attach_type_strings[attach_type],strerror (-err)); +close (progfd);return err; }if (json_output)jsonw_null (json_wtr); +close (progfd);return 0 ; }
Signature · 1 line
2.17.1
Quoted 5 lines · Wang Hai
progfd is created by
prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")Signed-off-by Wang Hai <[email protected]>
Thanks!
Quentin
Quoted 18 lines · Wang Hai
progfd is created by
prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")Signed-off-by Wang Hai <[email protected]>--- tools/bpf/bpftool/net.c | 2 ++ 1 file changed, 2 insertions(+)tools/bpf/bpftool/net.c +1
-0@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)if (err <0 ) {p_err ("interface %s attach failed: %s" , attach_type_strings[attach_type],strerror (-err)); +close (progfd);
tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 613
Quoted 10 lines
tools/bpf/bpftool/net.c +1
-0return err; }if (json_output)jsonw_null (json_wtr); +close (progfd);return 0 ; }
Nit - wouldn't it be better to create a cleanup/out section before return and use goto, to avoid copying the close call?
Quoted 25 lines · Michal Rostecki
Quoted 24 lines · Wang Hai
progfd is created by
prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")Signed-off-by Wang Hai <[email protected]>--- tools/bpf/bpftool/net.c | 2 ++ 1 file changed, 2 insertions(+)tools/bpf/bpftool/net.c +1
-0@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)if (err <0 ) {p_err ("interface %s attach failed: %s" , attach_type_strings[attach_type],strerror (-err)); +close (progfd);return err; }if (json_output)jsonw_null (json_wtr);
Quoted 7 lines
tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 613
Quoted 4 lines
tools/bpf/bpftool/net.c +1
-0+close (progfd);return 0 ; }Nit - wouldn't it be better to create a
cleanup/outsection before return and use goto, to avoid copying theclosecall?
I agree would be nicer.
Quoted 21 lines · Michal Rostecki
Quoted 20 lines · Wang Hai
progfd is created by
prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")Signed-off-by Wang Hai <[email protected]>---
tools/bpf/bpftool/net.c| 2 ++1 file changed, 2 insertions(+)tools/bpf/bpftool/net.c +1
-0@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv) if (err < 0) { p_err("interface %s attach failed: %s", attach_type_strings[attach_type], strerror(-err)); + close(progfd); return err; }
Quoted 9 lines
tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 612
Quoted 5 lines
tools/bpf/bpftool/net.c +0
-0if (json_output) jsonw_null(json_wtr); + close(progfd); return 0; }Nit - wouldn't it be better to create a
cleanup/outsection before return and use goto, to avoid copying theclosecall? .
Thanks for review. I just sent v2 patch
"[PATCH v2 bpf] tools: bpftool: Add missing close before bpftool net attach exit"