[BOOT:MM] Fix descriptor memory leaks

Sometimes when handling MmMdAddDescriptorToList() errors, descriptors
were not freed with MmMdFreeDescriptor().
This commit is contained in:
Quinn Stephens 2024-09-01 16:56:18 -04:00
parent 65e33fdad5
commit 43c6c75710
3 changed files with 15 additions and 2 deletions

View File

@ -421,6 +421,7 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -456,6 +457,7 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -486,6 +488,7 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
}
@ -507,6 +510,7 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -568,6 +572,7 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
}

View File

@ -152,6 +152,7 @@ Return Value:
--*/
{
NTSTATUS Status;
PMEMORY_DESCRIPTOR PrevDescriptor, NextDescriptor, NewDescriptor;
ULONGLONG DescriptorEnd, PrevDescriptorEnd, NextDescriptorEnd;
ULONGLONG MappedFirstPage;
@ -186,7 +187,10 @@ Return Value:
PrevDescriptor->Type
);
if (NewDescriptor != NULL) {
MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
Status = MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
}
}
}
@ -242,7 +246,10 @@ Return Value:
Descriptor->Type
);
if (NewDescriptor != NULL) {
MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
Status = MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
}
}
}

View File

@ -141,6 +141,7 @@ Return Value:
Status = MmMdAddDescriptorToList(&MmMdlReservedAllocated, NewDescriptor, 0x00);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
return Status;
}