summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Egranov <daniil.egranov@arm.com>2016-09-22 17:37:48 -0500
committerRyan Harkin <ryan.harkin@linaro.org>2016-11-02 16:58:05 +0000
commit0f559af41b1e4045d46e0be0330c7e8efce9ded1 (patch)
treee065e54de09e5bed143ad589ec4a168961fbc93d
parent69a4a8cf0c64d6b79c0bd065f34a5d4018043079 (diff)
ArmPkg/Library/ArmDmaLib: Deallocate Map buffer in case of errorarmlt-20161117-001armlt-16.1116.11
The patch is fixing memory leak in case of errors. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Daniil Egranov <daniil.egranov@arm.com>
-rw-r--r--ArmPkg/Library/ArmDmaLib/ArmDmaLib.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
index d48d6ff6db..dffaf01661 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
@@ -90,14 +90,13 @@ DmaMap (
return EFI_OUT_OF_RESOURCES;
}
- *Mapping = Map;
-
if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||
((*NumberOfBytes & (gCacheAlignment - 1)) != 0)) {
// Get the cacheability of the region
Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);
if (EFI_ERROR(Status)) {
+ FreePool(Map);
return Status;
}
@@ -112,6 +111,7 @@ DmaMap (
"%a: Operation type 'MapOperationBusMasterCommonBuffer' is only supported\n"
"on memory regions that were allocated using DmaAllocateBuffer ()\n",
__FUNCTION__));
+ FreePool(Map);
return EFI_UNSUPPORTED;
}
@@ -122,6 +122,7 @@ DmaMap (
Map->DoubleBuffer = TRUE;
Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);
if (EFI_ERROR (Status)) {
+ FreePool(Map);
return Status;
}
@@ -162,6 +163,8 @@ DmaMap (
Map->NumberOfBytes = *NumberOfBytes;
Map->Operation = Operation;
+ *Mapping = Map;
+
return EFI_SUCCESS;
}