Skip to content

Commit d4060ac

Browse files
tklauserborkmann
authored andcommitted
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bd6fecb commit d4060ac

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/bpf/bpftool/gen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static int codegen(const char *template, ...)
224224
} else {
225225
p_err("unrecognized character at pos %td in template '%s'",
226226
src - template - 1, template);
227+
free(s);
227228
return -EINVAL;
228229
}
229230
}
@@ -234,6 +235,7 @@ static int codegen(const char *template, ...)
234235
if (*src != '\t') {
235236
p_err("not enough tabs at pos %td in template '%s'",
236237
src - template - 1, template);
238+
free(s);
237239
return -EINVAL;
238240
}
239241
}

0 commit comments

Comments
 (0)