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.100; helo=mga07.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 B009621173C88 for ; Mon, 11 Jun 2018 01:32:26 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2018 01:32:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,501,1520924400"; d="scan'208";a="48906272" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by orsmga006.jf.intel.com with ESMTP; 11 Jun 2018 01:32:25 -0700 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Liming Gao , Ruiyu Ni , Jaben Carsey Date: Mon, 11 Jun 2018 16:32:04 +0800 Message-Id: <20180611083206.106804-1-dandan.bi@intel.com> X-Mailer: git-send-email 2.14.3.windows.1 Subject: [patch V2 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 08:32:26 -0000 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. 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. Cc: Liming Gao Cc: Ruiyu Ni Cc: Jaben Carsey Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Ruiyu Ni --- ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c | 70 ++++++++++++++------------- 1 file changed, 37 insertions(+), 33 deletions(-) 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 != NULL) { FreePool (HandleBuffer); HandleBuffer = NULL; } - return Status; + return EFI_SUCCESS; } /** Get Measurement form Fpdt records. @@ -729,39 +729,10 @@ RunDp ( // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); - // - // 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 = GetBootPerformanceTable (); - if (EFI_ERROR(Status)) { - return Status; - } - - // - //2. Cache the ModuleGuid and hanlde mapping table. - // - Status = BuildCachedGuidHandleTable(); - if (EFI_ERROR (Status)) { - return Status; - } - - // - //3. Build the measurement array form the FPDT records. - // - Status = BuildMeasurementList (); - if (EFI_ERROR(Status)) { - return Status; - } - // // Process Command Line arguments // Status = ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE); if (EFI_ERROR(Status)) { @@ -809,10 +780,42 @@ RunDp ( #if PROFILING_IMPLEMENTED ProfileMode = TRUE; #endif // PROFILING_IMPLEMENTED } + // + // 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 = GetBootPerformanceTable (); + if (EFI_ERROR (Status)) { + ShellStatus = Status; + goto Done; + } + + // + //2. Cache the ModuleGuid and hanlde mapping table. + // + Status = BuildCachedGuidHandleTable(); + if (EFI_ERROR (Status)) { + ShellStatus = Status; + goto Done; + } + + // + //3. Build the measurement array form the FPDT records. + // + Status = BuildMeasurementList (); + if (EFI_ERROR (Status)) { + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; + } + // // Initialize the pre-defined cumulative data. // InitCumulativeData (); @@ -821,21 +824,22 @@ RunDp ( // CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, L"-c"); if (CustomCumulativeToken != NULL) { CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA)); if (CustomCumulativeData == NULL) { - return SHELL_OUT_OF_RESOURCES; + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; } CustomCumulativeData->MinDur = PERF_MAXDUR; CustomCumulativeData->MaxDur = 0; CustomCumulativeData->Count = 0; CustomCumulativeData->Duration = 0; NameSize = StrLen (CustomCumulativeToken) + 1; CustomCumulativeData->Name = AllocateZeroPool (NameSize); if (CustomCumulativeData->Name == NULL) { - FreePool (CustomCumulativeData); - return SHELL_OUT_OF_RESOURCES; + ShellStatus = SHELL_OUT_OF_RESOURCES; + goto Done; } UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize); } // -- 2.14.3.windows.1