summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2016-02-24 21:00:04 +0100
committerLaszlo Ersek <lersek@redhat.com>2016-02-26 18:30:14 +0100
commitffbb5ae3ba7da2ece8dbf116b1eb0718c346d19b (patch)
treee4d4c3171582bb80c69e5df5e21f3a385096a871 /MdeModulePkg
parent328d8cfa6278a5558ce510662df73f4c17086567 (diff)
downloadedk2-ffbb5ae3ba7da2ece8dbf116b1eb0718c346d19b.tar.gz
edk2-ffbb5ae3ba7da2ece8dbf116b1eb0718c346d19b.tar.bz2
edk2-ffbb5ae3ba7da2ece8dbf116b1eb0718c346d19b.zip
MdeModulePkg: RegularExpressionDxe: support free(NULL)
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 <cecil.sheng@hpe.com> Cc: Cinnamon Shia <cinnamon.shia@hpe.com> Cc: Eric Dong <eric.dong@intel.com> Cc: Qiu Shumin <shumin.qiu@intel.com> Cc: Samer El-Haj-Mahmoud <elhaj@hpe.com> Cc: Yao Jiewen <Jiewen.Yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-By: Cinnamon Shia <cinnamon.shia@hpe.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h
index cb791f8c84..ca478de68e 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 = (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)