Skip to content

Commit

Permalink
add close(fd) before throw when fstat fails
Browse files Browse the repository at this point in the history
  • Loading branch information
yushihang authored Apr 19, 2024
1 parent 9fa3f0b commit 3995b21
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/binfile_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3995b21

Please sign in to comment.