summaryrefslogtreecommitdiffstats
path: root/ShellPkg/DynamicCommand
diff options
context:
space:
mode:
authorDandan Bi <dandan.bi@intel.com>2018-05-11 14:02:08 +0800
committerEric Dong <eric.dong@intel.com>2018-06-12 15:50:54 +0800
commit37d533da76e24828dc9b4cf86fa4ef8ec47c22a7 (patch)
tree6a6300feaf139acdc8a390a027b4e6aebdec952d /ShellPkg/DynamicCommand
parentc25d3905523ae4961bb039b1aba597983f7e3e4e (diff)
downloadedk2-37d533da76e24828dc9b4cf86fa4ef8ec47c22a7.tar.gz
edk2-37d533da76e24828dc9b4cf86fa4ef8ec47c22a7.tar.bz2
edk2-37d533da76e24828dc9b4cf86fa4ef8ec47c22a7.zip
ShellPkg/Dp: make sure memory is freed before exit
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 <liming.gao@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Jaben Carsey <jaben.carsey@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi <dandan.bi@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'ShellPkg/DynamicCommand')
-rw-r--r--ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
index aa9c2cdf7a..fe85937f55 100644
--- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
@@ -392,7 +392,7 @@ BuildCachedGuidHandleTable (
FreePool (HandleBuffer);
HandleBuffer = NULL;
}
- return Status;
+ return EFI_SUCCESS;
}
/**
@@ -732,35 +732,6 @@ RunDp (
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);
@@ -812,6 +783,38 @@ RunDp (
}
//
+ // 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 ();
@@ -823,7 +826,8 @@ RunDp (
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;
@@ -832,8 +836,8 @@ RunDp (
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);
}