]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
CryptoPkg: RuntimeCryptLib: support free(NULL)
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / RuntimeMemAllocation.c
index f615ae8f903c3efabff99831b6bf3eb17dd047ee..45ef9ff5f2525a48f7dbf8c7e52202cc09a1dbdd 100644 (file)
@@ -2,7 +2,7 @@
   Light-weight Memory Management Routines for OpenSSL-based Crypto\r
   Library at Runtime Phase.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -38,7 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define RT_PAGE_FREE                0x00000000\r
 #define RT_PAGE_USED                0x00000001\r
 \r
-#define MIN_REQUIRED_BLOCKS         24\r
+#define MIN_REQUIRED_BLOCKS         600\r
 \r
 //\r
 // Memory Page Table\r
@@ -64,7 +64,7 @@ RT_MEMORY_PAGE_TABLE  *mRTPageTable = NULL;
 //\r
 // Event for Runtime Address Conversion.\r
 //\r
-EFI_EVENT             mVirtualAddressChangeEvent;\r
+STATIC EFI_EVENT      mVirtualAddressChangeEvent;\r
 \r
 \r
 /**\r
@@ -385,7 +385,7 @@ RuntimeCryptLibConstructor (
 /* Allocates memory blocks */\r
 void *malloc (size_t size)\r
 {\r
-  return RuntimeAllocateMem ((UINTN)size);\r
+  return RuntimeAllocateMem ((UINTN) size);\r
 }\r
 \r
 /* Reallocate memory blocks */\r
@@ -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