Klocwork Issue Fix - File Resource Lost
In the event when file_size() fails and file open was successful,
with the current implementation, the function would return without
closing the file.
This commit fixes this condition by having separate checks for
file_size error code and file open failure.
Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Change-Id: I44e46a4093f5fab087b40bb95440fbb3d215bad8
diff --git a/src/firmware-update.cpp b/src/firmware-update.cpp
index d27b8c6..809b87a 100644
--- a/src/firmware-update.cpp
+++ b/src/firmware-update.cpp
@@ -273,8 +273,12 @@
{
std::error_code ec;
size_t sz = std::filesystem::file_size(fname, ec);
+ if (!ec)
+ {
+ return;
+ }
int fd = open(fname.c_str(), O_RDONLY);
- if (!ec || fd < 0)
+ if (fd < 0)
{
return;
}