]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bpf: do not leak dlopen object
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 10:13:00 +0000 (11:13 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 15:44:15 +0000 (16:44 +0100)
CID#1609833

src/shared/bpf-dlopen.c

index e84b435f4882ae6975acc002534993f0d61d10c2..1c64498044ac5bc1fa70dc747f5848e6bad2e1c4 100644 (file)
@@ -49,6 +49,8 @@ DLSYM_PROTOTYPE(ring_buffer__free) = NULL;
 DLSYM_PROTOTYPE(ring_buffer__new) = NULL;
 DLSYM_PROTOTYPE(ring_buffer__poll) = NULL;
 
+static void* bpf_dl = NULL;
+
 /* new symbols available from libbpf 0.7.0 */
 int (*sym_bpf_map_create)(enum bpf_map_type,  const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *);
 struct bpf_map* (*sym_bpf_object__next_map)(const struct bpf_object *obj, const struct bpf_map *map);
@@ -71,8 +73,8 @@ static int bpf_print_func(enum libbpf_print_level level, const char *fmt, va_lis
 }
 
 int dlopen_bpf_full(int log_level) {
+        _cleanup_(dlclosep) void *dl = NULL;
         static int cached = 0;
-        void *dl;
         int r;
 
         if (cached != 0)
@@ -177,6 +179,8 @@ int dlopen_bpf_full(int log_level) {
 
         REENABLE_WARNING;
 
+        bpf_dl = TAKE_PTR(dl);
+
         return cached = true;
 }