From: Yu Watanabe Date: Fri, 23 Jun 2023 01:10:58 +0000 (+0900) Subject: copy: fix fd leak X-Git-Tag: v254-rc1~119^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=440ccf0424f8b6bba891d9c98351beb387759424;p=thirdparty%2Fsystemd.git copy: fix fd leak Follow-up for 01428141ba42a06d22f2c0e0df26049e700f4098. --- diff --git a/src/shared/copy.c b/src/shared/copy.c index 5a4a8aaf0d5..9d3db2d7716 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -1233,6 +1233,7 @@ int copy_directory_at_full( copy_progress_bytes_t progress_bytes, void *userdata) { + _cleanup_close_ int fdt = -EBADF; struct stat st; int r; @@ -1262,11 +1263,14 @@ int copy_directory_at_full( if (r < 0) return r; + if (FLAGS_SET(copy_flags, COPY_LOCK_BSD)) + fdt = r; + r = sync_dir_by_flags(dir_fdt, to, copy_flags); if (r < 0) return r; - return 0; + return FLAGS_SET(copy_flags, COPY_LOCK_BSD) ? TAKE_FD(fdt) : 0; } int copy_file_fd_at_full(