From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id 164F31A201C for ; Thu, 22 Sep 2016 15:38:01 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EAF4214F; Thu, 22 Sep 2016 15:38:00 -0700 (PDT) Received: from usa.arm.com (unknown [10.118.32.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B14B63F21A; Thu, 22 Sep 2016 15:38:00 -0700 (PDT) From: Daniil Egranov To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, Daniil Egranov Date: Thu, 22 Sep 2016 17:37:48 -0500 Message-Id: <1474583868-41777-1-git-send-email-daniil.egranov@arm.com> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] ArmPkg/Library/ArmDmaLib: Deallocate Map buffer in case of error X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2016 22:38:01 -0000 The patch is fixing memory leak in case of errors. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Daniil Egranov --- ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index d48d6ff..e0006c0 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; } -- 2.7.4