]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StdLib/LibC/StdLib/Malloc.c: Make the free() function conform to the ISO/IEC 9899...
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 24 Sep 2012 22:44:03 +0000 (22:44 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 24 Sep 2012 22:44:03 +0000 (22:44 +0000)
The C95 specification states: "The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation.  If ptr is a null pointer, no action occurs".  The UEFI FreePool() function, which the StdLib implementation of free() uses, does not make this check.  This fix adds a check for null to the free() function such that if the pointer argument is NULL, nothing is done.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: erik.c.bjorge@intel.com
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13739 6f19259b-4bc3-4df7-8a09-765794883524

StdLib/LibC/StdLib/Malloc.c

index 51068d3a06501cbe8e6ebabd66d28e933f1a7cc6..3f79deb49bed4c5294ca8b7fd00ffe40471fafda 100644 (file)
@@ -137,7 +137,9 @@ calloc(size_t Num, size_t Size)
 void\r
 free(void *Ptr)\r
 {\r
-  (void) gBS->FreePool (Ptr);\r
+  if(Ptr != NULL) {\r
+    (void) gBS->FreePool (Ptr);\r
+  }\r
 }\r
 \r
 /** The realloc function changes the size of the object pointed to by Ptr to\r