]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bpf: adjust comment about not calling sym_bpf_link__destroy
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 9 Jan 2022 18:53:22 +0000 (19:53 +0100)
committerJulia Kartseva <hex@fb.com>
Mon, 10 Jan 2022 05:45:50 +0000 (21:45 -0800)
src/shared/bpf-link.c

index 85eab090328d48c7b8d4279ea803431042b4918e..fea49b2ecbbdc7d65c76970bb5761ba50841871b 100644 (file)
@@ -32,12 +32,12 @@ int bpf_serialize_link(FILE *f, FDSet *fds, const char *key, struct bpf_link *li
 }
 
 struct bpf_link *bpf_link_free(struct bpf_link *link) {
-
-        /* Avoid a useless dlopen() if link == NULL */
-        if (!link)
-                return NULL;
-
-        (void) sym_bpf_link__destroy(link);
+        /* If libbpf wasn't dlopen()ed, sym_bpf_link__destroy might be unresolved (NULL), so let's not try to
+         * call it if link is NULL. link might also be a non-null "error pointer", but such a value can only
+         * originate from a call to libbpf, but that means that libbpf is available, and we can let
+         * bpf_link__destroy() handle it. */
+        if (link)
+                (void) sym_bpf_link__destroy(link);
 
         return NULL;
 }