tools: bpftool: close prog FD before exit on showing a single program
authorQuentin Monnet <quentin.monnet@netronome.com>
Thu, 15 Aug 2019 14:22:23 +0000 (15:22 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 16 Aug 2019 05:09:41 +0000 (22:09 -0700)
When showing metadata about a single program by invoking
"bpftool prog show PROG", the file descriptor referring to the program
is not closed before returning from the function. Let's close it.

Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/bpf/bpftool/prog.c

index 66f04a4846a587e8e48bf3a599082ee48c452c19..43fdbbfe41bb24eef44e91c984c4dd30f41a6798 100644 (file)
@@ -363,7 +363,9 @@ static int do_show(int argc, char **argv)
                if (fd < 0)
                        return -1;
 
-               return show_prog(fd);
+               err = show_prog(fd);
+               close(fd);
+               return err;
        }
 
        if (argc)