]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dlfcn-util: fix potential dl handle leak
authorMike Yuan <me@yhndnzj.com>
Tue, 25 Nov 2025 02:52:57 +0000 (03:52 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 26 Nov 2025 00:41:51 +0000 (01:41 +0100)
Follow-up for 2c7bdaf9f144ad339c72628579183fc849f2b794

src/basic/dlfcn-util.c

index 26c5a44ffe0bfb96236e5119d5df46b0783ade74..8574e99546b81db93d4295ed44e94852d25f0d6b 100644 (file)
@@ -84,6 +84,7 @@ void block_dlopen(void) {
 }
 
 int dlopen_safe(const char *filename, void **ret, const char **reterr_dlerror) {
+        _cleanup_(dlclosep) void *dl = NULL;
         int r;
 
         assert(filename);
@@ -99,8 +100,8 @@ int dlopen_safe(const char *filename, void **ret, const char **reterr_dlerror) {
                 flags |= RTLD_NOLOAD;
 
         errno = 0;
-        void *p = dlopen(filename, flags);
-        if (!p) {
+        dl = dlopen(filename, flags);
+        if (!dl) {
                 if (dlopen_blocked) {
                         (void) dlerror(); /* consume error, so that no later call will return it */
 
@@ -121,7 +122,7 @@ int dlopen_safe(const char *filename, void **ret, const char **reterr_dlerror) {
         }
 
         if (ret)
-                *ret = TAKE_PTR(p);
+                *ret = TAKE_PTR(dl);
 
         return 0;
 }