From: Tobias Klauser <[email protected]>

[ Upstream commit d4060ac969563113101c79433f2ae005feca1c29 ]

Free the memory allocated for the template on error paths in function
codegen.

Signed-off-by: Tobias Klauser <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
---
 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 f8113b3646f52..f5960b48c8615 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -225,6 +225,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;
                }
        }
@@ -235,6 +236,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.25.1



Reply via email to