diff mbox series

[bpf] tools, bpftool: Fix memory leak in codegen error cases

Message ID 20200610130804.21423-1-tklauser@distanz.ch
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf] tools, bpftool: Fix memory leak in codegen error cases | expand

Commit Message

Tobias Klauser June 10, 2020, 1:08 p.m. UTC
Free the memory allocated for the template on error paths in function
codegen.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 tools/bpf/bpftool/gen.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Andrii Nakryiko June 10, 2020, 6:31 p.m. UTC | #1
On Wed, Jun 10, 2020 at 6:10 AM Tobias Klauser <tklauser@distanz.ch> wrote:
>
> Free the memory allocated for the template on error paths in function
> codegen.
>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  tools/bpf/bpftool/gen.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index a3c4bb86c05a..ecbae47e66b8 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;
>                         }
>                 }
> --
> 2.27.0
>
Daniel Borkmann June 11, 2020, 2:24 p.m. UTC | #2
On 6/10/20 3:08 PM, Tobias Klauser wrote:
> Free the memory allocated for the template on error paths in function
> codegen.
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

Applied, thanks!
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index a3c4bb86c05a..ecbae47e66b8 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;
 			}
 		}