From 5ed1cc5eb5ea7994c6f0fe137528dc860904b9a2 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 19 Jan 2023 09:12:58 -0800 Subject: [PATCH] Fix possible leak when committing a null allocation. --- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 6e8a4b5ed..32c049518 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1205,7 +1205,7 @@ namespace gpgmm::d3d12 { } ComPtr committedResource; - Heap* resourceHeap = nullptr; + ComPtr resourceHeap; ReturnIfFailed(CreateCommittedResource(heapProperties, heapFlags, resourceInfo, &newResourceDesc, clearValue, initialResourceState, &committedResource, &resourceHeap)); @@ -1221,12 +1221,13 @@ namespace gpgmm::d3d12 { allocationDesc.HeapOffset = kInvalidOffset; allocationDesc.SizeInBytes = request.SizeInBytes; allocationDesc.Method = AllocationMethod::kStandalone; - allocationDesc.OffsetFromResource = 0; allocationDesc.DebugName = allocationDescriptor.DebugName; - *ppResourceAllocationOut = - new ResourceAllocation(allocationDesc, mResidencyManager.Get(), this, resourceHeap, - nullptr, std::move(committedResource)); + if (ppResourceAllocationOut != nullptr) { + *ppResourceAllocationOut = new ResourceAllocation( + allocationDesc, mResidencyManager.Get(), this, resourceHeap.Detach(), nullptr, + std::move(committedResource)); + } return S_OK; }