From: Yu Watanabe Date: Fri, 2 Sep 2022 20:52:45 +0000 (+0900) Subject: loop-util: fix memleak when fd is for a block device with non-zero offset or size X-Git-Tag: v252-rc1~263 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d12c0f4cfe339a30230e4c3d04eb93bcd0bd2c0f;p=thirdparty%2Fsystemd.git loop-util: fix memleak when fd is for a block device with non-zero offset or size --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 568e431655f..928792281c5 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -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. */