From: Tobias Klauser Date: Wed, 10 Jun 2020 13:08:04 +0000 (+0200) Subject: tools, bpftool: Fix memory leak in codegen error cases X-Git-Tag: v5.15~3561^2~2^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4060ac969563113101c79433f2ae005feca1c29;p=platform%2Fkernel%2Flinux-starfive.git tools, bpftool: Fix memory leak in codegen error cases Free the memory allocated for the template on error paths in function codegen. Signed-off-by: Tobias Klauser Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20200610130804.21423-1-tklauser@distanz.ch --- diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index a3c4bb86..ecbae47 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -224,6 +224,7 @@ static int codegen(const char *template, ...) } else { p_err("unrecognized character at pos %td in template '%s'", src - template - 1, template); + free(s); return -EINVAL; } } @@ -234,6 +235,7 @@ static int codegen(const char *template, ...) if (*src != '\t') { p_err("not enough tabs at pos %td in template '%s'", src - template - 1, template); + free(s); return -EINVAL; } }