On Tue, 2025-01-21 at 16:50 +0000, David CARLIER wrote: > libbpf.c memory leaks fixes proposal. Hi David, please take a look at the documentation regarding sending kernel patches: https://www.kernel.org/doc/html/latest/process/submitting-patches.html In particular: - the email should be in plain text - subject should be present - the patch itself is a part of the email, not an attachment. About the change itself, why do you think there is a resource leak? Here is a fragment of bpf_program__attach_kprobe_opts: link = bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); err = libbpf_get_error(link); if (err) { - close(pfd); + bpf_link__destroy(link); pr_warn("prog '%s': failed to attach to %s '%s+0x%zx': %s\n", prog->name, retprobe ? "kretprobe" : "kprobe", func_name, offset, errstr(err)); goto err_clean_legacy; } When libbpf_get_error returns a non-zero value the `link` is either an error value or null, so bpf_link__destroy has nothing to work with.