mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-24 23:23:58 +00:00
FileManager: Fix descriptor leak in copy_file, found by Coverity
This commit is contained in:
parent
e43d5d5eaa
commit
73ab030f88
Notes:
sideshowbarker
2024-07-19 03:30:18 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/73ab030f88f Pull-request: https://github.com/SerenityOS/serenity/pull/3184 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bugaevc
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 (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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue