]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/DevicePath: Fix potential memory leak
authorHao Wu <hao.a.wu@intel.com>
Wed, 3 Jan 2018 08:51:27 +0000 (16:51 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 15 Jan 2018 02:42:17 +0000 (10:42 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/DevicePath/DevicePath.c
BaseTools/Source/C/DevicePath/DevicePathFromText.c

index 76b8553b7145296b886176151eedf66fc8a93fb9..9185b89e35e21e62b9360f0636da1330aa757053 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Definition for Device Path Tool.\r
 \r
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -190,5 +190,6 @@ int main(int argc, CHAR8 *argv[])
   }\r
   PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);\r
   putchar('\n');\r
+  free(Str16);\r
   return STATUS_SUCCESS;\r
 }\r
index 3d2f5a811c4f7407a1f03688a534311e98d8df1b..776cf051b0d955044553461d20b457378ed897f1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -3277,6 +3277,17 @@ UefiDevicePathLibConvertTextToDeviceNode (
     //\r
     FromText = DevPathFromTextFilePath;\r
     DeviceNode = FromText (DeviceNodeStr);\r
+    //\r
+    // According to above logic, if 'FromText' is NULL in the 'if' statement,\r
+    // then 'ParamStr' must be NULL as well. No memory allocation has been made\r
+    // in this case.\r
+    //\r
+    // The below check is for addressing a false positive potential memory leak\r
+    // issue raised from static analysis.\r
+    //\r
+    if (ParamStr != NULL) {\r
+      free (ParamStr);\r
+    }\r
   } else {\r
     DeviceNode = FromText (ParamStr);\r
     free (ParamStr);\r