https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d09e1398f83d71a7940ed0...
commit d09e1398f83d71a7940ed02ee68e63fff2756cbc Author: Trevor Thompson tmt256@email.vccs.edu AuthorDate: Fri Jul 15 15:27:04 2016 +0000
[NTFS] *AddRun() - Don't leak RunBuffer when encountering errors. Handle exception from FsRtlAddLargeMcbEntry().
svn path=/branches/GSoC_2016/NTFS/; revision=71945 --- drivers/filesystems/ntfs/attrib.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/filesystems/ntfs/attrib.c b/drivers/filesystems/ntfs/attrib.c index 3cf40d8341..61d8c8ab8f 100644 --- a/drivers/filesystems/ntfs/attrib.c +++ b/drivers/filesystems/ntfs/attrib.c @@ -88,25 +88,40 @@ AddRun(PNTFS_VCB Vcb, ULONGLONG NextVBN = AttrContext->Record.NonResident.LowestVCN;
// Allocate some memory for the RunBuffer - PUCHAR RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS); + PUCHAR RunBuffer; int RunBufferOffset = 0;
if (!AttrContext->Record.IsNonResident) return STATUS_INVALID_PARAMETER;
+ RunBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->NtfsInfo.BytesPerFileRecord, TAG_NTFS); + // Convert the data runs to a map control block Status = ConvertDataRunsToLargeMCB(DataRun, &DataRunsMCB, &NextVBN); if (!NT_SUCCESS(Status)) { DPRINT1("Unable to convert data runs to MCB (probably ran out of memory)!\n"); + ExFreePoolWithTag(RunBuffer, TAG_NTFS); return Status; }
// Add newly-assigned clusters to mcb - FsRtlAddLargeMcbEntry(&DataRunsMCB, - NextVBN, - NextAssignedCluster, - RunLength); + _SEH2_TRY{ + if (!FsRtlAddLargeMcbEntry(&DataRunsMCB, + NextVBN, + 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 ConvertLargeMCBToDataRuns(&DataRunsMCB, RunBuffer, Vcb->NtfsInfo.BytesPerCluster, &RunBufferOffset);