The ISO C standard says about free(), If ptr is a null pointer, no action occurs.
This is not true of the FreePool() interface of the MemoryAllocationLib class: Buffer must have been allocated on a previous call to the pool allocation services of the Memory Allocation Library. [...] If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, then ASSERT(). Therefore we must not forward the argument of free() to FreePool() without checking. Cc: Cecil Sheng <[email protected]> Cc: Cinnamon Shia <[email protected]> Cc: Eric Dong <[email protected]> Cc: Qiu Shumin <[email protected]> Cc: Samer El-Haj-Mahmoud <[email protected]> Cc: Yao Jiewen <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <[email protected]> --- Notes: Build-tested only. MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h index cb791f8c84c6..b970aaa48c0e 100644 --- a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h +++ b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h @@ -30,7 +30,17 @@ typedef UINTN size_t; #define malloc(n) AllocatePool(n) #define calloc(n,s) AllocateZeroPool((n)*(s)) -#define free(p) FreePool(p) + +#define free(p) \ + do { \ + VOID *EvalOnce; \ + \ + EvalOnce = (VOID *)(p); \ + if (EvalOnce != NULL) { \ + FreePool (EvalOnce); \ + } \ + } while (FALSE) + #define realloc(OldPtr,NewSize,OldSize) ReallocatePool(OldSize,NewSize,OldPtr) #define xmemmove(Dest,Src,Length) CopyMem(Dest,Src,Length) #define xmemcpy(Dest,Src,Length) CopyMem(Dest,Src,Length) -- 1.8.3.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

