tools: bpftool: remember to close the libbpf object after prog load

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: 49a086c201 ("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>
This commit is contained in:
Jakub Kicinski 2018-06-20 11:42:46 -07:00 committed by Daniel Borkmann
parent 957f9a13df
commit bfee71fb73

View 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)