]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mstack: fix resource leak on failure path
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 20 Feb 2026 07:18:07 +0000 (16:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 20 Feb 2026 07:21:48 +0000 (16:21 +0900)
This makes the mstack_load() requires 'ret', as clearing the loaded
mstack without use is meaningless. All callers already pass non-NULL for
the argument.

Follow-up for 8343032a86b62f62780de85a696ab8f9d2632244.
Fixes CID#1645105.

src/shared/mstack.c

index f0ebd57635bdae98cca59189fdd03d03d4644218..d1eddda28bbf3688a7107f24395eb085218d97a5 100644 (file)
@@ -1120,19 +1120,18 @@ int mstack_apply(
         return mstack_bind_mounts(&mstack, where, /* where_fd= */ -EBADF, flags, ret_root_fd);
 }
 
-int mstack_load(const char *dir,
-                int dir_fd,
-                MStack **ret) {
-
+int mstack_load(const char *dir, int dir_fd, MStack **ret) {
         int r;
 
+        assert(ret);
+
         /* Well-known errors:
          *
          *     -ENOTUNIQ → Multiple conflicting layers for the same path defined
          *     -EBADMSG  → Bad file suffix, inode type for layer, or unrecognized entry
          */
 
-        MStack *mstack = new(MStack, 1);
+        _cleanup_(mstack_freep) MStack *mstack = new(MStack, 1);
         if (!mstack)
                 return -ENOMEM;
 
@@ -1142,9 +1141,7 @@ int mstack_load(const char *dir,
         if (r < 0)
                 return r;
 
-        if (ret)
-                *ret = TAKE_PTR(mstack);
-
+        *ret = TAKE_PTR(mstack);
         return 0;
 }