Skip to content

Commit

Permalink
CryptoPkg: RuntimeCryptLib: support free(NULL)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lersek committed Feb 25, 2016
1 parent 211372d commit 1246dde
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1246dde

Please sign in to comment.