summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-08-16 18:20:01 -0700
committerAndreas Kling <kling@serenityos.org>2020-08-17 09:17:57 +0200
commit73ab030f88f1619347f353914e285c503a87eaa7 (patch)
treefe49c93b995948996b13e5d06a3600838b16510e /Applications
parente43d5d5eaabf1700559a3b54475122a1c4a33ba3 (diff)
downloadserenity-73ab030f88f1619347f353914e285c503a87eaa7.zip
FileManager: Fix descriptor leak in copy_file, found by Coverity
Diffstat (limited to 'Applications')
-rw-r--r--Applications/FileManager/FileUtils.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/Applications/FileManager/FileUtils.cpp b/Applications/FileManager/FileUtils.cpp
index 7ba59f063b..99a74c4d03 100644
--- a/Applications/FileManager/FileUtils.cpp
+++ b/Applications/FileManager/FileUtils.cpp
@@ -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;
}