*AddRun() - Don't leak RunBuffer when encountering errors.
Handle exception from FsRtlAddLargeMcbEntry().

svn path=/branches/GSoC_2016/NTFS/; revision=71945
This commit is contained in:
Trevor Thompson 2016-07-15 15:27:04 +00:00 committed by Thomas Faber
parent afe40eb054
commit d09e1398f8

View file

@ -88,25 +88,40 @@ AddRun(PNTFS_VCB Vcb,
ULONGLONG NextVBN = AttrContext->Record.NonResident.LowestVCN; ULONGLONG NextVBN = AttrContext->Record.NonResident.LowestVCN;
// Allocate some memory for the RunBuffer // Allocate some memory for the RunBuffer
PUCHAR RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS); PUCHAR RunBuffer;
int RunBufferOffset = 0; int RunBufferOffset = 0;
if (!AttrContext->Record.IsNonResident) if (!AttrContext->Record.IsNonResident)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS);
// Convert the data runs to a map control block // Convert the data runs to a map control block
Status = ConvertDataRunsToLargeMCB(DataRun, &DataRunsMCB, &NextVBN); Status = ConvertDataRunsToLargeMCB(DataRun, &DataRunsMCB, &NextVBN);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("Unable to convert data runs to MCB (probably ran out of memory)!\n"); DPRINT1("Unable to convert data runs to MCB (probably ran out of memory)!\n");
ExFreePoolWithTag(RunBuffer, TAG_NTFS);
return Status; return Status;
} }
// Add newly-assigned clusters to mcb // Add newly-assigned clusters to mcb
FsRtlAddLargeMcbEntry(&DataRunsMCB, _SEH2_TRY{
NextVBN, if (!FsRtlAddLargeMcbEntry(&DataRunsMCB,
NextAssignedCluster, NextVBN,
RunLength); NextAssignedCluster,
RunLength))
{
FsRtlUninitializeLargeMcb(&DataRunsMCB);
ExFreePoolWithTag(RunBuffer, TAG_NTFS);
return STATUS_INSUFFICIENT_RESOURCES;
}
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
FsRtlUninitializeLargeMcb(&DataRunsMCB);
ExFreePoolWithTag(RunBuffer, TAG_NTFS);
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
} _SEH2_END;
// Convert the map control block back to encoded data runs // Convert the map control block back to encoded data runs
ConvertLargeMCBToDataRuns(&DataRunsMCB, RunBuffer, Vcb->NtfsInfo.BytesPerCluster, &RunBufferOffset); ConvertLargeMCBToDataRuns(&DataRunsMCB, RunBuffer, Vcb->NtfsInfo.BytesPerCluster, &RunBufferOffset);