]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VfrCompile: Avoid freeing memory with mismatched functions
authorHao Wu <hao.a.wu@intel.com>
Tue, 27 Sep 2016 05:40:58 +0000 (13:40 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:37:17 +0000 (16:37 +0800)
Memory allocated by operator new[] should be freed using delete[] to avoid
possible memory leak.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
BaseTools/Source/C/VfrCompile/VfrError.cpp
BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp
BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
BaseTools/Source/C/VfrCompile/VfrUtilityLib.h

index 16453439ec0b148bec6368b0dd408361037c7431..1bca37244d5291d76bea76db3081f6580be9c1a5 100644 (file)
@@ -677,7 +677,7 @@ CVfrCompiler::PreProcess (
     goto Fail;\r
   }\r
 \r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 \r
 Out:\r
   SET_RUN_STATUS (STATUS_PREPROCESSED);\r
@@ -687,7 +687,7 @@ Fail:
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 }\r
 \r
 extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *);\r
index 3c506ec2047609650d0ebf16c37ad31f8e7da730..285e175fa60fc2bc26c637b949ea6078a37c5dee 100644 (file)
@@ -2,7 +2,7 @@
   \r
   VfrCompiler error handler.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -145,7 +145,7 @@ SVfrFileScopeRecord::~SVfrFileScopeRecord (
   )\r
 {\r
   if (mFileName != NULL) {\r
-    delete mFileName;\r
+    delete[] mFileName;\r
   }\r
 }\r
 \r
index 124b8e8e726d6b585fe82dfbab15eca3488e751c..9c76b29418e08f9cf6ad19f4350a1aea46763e3b 100644 (file)
@@ -56,13 +56,13 @@ SPendingAssign::~SPendingAssign (
   )\r
 {\r
   if (mKey != NULL) {\r
-    delete mKey;\r
+    delete[] mKey;\r
   }\r
   mAddr   = NULL;\r
   mLen    = 0;\r
   mLineNo = 0;\r
   if (mMsg != NULL) {\r
-    delete mMsg;\r
+    delete[] mMsg;\r
   }\r
   mNext   = NULL;\r
 }\r
@@ -898,7 +898,7 @@ CFormPkg::DeclarePendingQuestion (
             strcpy (NewStr, SName);\r
             strcat (NewStr, VarStr + strlen (FName));\r
             ReturnCode = lCVfrVarDataTypeDB.GetDataFieldInfo (NewStr, Info.mInfo.mVarOffset, Info.mVarType, Info.mVarTotalSize);\r
-            delete NewStr;\r
+            delete[] NewStr;\r
           }\r
         } else {\r
           ReturnCode = VFR_RETURN_UNSUPPORTED;\r
index 24b0bfa6fd9a0aee4b679781a27b5049b8bb500c..1afa5a2590a1ede8a710ec4bb1e752a39d9d2bde 100644 (file)
@@ -123,7 +123,7 @@ SConfigInfo::~SConfigInfo (
   VOID\r
   )\r
 {\r
-  BUFFER_SAFE_FREE (mValue);\r
+  ARRAY_SAFE_FREE (mValue);\r
 }\r
 \r
 SConfigItem::SConfigItem (\r
@@ -200,9 +200,9 @@ SConfigItem::~SConfigItem (
 {\r
   SConfigInfo  *Info;\r
 \r
-  BUFFER_SAFE_FREE (mName);\r
-  BUFFER_SAFE_FREE (mGuid);\r
-  BUFFER_SAFE_FREE (mId);\r
+  ARRAY_SAFE_FREE (mName);\r
+  ARRAY_SAFE_FREE (mGuid);\r
+  ARRAY_SAFE_FREE (mId);\r
   while (mInfoStrList != NULL) {\r
     Info = mInfoStrList;\r
     mInfoStrList = mInfoStrList->mNext;\r
@@ -1393,7 +1393,7 @@ SVfrVarStorageNode::~SVfrVarStorageNode (
   )\r
 {\r
   if (mVarStoreName != NULL) {\r
-    delete mVarStoreName;\r
+    delete[] mVarStoreName;\r
   }\r
 \r
   if (mVarStoreType == EFI_VFR_VARSTORE_NAME) {\r
@@ -2102,7 +2102,7 @@ SVfrDefaultStoreNode::~SVfrDefaultStoreNode (
   )\r
 {\r
   if (mRefName != NULL) {\r
-    delete mRefName;\r
+    delete[] mRefName;\r
   }\r
 }\r
 \r
@@ -2304,7 +2304,7 @@ SVfrRuleNode::~SVfrRuleNode (
   )\r
 {\r
   if (mRuleName != NULL) {\r
-    delete mRuleName;\r
+    delete[] mRuleName;\r
   }\r
 }\r
 \r
@@ -2523,11 +2523,11 @@ SVfrQuestionNode::~SVfrQuestionNode (
   )\r
 {\r
   if (mName != NULL) {\r
-    delete mName;\r
+    delete[] mName;\r
   }\r
 \r
   if (mVarIdStr != NULL) {\r
-    delete mVarIdStr;\r
+    delete[] mVarIdStr;\r
   }\r
 }\r
 \r
@@ -3387,7 +3387,7 @@ CVfrStringDB::GetVarStoreNameFormStringId (
   // Check the String package.\r
   //\r
   if (PkgHeader->Header.Type != EFI_HII_PACKAGE_STRINGS) {\r
-    delete StringPtr;\r
+    delete[] StringPtr;\r
     return NULL;\r
   }\r
 \r
@@ -3414,7 +3414,7 @@ CVfrStringDB::GetVarStoreNameFormStringId (
   //\r
   Status = FindStringBlock(Current, StringId, &NameOffset, &BlockType);\r
   if (Status != EFI_SUCCESS) {\r
-    delete StringPtr;\r
+    delete[] StringPtr;\r
     return NULL;\r
   }\r
 \r
@@ -3447,7 +3447,7 @@ CVfrStringDB::GetVarStoreNameFormStringId (
     break;\r
   }\r
 \r
-  delete StringPtr;\r
+  delete[] StringPtr;\r
 \r
   return VarStoreName;\r
 }\r
index 5faa1f40fdcfdfb480bfaba6d0fa1f01ad7eb916..35d17a031b1b47b87c3df546fe00d05ce09cb26c 100644 (file)
@@ -33,6 +33,8 @@ extern BOOLEAN  VfrCompatibleMode;
 #define EFI_BITS_PER_UINT32                (1 << EFI_BITS_SHIFT_PER_UINT32)\r
 \r
 #define BUFFER_SAFE_FREE(Buf)              do { if ((Buf) != NULL) { delete (Buf); } } while (0);\r
+#define ARRAY_SAFE_FREE(Buf)               do { if ((Buf) != NULL) { delete[] (Buf); } } while (0);\r
+\r
 \r
 class CVfrBinaryOutput {\r
 public:\r
@@ -139,7 +141,7 @@ struct SVfrPackStackNode {
 \r
   ~SVfrPackStackNode (VOID) {\r
     if (mIdentifier != NULL) {\r
-      delete mIdentifier;\r
+      delete[] mIdentifier;\r
     }\r
     mNext = NULL;\r
   }\r