]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: RuntimeCryptLib: support free(NULL)
authorLaszlo Ersek <lersek@redhat.com>
Wed, 24 Feb 2016 20:00:04 +0000 (21:00 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 25 Feb 2016 10:04:28 +0000 (11:04 +0100)
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>
Reviewed-by: Qin Long <qin.long@intel.com>
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c

index 616ee7717e72859b993da72b37d939dff00c1e5a..45ef9ff5f2525a48f7dbf8c7e52202cc09a1dbdd 100644 (file)
@@ -434,5 +434,11 @@ void *realloc (void *ptr, size_t size)
 /* Deallocates or frees a memory block */\r
 void free (void *ptr)\r
 {\r
-  RuntimeFreeMem (ptr);\r
+  //\r
+  // In Standard C, free() handles a null pointer argument transparently. This\r
+  // is not true of RuntimeFreeMem() below, so protect it.\r
+  //\r
+  if (ptr != NULL) {\r
+    RuntimeFreeMem (ptr);\r
+  }\r
 }\r