Skip to content

Commit

Permalink
FileSystem: Fix crash on file open fail in WriteAtomicRenamedFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 9, 2024
1 parent b2ca23e commit 8ad133d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/common/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ bool FileSystem::WriteAtomicRenamedFile(std::string filename, const void* data,
Error* error /*= nullptr*/)
{
AtomicRenamedFile fp = CreateAtomicRenamedFile(std::move(filename), "wb", error);
if (!fp)
return false;

if (data_length > 0 && std::fwrite(data, 1u, data_length, fp.get()) != data_length) [[unlikely]]
{
Error::SetErrno(error, "fwrite() failed: ", errno);
Expand Down

0 comments on commit 8ad133d

Please sign in to comment.