]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: fix fd leak
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 Jun 2023 01:10:58 +0000 (10:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 Jun 2023 01:11:06 +0000 (10:11 +0900)
Follow-up for 01428141ba42a06d22f2c0e0df26049e700f4098.

src/shared/copy.c

index 5a4a8aaf0d5c0ff89347573aa04ecfd403aa7022..9d3db2d77165b6aab9e8e7bbcca188c096db5ddf 100644 (file)
@@ -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(