[NTOS:MM] Fix memory leak in MiMapViewOfDataSection

If inserting the allocated VAD fails, MiMapViewOfDataSection will make no attempt to free the allocated VAD. Nor will it call MiDereferenceControlArea(ControlArea); like other failure return paths. This commit fixes this behavior.
Co-authored-by: Hermès BÉLUSCA - MAÏTO <[email protected]>
This commit is contained in:
Tuur Martens
2022-05-18 12:31:31 +02:00
committed by George Bișoc
parent 032c50f87c
commit 4f8bbd141e
+12
View File
@@ -1494,6 +1494,11 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
if (!NT_SUCCESS(Status))
{
ExFreePoolWithTag(Vad, 'ldaV');
MiDereferenceControlArea(ControlArea);
KeAcquireGuardedMutex(&MmSectionCommitMutex);
Segment->NumberOfCommittedPages -= QuotaCharge;
KeReleaseGuardedMutex(&MmSectionCommitMutex);
return Status;
}
@@ -1506,6 +1511,13 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
AllocationType);
if (!NT_SUCCESS(Status))
{
ExFreePoolWithTag(Vad, 'ldaV');
MiDereferenceControlArea(ControlArea);
KeAcquireGuardedMutex(&MmSectionCommitMutex);
Segment->NumberOfCommittedPages -= QuotaCharge;
KeReleaseGuardedMutex(&MmSectionCommitMutex);
PsReturnProcessNonPagedPoolQuota(PsGetCurrentProcess(), sizeof(MMVAD_LONG));
return Status;
}