From 2ee87a12ff959218f909fe54a83bc795190885dc Mon Sep 17 00:00:00 2001 From: Simon Sundberg Date: Mon, 5 Sep 2022 17:35:46 +0200 Subject: [PATCH] pping: Close bpf_object on shutdown/error Signed-off-by: Simon Sundberg --- pping/pping.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pping/pping.c b/pping/pping.c index 869d6a30..5cc61200 100644 --- a/pping/pping.c +++ b/pping/pping.c @@ -904,7 +904,7 @@ static int load_attach_bpfprogs(struct bpf_object **obj, fprintf(stderr, "Failed attaching ingress BPF program on interface %s: %s\n", config->ifname, get_libbpf_strerror(err)); - return err; + goto ingress_err; } // Attach egress prog @@ -935,6 +935,8 @@ static int load_attach_bpfprogs(struct bpf_object **obj, if (detach_err) fprintf(stderr, "Failed detaching ingress program from %s: %s\n", config->ifname, get_libbpf_strerror(detach_err)); +ingress_err: + bpf_object__close(*obj); return err; } @@ -1143,5 +1145,7 @@ int main(int argc, char *argv[]) "Failed removing egress program from interface %s: %s\n", config.ifname, get_libbpf_strerror(detach_err)); + bpf_object__close(obj); + return (err != 0 && keep_running) || detach_err != 0; }