diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2022-05-16 21:45:47 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-05-16 23:42:44 +0300 |
commit | ac6a65868a5a45db49d5ee8524df3b701110d844 (patch) | |
tree | 72f9343ef2e613411b74f51400d8169d948dbf4a /tools/lib | |
parent | 418fbe82578e2889dcc2c0ae4d367ea4e28dd05c (diff) | |
download | linux-ac6a65868a5a45db49d5ee8524df3b701110d844.tar.xz |
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>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9aae886cbabf..ef7f302e542f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -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; - sec_name = strdup(prog->sec_name); - if (!sec_name) - return -ENOMEM; - *link = NULL; /* no auto-attach for SEC("tp") or SEC("tracepoint") */ if (strcmp(prog->sec_name, "tp") == 0 || strcmp(prog->sec_name, "tracepoint") == 0) return 0; + sec_name = strdup(prog->sec_name); + if (!sec_name) + return -ENOMEM; + /* extract "tp/<category>/<name>" or "tracepoint/<category>/<name>" */ if (str_has_pfx(prog->sec_name, "tp/")) tp_cat = sec_name + sizeof("tp/") - 1; |