diff options
author | Laszlo Ersek <lersek@redhat.com> | 2016-02-24 21:00:04 +0100 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-02-26 09:44:13 +0800 |
commit | 547b9e2744c4b18de4e5af62756e865a175c7e36 (patch) | |
tree | 2b0a952267e6b778e660d1a68fbe3642a03b145f /CryptoPkg | |
parent | d14fd60dc0227b6fa9b18a344fb2aa0e73303a4b (diff) | |
download | edk2-platforms-547b9e2744c4b18de4e5af62756e865a175c7e36.tar.xz |
CryptoPkg: RuntimeCryptLib: support free(NULL)
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>
(cherry picked from commit 1246dde58e8a84644ad46679b8767f8643818e31)
Diffstat (limited to 'CryptoPkg')
-rw-r--r-- | CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c index 616ee7717e..45ef9ff5f2 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);
+ }
}
|