sd-dhcp-server: use close_and_replace (avoid fd leak)

Follow-up for 11b88419ae

Fixes #32252
This commit is contained in:
Mike Yuan
2024-04-13 02:48:52 +08:00
parent 3c321488bc
commit d2198b3206
+3 -3
View File
@@ -1605,8 +1605,7 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char
if (!path_is_safe(path))
return -EINVAL;
_cleanup_close_ int fd = -EBADF;
fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH);
_cleanup_close_ int fd = fd_reopen(dir_fd, O_CLOEXEC | O_DIRECTORY | O_PATH);
if (fd < 0)
return fd;
@@ -1614,6 +1613,7 @@ int sd_dhcp_server_set_lease_file(sd_dhcp_server *server, int dir_fd, const char
if (r < 0)
return r;
server->lease_dir_fd = TAKE_FD(fd);
close_and_replace(server->lease_dir_fd, fd);
return 0;
}