Skip to content

Commit

Permalink
updatemanager: Close file on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Sep 11, 2024
1 parent fcb7978 commit 02e0b02
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/updatemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,14 @@ static bool cacheInfoIsUsable(CachePaths& paths)
if (filesize <= 0)
{
// Invalid file size
PHYSFS_close(fileHandle);
throw std::runtime_error("Invalid filesize");
}
std::vector<char> fileData(static_cast<size_t>(filesize + 1), '\0');
if (WZ_PHYSFS_readBytes(fileHandle, fileData.data(), static_cast<PHYSFS_uint32>(filesize)) != filesize)
{
// Read failed
PHYSFS_close(fileHandle);
throw std::runtime_error("Read failed");
}
PHYSFS_close(fileHandle);
Expand Down Expand Up @@ -791,12 +793,14 @@ static void initProcessData(const std::vector<std::string> &updateDataUrls, Proc
if (filesize < 0 || filesize > WZ_UPDATES_JSON_MAX_SIZE)
{
// Invalid file size
PHYSFS_close(fileHandle);
throw std::runtime_error("Invalid filesize");
}
std::vector<char> fileData(static_cast<size_t>(filesize + 1), '\0');
if (WZ_PHYSFS_readBytes(fileHandle, fileData.data(), static_cast<PHYSFS_uint32>(filesize)) != filesize)
{
// Read failed
PHYSFS_close(fileHandle);
throw std::runtime_error("Read failed");
}
PHYSFS_close(fileHandle);
Expand Down

0 comments on commit 02e0b02

Please sign in to comment.