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.24; helo=mga09.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 C2CFC2116745B for ; Sun, 10 Jun 2018 20:01:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jun 2018 20:01:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,500,1520924400"; d="scan'208";a="206963369" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga004.jf.intel.com with ESMTP; 10 Jun 2018 20:01:16 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 10 Jun 2018 20:01:15 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 10 Jun 2018 20:01:14 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.87]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.51]) with mapi id 14.03.0319.002; Mon, 11 Jun 2018 11:01:13 +0800 From: "Ni, Ruiyu" To: "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Carsey, Jaben" Thread-Topic: [patch 1/3] ShellPkg/Dp: make sure memory is freed before exit Thread-Index: AQHT/KfgLdWa+m3AAEqcGi6QEW+4BaRaZ3Nw Date: Mon, 11 Jun 2018 03:01:12 +0000 Deferred-Delivery: Mon, 11 Jun 2018 03:01:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BD2DE66@SHSMSX104.ccr.corp.intel.com> References: <20180605083243.81276-1-dandan.bi@intel.com> In-Reply-To: <20180605083243.81276-1-dandan.bi@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch 1/3] ShellPkg/Dp: make sure memory is freed before exit X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jun 2018 03:01:16 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: Bi, Dandan > Sent: Tuesday, June 5, 2018 4:33 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming ; Ni, Ruiyu ; > Carsey, Jaben > Subject: [patch 1/3] ShellPkg/Dp: make sure memory is freed before exit >=20 > Run dp command now: > Firstly it will get performance records from FPDT and then parse the DP > command. And if encounter invalid parameters, it will exit directly. Thus= the > performance records got before are invalid. And what's worse is that the > memory allocated in getting performance records phase is not freed. >=20 > This patch update the code to parse the command firstly and then get the > performance records. And make sure that all the clean work has been done > before exiting. >=20 > Cc: Liming Gao > Cc: Ruiyu Ni > Cc: Jaben Carsey > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Dandan Bi > --- > ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c | 70 > ++++++++++++++------------- > 1 file changed, 37 insertions(+), 33 deletions(-) >=20 > diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c > b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c > index aa9c2cdf7a8..fe85937f557 100644 > --- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c > +++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c > @@ -390,11 +390,11 @@ BuildCachedGuidHandleTable ( > } > if (HandleBuffer !=3D NULL) { > FreePool (HandleBuffer); > HandleBuffer =3D NULL; > } > - return Status; > + return EFI_SUCCESS; > } >=20 > /** > Get Measurement form Fpdt records. >=20 > @@ -729,39 +729,10 @@ RunDp ( > // initialize the shell lib (we must be in non-auto-init...) > // > Status =3D ShellInitialize(); > ASSERT_EFI_ERROR(Status); >=20 > - // > - // DP dump performance data by parsing FPDT table in ACPI table. > - // Folloing 3 steps are to get the measurement form the FPDT table. > - // > - > - // > - //1. Get FPDT from ACPI table. > - // > - Status =3D GetBootPerformanceTable (); > - if (EFI_ERROR(Status)) { > - return Status; > - } > - > - // > - //2. Cache the ModuleGuid and hanlde mapping table. > - // > - Status =3D BuildCachedGuidHandleTable(); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - // > - //3. Build the measurement array form the FPDT records. > - // > - Status =3D BuildMeasurementList (); > - if (EFI_ERROR(Status)) { > - return Status; > - } > - > // > // Process Command Line arguments > // > Status =3D ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE= ); > if (EFI_ERROR(Status)) { > @@ -809,10 +780,42 @@ RunDp ( > #if PROFILING_IMPLEMENTED > ProfileMode =3D TRUE; > #endif // PROFILING_IMPLEMENTED > } >=20 > + // > + // DP dump performance data by parsing FPDT table in ACPI table. > + // Folloing 3 steps are to get the measurement form the FPDT table. > + // > + > + // > + //1. Get FPDT from ACPI table. > + // > + Status =3D GetBootPerformanceTable (); > + if (EFI_ERROR (Status)) { > + ShellStatus =3D Status; > + goto Done; > + } > + > + // > + //2. Cache the ModuleGuid and hanlde mapping table. > + // > + Status =3D BuildCachedGuidHandleTable(); if (EFI_ERROR (Status)) { > + ShellStatus =3D Status; > + goto Done; > + } > + > + // > + //3. Build the measurement array form the FPDT records. > + // > + Status =3D BuildMeasurementList (); > + if (EFI_ERROR (Status)) { > + ShellStatus =3D SHELL_OUT_OF_RESOURCES; > + goto Done; > + } > + > // > // Initialize the pre-defined cumulative data. > // > InitCumulativeData (); >=20 > @@ -821,21 +824,22 @@ RunDp ( > // > CustomCumulativeToken =3D ShellCommandLineGetValue (ParamPackage, > L"-c"); > if (CustomCumulativeToken !=3D NULL) { > CustomCumulativeData =3D AllocateZeroPool (sizeof (PERF_CUM_DATA)); > if (CustomCumulativeData =3D=3D NULL) { > - return SHELL_OUT_OF_RESOURCES; > + ShellStatus =3D SHELL_OUT_OF_RESOURCES; > + goto Done; > } > CustomCumulativeData->MinDur =3D PERF_MAXDUR; > CustomCumulativeData->MaxDur =3D 0; > CustomCumulativeData->Count =3D 0; > CustomCumulativeData->Duration =3D 0; > NameSize =3D StrLen (CustomCumulativeToken) + 1; > CustomCumulativeData->Name =3D AllocateZeroPool (NameSize); > if (CustomCumulativeData->Name =3D=3D NULL) { > - FreePool (CustomCumulativeData); > - return SHELL_OUT_OF_RESOURCES; > + ShellStatus =3D SHELL_OUT_OF_RESOURCES; > + goto Done; > } > UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData- > >Name, NameSize); > } >=20 > // > -- > 2.14.3.windows.1