diff mbox

[edk2,2/4] CryptoPkg: RuntimeCryptLib: support free(NULL)

Message ID 1456348432-18818-3-git-send-email-lersek@redhat.com
State Accepted
Commit 211372d63a82861e52250c0f7a5ee78d9dc417ae
Headers show

Commit Message

Laszlo Ersek Feb. 24, 2016, 9:13 p.m. UTC
The ISO C standard says about free(),

  If ptr is a null pointer, no action occurs.

This is not true of the RuntimeFreeMem() internal function. Therefore we
must not forward the argument of free() to RuntimeFreeMem() without
checking.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Qin Long <qin.long@intel.com>
Cc: Ting Ye <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---
 CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
1.8.3.1


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
index 616ee7717e72..45ef9ff5f252 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
@@ -434,5 +434,11 @@  void *realloc (void *ptr, size_t size)
 /* Deallocates or frees a memory block */
 void free (void *ptr)
 {
-  RuntimeFreeMem (ptr);
+  //
+  // In Standard C, free() handles a null pointer argument transparently. This
+  // is not true of RuntimeFreeMem() below, so protect it.
+  //
+  if (ptr != NULL) {
+    RuntimeFreeMem (ptr);
+  }
 }