diff options
| author | Stefan Boberg <[email protected]> | 2021-09-25 18:40:31 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-25 18:40:31 +0200 |
| commit | ef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1 (patch) | |
| tree | 782d323bf21db28f625f1518377232d155ddfb65 | |
| parent | Added --upstream-jupiter-prod for easy production settings. (diff) | |
| download | zen-ef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1.tar.xz zen-ef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1.zip | |
Ensure FILE_RENAME_INFO structure allocation is freed also if FileCasStrategy::InsertChunk() throws
| -rw-r--r-- | zenstore/filecas.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index c036efd35..0b18848d5 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -7,6 +7,7 @@ #include <zencore/fmtutils.h> #include <zencore/logging.h> #include <zencore/memory.h> +#include <zencore/scopeguard.h> #include <zencore/string.h> #include <zencore/thread.h> #include <zencore/uid.h> @@ -133,6 +134,8 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) memcpy(RenameInfo->FileName, FileName.c_str(), FileName.size() * sizeof(WCHAR)); RenameInfo->FileName[FileName.size()] = 0; + auto $ = MakeGuard([&] { Memory::Free(RenameInfo); }); + // Try to move file into place BOOL Success = SetFileInformationByHandle(FileRef.FileHandle, FileRenameInfo, RenameInfo, BufferSize); @@ -175,8 +178,6 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) Success = SetFileInformationByHandle(FileRef.FileHandle, FileRenameInfo, RenameInfo, BufferSize); } - Memory::Free(RenameInfo); - if (Success) { return CasStore::InsertResult{.New = true}; |