BaseTools/VfrCompile: Avoid freeing freed memory in classes

For classes that contain dynamically allocated data members, copy
constructor and assignment operator should be implemented or both
operations should be prohibited to avoid freeing freed memory caused by
shallow copy.

This commit declares both copy constructor and assignment operator as
'private' for classes that contain dynamically allocated data members.
This will prevent freeing already freed memory.

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>
This commit is contained in:
Hao Wu
2016-09-27 13:43:32 +08:00
parent 0d46defefa
commit 77dee0b185
4 changed files with 79 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
VfrCompiler Error definition
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -73,6 +73,10 @@ struct SVfrFileScopeRecord {
SVfrFileScopeRecord (IN CHAR8 *, IN UINT32);
~SVfrFileScopeRecord();
private:
SVfrFileScopeRecord (IN CONST SVfrFileScopeRecord&); // Prevent copy-construction
SVfrFileScopeRecord& operator= (IN CONST SVfrFileScopeRecord&); // Prevent assignment
};
class CVfrErrorHandle {
@@ -95,6 +99,10 @@ public:
UINT8 HandleError (IN EFI_VFR_RETURN_CODE, IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL);
UINT8 HandleWarning (IN EFI_VFR_WARNING_CODE, IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL);
VOID PrintMsg (IN UINT32 LineNum = 0, IN CHAR8 *TokName = NULL, IN CONST CHAR8 *MsgType = "Error", IN CONST CHAR8 *ErrorMsg = "");
private:
CVfrErrorHandle (IN CONST CVfrErrorHandle&); // Prevent copy-construction
CVfrErrorHandle& operator= (IN CONST CVfrErrorHandle&); // Prevent assignment
};
#define CHECK_ERROR_RETURN(f, v) do { EFI_VFR_RETURN_CODE r; if ((r = (f)) != (v)) { return r; } } while (0)