From 73ab030f88f1619347f353914e285c503a87eaa7 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 16 Aug 2020 18:20:01 -0700 Subject: FileManager: Fix descriptor leak in copy_file, found by Coverity --- Applications/FileManager/FileUtils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Applications') 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; } -- cgit v1.2.3