From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 92952222A54D8 for ; Sun, 7 Jan 2018 21:25:41 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2018 21:30:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,329,1511856000"; d="scan'208";a="8276709" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga002.fm.intel.com with ESMTP; 07 Jan 2018 21:30:50 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Yonghong Zhu , Liming Gao Date: Mon, 8 Jan 2018 13:30:42 +0800 Message-Id: <20180108053044.11788-4-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180108053044.11788-1-hao.a.wu@intel.com> References: <20180108053044.11788-1-hao.a.wu@intel.com> Subject: [PATCH 3/5] BaseTools/DevicePath: Fix potential memory leak X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2018 05:25:42 -0000 Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- 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