public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner" <abner.chang@amd.com>
To: <devel@edk2.groups.io>
Cc: Nickle Wang <nickle@csie.io>, Igor Kulchytskyy <igork@ami.com>
Subject: [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue
Date: Sat, 29 Oct 2022 11:59:11 +0800	[thread overview]
Message-ID: <20221029035911.651-1-abner.chang@amd.com> (raw)

From: Abner Chang <abner.chang@amd.com>

Check the memory block pointer before freeing it.

Cc: Nickle Wang <nickle@csie.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Signed-off-by: Abner Chang <abner.chang@amd.com>
---
 .../RedfishDiscoverDxe/RedfishDiscoverDxe.c      | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 1293ddd633c..1616b5134bc 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -261,6 +261,7 @@ Tcp6GetSubnetInfo (
 
   Tcp6 = (EFI_TCP6_PROTOCOL *)Instance->NetworkInterfaceProtocolInfo.NetworkProtocolInterface;
 
+  ZeroMem ((VOID *)&IpModedata, sizeof (EFI_IP6_MODE_DATA));
   Status = Tcp6->GetModeData (Tcp6, NULL, NULL, &IpModedata, NULL, NULL);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a: Can't get IP mode data information\n", __FUNCTION__));
@@ -282,12 +283,15 @@ Tcp6GetSubnetInfo (
   }
 
   Instance->SubnetAddrInfoIPv6Number = IpModedata.AddressCount;
-  CopyMem (
-    (VOID *)Instance->SubnetAddrInfoIPv6,
-    (VOID *)&IpModedata.AddressList,
-    IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)
-    );
-  FreePool (IpModedata.AddressList);
+  if (IpModedata.AddressCount != 0 && IpModedata.AddressList != NULL) {
+    CopyMem (
+      (VOID *)Instance->SubnetAddrInfoIPv6,
+      (VOID *)&IpModedata.AddressList,
+      IpModedata.AddressCount * sizeof (EFI_IP6_ADDRESS_INFO)
+      );
+    FreePool(IpModedata.AddressList);
+  }
+
   return EFI_SUCCESS;
 }
 
-- 
2.37.1.windows.1


             reply	other threads:[~2022-10-29  3:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-29  3:59 Chang, Abner [this message]
2022-10-29  7:50 ` [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: Fix memory free issue Nickle Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221029035911.651-1-abner.chang@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox