]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: RegularExpressionDxe: support free(NULL)
authorLaszlo Ersek <lersek@redhat.com>
Wed, 24 Feb 2016 20:00:04 +0000 (21:00 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 26 Feb 2016 17:30:14 +0000 (18:30 +0100)
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>
MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h

index cb791f8c84c65679e329ca4c74fe6ef3ecfe6520..ca478de68e772c2bd074231569a8b5bdf20a2b19 100644 (file)
@@ -30,7 +30,17 @@ typedef UINTN size_t;
 \r
 #define malloc(n) AllocatePool(n)\r
 #define calloc(n,s) AllocateZeroPool((n)*(s))\r
-#define free(p) FreePool(p)\r
+\r
+#define free(p)             \\r
+  do {                      \\r
+    VOID *EvalOnce;         \\r
+                            \\r
+    EvalOnce = (p);         \\r
+    if (EvalOnce != NULL) { \\r
+      FreePool (EvalOnce);  \\r
+    }                       \\r
+  } while (FALSE)\r
+\r
 #define realloc(OldPtr,NewSize,OldSize) ReallocatePool(OldSize,NewSize,OldPtr)\r
 #define xmemmove(Dest,Src,Length) CopyMem(Dest,Src,Length)\r
 #define xmemcpy(Dest,Src,Length) CopyMem(Dest,Src,Length)\r