From ba5450f4119c75ad9e3214bf4edeecb4d3f55a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 6 Dec 2019 10:40:20 +0100 Subject: [PATCH] shared/loop-util: fix leak of fd in error path --- src/shared/loop-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 05b0d51d97..c3d8f81d08 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -58,7 +58,7 @@ int loop_device_make_full( } if (offset == 0 && IN_SET(size, 0, UINT64_MAX)) { - int copy; + _cleanup_close_ int copy = -1; /* If this is already a block device, store a copy of the fd as it is */ @@ -71,7 +71,7 @@ int loop_device_make_full( return -ENOMEM; *d = (LoopDevice) { - .fd = copy, + .fd = TAKE_FD(copy), .nr = nr, .node = TAKE_PTR(loopdev), .relinquished = true, /* It's not allocated by us, don't destroy it when this object is freed */