From 0fd3e515808e6c0cc4dd2c662133aeb6e3f9e7b2 Mon Sep 17 00:00:00 2001 From: Serge Gautherie <32623169+SergeGautherie@users.noreply.github.com> Date: Mon, 20 Dec 2021 21:14:36 +0100 Subject: [PATCH] [HALX86] HalpDmaAllocateChildAdapter(): Fix memory leak, on error (#4156) Simplify code, instead of adding 2 missing ObDereferenceObject(). (Note that ObInsertObject() always dereferences the object in case of failure.) CORE-17904 --- hal/halx86/generic/dma.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hal/halx86/generic/dma.c b/hal/halx86/generic/dma.c index 19d70517b5f..2966a5b2983 100644 --- a/hal/halx86/generic/dma.c +++ b/hal/halx86/generic/dma.c @@ -477,12 +477,6 @@ HalpDmaAllocateChildAdapter(IN ULONG NumberOfMapRegisters, (PVOID)&AdapterObject); if (!NT_SUCCESS(Status)) return NULL; - Status = ObReferenceObjectByPointer(AdapterObject, - FILE_READ_DATA | FILE_WRITE_DATA, - IoAdapterObjectType, - KernelMode); - if (!NT_SUCCESS(Status)) return NULL; - RtlZeroMemory(AdapterObject, sizeof(ADAPTER_OBJECT)); Status = ObInsertObject(AdapterObject, @@ -493,6 +487,8 @@ HalpDmaAllocateChildAdapter(IN ULONG NumberOfMapRegisters, &Handle); if (!NT_SUCCESS(Status)) return NULL; + ObReferenceObject(AdapterObject); + ZwClose(Handle); AdapterObject->DmaHeader.Version = (USHORT)DeviceDescription->Version;