mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
FileManager: Fix descriptor leak in copy_file, found by Coverity
This commit is contained in:
parent
e43d5d5eaa
commit
73ab030f88
1 changed files with 2 additions and 1 deletions
|
@ -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 (src_stat.st_size > 0) {
|
||||||
if (ftruncate(dst_fd, src_stat.st_size) < 0) {
|
if (ftruncate(dst_fd, src_stat.st_size) < 0) {
|
||||||
perror("cp: ftruncate");
|
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(src_fd);
|
||||||
close(dst_fd);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue