]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/Dp: make sure memory is freed before exit
authorDandan Bi <dandan.bi@intel.com>
Fri, 11 May 2018 06:02:08 +0000 (14:02 +0800)
committerEric Dong <eric.dong@intel.com>
Tue, 12 Jun 2018 07:50:54 +0000 (15:50 +0800)
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>
ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c

index aa9c2cdf7a83b5a82bcf85c0b62f78ee112463d1..fe85937f557b4ffdb64b31a6113baf5d072cb53e 100644 (file)
@@ -392,7 +392,7 @@ BuildCachedGuidHandleTable (
     FreePool (HandleBuffer);\r
     HandleBuffer = NULL;\r
   }\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -731,35 +731,6 @@ RunDp (
   Status = ShellInitialize();\r
   ASSERT_EFI_ERROR(Status);\r
 \r
-  //\r
-  // DP dump performance data by parsing FPDT table in ACPI table.\r
-  // Folloing 3 steps are to get the measurement form the FPDT table.\r
-  //\r
-\r
-  //\r
-  //1. Get FPDT from ACPI table.\r
-  //\r
-  Status = GetBootPerformanceTable ();\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  //2. Cache the ModuleGuid and hanlde mapping table.\r
-  //\r
-  Status = BuildCachedGuidHandleTable();\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  //3. Build the measurement array form the FPDT records.\r
-  //\r
-  Status = BuildMeasurementList ();\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
   //\r
   // Process Command Line arguments\r
   //\r
@@ -811,6 +782,38 @@ RunDp (
 #endif  // PROFILING_IMPLEMENTED\r
   }\r
 \r
+  //\r
+  // DP dump performance data by parsing FPDT table in ACPI table.\r
+  // Folloing 3 steps are to get the measurement form the FPDT table.\r
+  //\r
+\r
+  //\r
+  //1. Get FPDT from ACPI table.\r
+  //\r
+  Status = GetBootPerformanceTable ();\r
+  if (EFI_ERROR (Status)) {\r
+    ShellStatus = Status;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  //2. Cache the ModuleGuid and hanlde mapping table.\r
+  //\r
+  Status = BuildCachedGuidHandleTable();\r
+  if (EFI_ERROR (Status)) {\r
+    ShellStatus = Status;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  //3. Build the measurement array form the FPDT records.\r
+  //\r
+  Status = BuildMeasurementList ();\r
+  if (EFI_ERROR (Status)) {\r
+    ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+\r
   //\r
   // Initialize the pre-defined cumulative data.\r
   //\r
@@ -823,7 +826,8 @@ RunDp (
   if (CustomCumulativeToken != NULL) {\r
     CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA));\r
     if (CustomCumulativeData == NULL) {\r
-      return SHELL_OUT_OF_RESOURCES;\r
+      ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+      goto Done;\r
     }\r
     CustomCumulativeData->MinDur = PERF_MAXDUR;\r
     CustomCumulativeData->MaxDur = 0;\r
@@ -832,8 +836,8 @@ RunDp (
     NameSize = StrLen (CustomCumulativeToken) + 1;\r
     CustomCumulativeData->Name   = AllocateZeroPool (NameSize);\r
     if (CustomCumulativeData->Name == NULL) {\r
-      FreePool (CustomCumulativeData);\r
-      return SHELL_OUT_OF_RESOURCES;\r
+      ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+      goto Done;\r
     }\r
     UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize);\r
   }\r