From 3995b218a389564989519d6b4e7d27d797795862 Mon Sep 17 00:00:00 2001 From: yushihang Date: Fri, 19 Apr 2024 18:25:37 +0800 Subject: [PATCH] add close(fd) before throw when fstat fails --- src/binfile_utils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index 4ca5dab..821a302 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -22,8 +22,10 @@ BinFile::BinFile(const std::string& fileName, const std::string& _type, uint32_t throw std::system_error(errno, std::generic_category(), "open"); - if (fstat(fd, &sb) == -1) /* To obtain file size */ + if (fstat(fd, &sb) == -1) { /* To obtain file size */ + close(fd); throw std::system_error(errno, std::generic_category(), "fstat"); + } size = sb.st_size;