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//" or "tracepoint//" */ if (str_has_pfx(prog->sec_name, "tp/")) tp_cat = sec_name + sizeof("tp/") - 1;