From 46cced287e3a01c19929c4a92bbb713c9c999842 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Wed, 3 Jan 2018 16:51:27 +0800 Subject: [PATCH] BaseTools/DevicePath: Fix potential memory leak Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Yonghong Zhu Reviewed-by: Liming Gao --- BaseTools/Source/C/DevicePath/DevicePath.c | 3 ++- BaseTools/Source/C/DevicePath/DevicePathFromText.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c index 76b8553b71..9185b89e35 100644 --- a/BaseTools/Source/C/DevicePath/DevicePath.c +++ b/BaseTools/Source/C/DevicePath/DevicePath.c @@ -1,7 +1,7 @@ /** @file Definition for Device Path Tool. -Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -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..776cf051b0 100644 --- a/BaseTools/Source/C/DevicePath/DevicePathFromText.c +++ b/BaseTools/Source/C/DevicePath/DevicePathFromText.c @@ -1,7 +1,7 @@ /** @file DevicePathFromText protocol as defined in the UEFI 2.0 specification. -Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -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);