aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-25 18:40:31 +0200
committerStefan Boberg <[email protected]>2021-09-25 18:40:31 +0200
commitef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1 (patch)
tree782d323bf21db28f625f1518377232d155ddfb65
parentAdded --upstream-jupiter-prod for easy production settings. (diff)
downloadzen-ef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1.tar.xz
zen-ef0c8e3f91b5f9fed8a8ae0547cab733e0a70de1.zip
Ensure FILE_RENAME_INFO structure allocation is freed also if FileCasStrategy::InsertChunk() throws
-rw-r--r--zenstore/filecas.cpp5
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};