tools: bpftool: remember to close the libbpf object after prog load
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 20 Jun 2018 18:42:46 +0000 (11:42 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 21 Jun 2018 21:07:13 +0000 (23:07 +0200)
Remembering to close all descriptors and free memory may not seem
important in a user space tool like bpftool, but if we were to run
in batch mode the consumed resources start to add up quickly.  Make
sure program load closes the libbpf object (which unloads and frees
it).

Fixes: 49a086c201a9 ("bpftool: implement prog load command")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/bpf/bpftool/prog.c

index 12b694f..959aa53 100644 (file)
@@ -695,12 +695,18 @@ static int do_load(int argc, char **argv)
        }
 
        if (do_pin_fd(prog_fd, argv[1]))
-               return -1;
+               goto err_close_obj;
 
        if (json_output)
                jsonw_null(json_wtr);
 
+       bpf_object__close(obj);
+
        return 0;
+
+err_close_obj:
+       bpf_object__close(obj);
+       return -1;
 }
 
 static int do_help(int argc, char **argv)