]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: lock_fd must be closed before calling LOOP_CLR_FD 24561/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Sep 2022 18:04:07 +0000 (03:04 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Sep 2022 19:31:47 +0000 (04:31 +0900)
Follow-up for 7f52206a2bc128f9ae8306db43aa6e2f7d916f82.

C.f. 87862cc2b4abb9564f7e0365ac515dc9020a54e4.

src/shared/loop-util.c

index 3cc72b65a06001442d15e91e1cd47ea627b51cdc..ed237c6f20d7e93ee00bc1438802ec98af39e322 100644 (file)
@@ -357,7 +357,7 @@ static int loop_device_make_internal(
                 int lock_op,
                 LoopDevice **ret) {
 
-        _cleanup_close_ int direct_io_fd = -1, lock_fd = -1;
+        _cleanup_close_ int direct_io_fd = -1;
         _cleanup_free_ char *node = NULL;
         bool try_loop_configure = true;
         struct loop_config config;
@@ -410,8 +410,10 @@ static int loop_device_make_internal(
                         fd = direct_io_fd; /* From now on, operate on our new O_DIRECT fd */
         }
 
+        /* On failure, lock_fd must be closed at first, otherwise LOOP_CLR_FD will fail. */
         _cleanup_close_ int control = -1;
         _cleanup_(cleanup_clear_loop_close) int loop_with_fd = -1;
+        _cleanup_close_ int lock_fd = -1;
 
         control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
         if (control < 0)