summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-08-16 18:14:20 -0700
committerAndreas Kling <kling@serenityos.org>2020-08-17 09:17:57 +0200
commite43d5d5eaabf1700559a3b54475122a1c4a33ba3 (patch)
treeff10028d8db8e17c94401b5c843e2c5bdb81bb18
parentbcbac83a8bdd2ca29f70204d6c7d8202d6b01bdf (diff)
downloadserenity-e43d5d5eaabf1700559a3b54475122a1c4a33ba3.zip
FileManger: Fix file descriptor leak in copy_file_or_directory, found by Coverity
-rw-r--r--Applications/FileManager/FileUtils.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Applications/FileManager/FileUtils.cpp b/Applications/FileManager/FileUtils.cpp
index 20187415d7..7ba59f063b 100644
--- a/Applications/FileManager/FileUtils.cpp
+++ b/Applications/FileManager/FileUtils.cpp
@@ -26,6 +26,7 @@
#include "FileUtils.h"
#include <AK/LexicalPath.h>
+#include <AK/ScopeGuard.h>
#include <AK/StringBuilder.h>
#include <LibCore/DirIterator.h>
#include <stdio.h>
@@ -86,6 +87,8 @@ bool copy_file_or_directory(const String& src_path, const String& dst_path)
return false;
}
+ ScopeGuard close_fd_guard([src_fd]() { close(src_fd); });
+
struct stat src_stat;
int rc = fstat(src_fd, &src_stat);
if (rc < 0) {