]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: fix memleak when fd is for a block device with non-zero offset or size
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Sep 2022 20:52:45 +0000 (05:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Sep 2022 00:47:53 +0000 (09:47 +0900)
src/shared/loop-util.c

index 568e431655fa74c9f4bb4e133828ff0a43b64867..928792281c58be1ff9b0bcf585a15a67d44cb255 100644 (file)
@@ -506,6 +506,7 @@ static int loop_device_make_internal(
                 if (nr < 0)
                         return -errno;
 
+                node = mfree(node);
                 if (asprintf(&node, "/dev/loop%i", nr) < 0)
                         return -ENOMEM;
 
@@ -537,7 +538,6 @@ static int loop_device_make_internal(
                 /* Now close the loop device explicitly. This will release any lock acquired by
                  * attach_empty_file() or similar, while we sleep below. */
                 loop = safe_close(loop);
-                node = mfree(node);
 
                 /* Wait some random time, to make collision less likely. Let's pick a random time in the
                  * range 0ms…250ms, linearly scaled by the number of failed attempts. */