FileManager: Fix descriptor leak in copy_file, found by Coverity

This commit is contained in:
Brian Gianforcaro 2020-08-16 18:20:01 -07:00 committed by Andreas Kling
parent e43d5d5eaa
commit 73ab030f88
Notes: sideshowbarker 2024-07-19 03:30:18 +09:00

View file

@ -144,6 +144,8 @@ bool copy_file(const String& src_path, const String& dst_path, const struct stat
}
}
ScopeGuard close_fd_guard([dst_fd]() { close(dst_fd); });
if (src_stat.st_size > 0) {
if (ftruncate(dst_fd, src_stat.st_size) < 0) {
perror("cp: ftruncate");
@ -180,7 +182,6 @@ bool copy_file(const String& src_path, const String& dst_path, const struct stat
}
close(src_fd);
close(dst_fd);
return true;
}