public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>,
	Yonghong Zhu <yonghong.zhu@intel.com>,
	Liming Gao <liming.gao@intel.com>
Subject: [PATCH 3/5] BaseTools/DevicePath: Fix potential memory leak
Date: Mon,  8 Jan 2018 13:30:42 +0800	[thread overview]
Message-ID: <20180108053044.11788-4-hao.a.wu@intel.com> (raw)
In-Reply-To: <20180108053044.11788-1-hao.a.wu@intel.com>

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 BaseTools/Source/C/DevicePath/DevicePath.c         |  1 +
 BaseTools/Source/C/DevicePath/DevicePathFromText.c | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index 76b8553b71..4f859a0e44 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -190,5 +190,6 @@ int main(int argc, CHAR8 *argv[])
   }
   PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);
   putchar('\n');
+  free(Str16);
   return STATUS_SUCCESS;
 }
diff --git a/BaseTools/Source/C/DevicePath/DevicePathFromText.c b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
index 3d2f5a811c..120f2a38a2 100644
--- a/BaseTools/Source/C/DevicePath/DevicePathFromText.c
+++ b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
@@ -3277,6 +3277,17 @@ UefiDevicePathLibConvertTextToDeviceNode (
     //
     FromText = DevPathFromTextFilePath;
     DeviceNode = FromText (DeviceNodeStr);
+    //
+    // According to above logic, if 'FromText' is NULL in the 'if' statement,
+    // then 'ParamStr' must be NULL as well. No memory allocation has been made
+    // in this case.
+    //
+    // The below check is for addressing a false positive potential memory leak
+    // issue raised from static analysis.
+    //
+    if (ParamStr != NULL) {
+      free (ParamStr);
+    }
   } else {
     DeviceNode = FromText (ParamStr);
     free (ParamStr);
-- 
2.12.0.windows.1



  parent reply	other threads:[~2018-01-08  5:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08  5:30 [PATCH 0/5] BaseTools/Common & DevicePath: Code refinements Hao Wu
2018-01-08  5:30 ` [PATCH 1/5] BaseTools/C/Common: Fix code to be more readable Hao Wu
2018-01-08  5:30 ` [PATCH 2/5] BaseTools/C/Common: Fix potential memory leak Hao Wu
2018-01-08  5:30 ` Hao Wu [this message]
2018-01-08  5:30 ` [PATCH 4/5] BaseTools/C/Common: Fix potential null pointer dereference Hao Wu
2018-01-08  5:30 ` [PATCH 5/5] BaseTools/DevicePath: " Hao Wu
2018-01-11  3:09 ` [PATCH 0/5] BaseTools/Common & DevicePath: Code refinements Zhu, Yonghong
2018-01-12  1:00 ` Gao, Liming

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=20180108053044.11788-4-hao.a.wu@intel.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