loop-util: fix leak of file descriptor on failure

This commit is contained in:
Yu Watanabe
2022-09-07 05:36:26 +09:00
parent 844768c78b
commit 10719a6ff8

View File

@@ -118,17 +118,19 @@ static int device_has_block_children(sd_device *d) {
}
static int open_lock_fd(int primary_fd, int operation) {
int lock_fd;
_cleanup_close_ int lock_fd = -1;
assert(primary_fd >= 0);
assert(IN_SET(operation & ~LOCK_NB, LOCK_SH, LOCK_EX));
lock_fd = fd_reopen(primary_fd, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (lock_fd < 0)
return lock_fd;
if (flock(lock_fd, operation) < 0)
return -errno;
return lock_fd;
return TAKE_FD(lock_fd);
}
static int loop_configure(