mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 16:19:06 +08:00
libbpf: fix memory leak in attach_tp for target-less tracepoint program
Fix sec_name memory leak if user defines target-less SEC("tp").
Fixes: 9af8efc45eb1 ("libbpf: Allow "incomplete" basic tracing SEC() definitions")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20220516184547.3204674-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
12e932ac0e
commit
d43fc5a42f
@@ -11592,16 +11592,16 @@ static int attach_tp(const struct bpf_program *prog, long cookie, struct bpf_lin
|
|||||||
{
|
{
|
||||||
char *sec_name, *tp_cat, *tp_name;
|
char *sec_name, *tp_cat, *tp_name;
|
||||||
|
|
||||||
sec_name = strdup(prog->sec_name);
|
|
||||||
if (!sec_name)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
*link = NULL;
|
*link = NULL;
|
||||||
|
|
||||||
/* no auto-attach for SEC("tp") or SEC("tracepoint") */
|
/* no auto-attach for SEC("tp") or SEC("tracepoint") */
|
||||||
if (strcmp(prog->sec_name, "tp") == 0 || strcmp(prog->sec_name, "tracepoint") == 0)
|
if (strcmp(prog->sec_name, "tp") == 0 || strcmp(prog->sec_name, "tracepoint") == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
sec_name = strdup(prog->sec_name);
|
||||||
|
if (!sec_name)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
/* extract "tp/<category>/<name>" or "tracepoint/<category>/<name>" */
|
/* extract "tp/<category>/<name>" or "tracepoint/<category>/<name>" */
|
||||||
if (str_has_pfx(prog->sec_name, "tp/"))
|
if (str_has_pfx(prog->sec_name, "tp/"))
|
||||||
tp_cat = sec_name + sizeof("tp/") - 1;
|
tp_cat = sec_name + sizeof("tp/") - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user