]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nsresource: fix FD leak
authorLuca Boccassi <bluca@debian.org>
Mon, 8 Apr 2024 01:33:27 +0000 (02:33 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 8 Apr 2024 09:19:42 +0000 (10:19 +0100)
Also fix return code, namespace_open_by_type uses RET_NERRNO

CID#1542923

Follow-up for 54452c7b2aa

src/shared/nsresource.c

index 4419f2fdde737e06993f25211ea23fe4fc3ee746..bc0a3525816840cfb44af901638f7e5290c97917 100644 (file)
@@ -146,15 +146,16 @@ int nsresource_register_userns(const char *name, int userns_fd) {
 
 int nsresource_add_mount(int userns_fd, int mount_fd) {
         _cleanup_(varlink_unrefp) Varlink *vl = NULL;
+        _cleanup_close_ int _userns_fd = -EBADF;
         int r, userns_fd_idx, mount_fd_idx;
         const char *error_id;
 
         assert(mount_fd >= 0);
 
         if (userns_fd < 0) {
-                int _userns_fd = namespace_open_by_type(NAMESPACE_USER);
+                _userns_fd = namespace_open_by_type(NAMESPACE_USER);
                 if (_userns_fd < 0)
-                        return -errno;
+                        return _userns_fd;
 
                 userns_fd = _userns_fd;
         }