From: Nick Clifton Date: Fri, 30 Apr 2021 13:04:08 +0000 (+0100) Subject: Fix a double free when re-allocating a buffer to size 0. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6cb40a679b23b07b9fe0c43147d300b630deec70;p=binutils-gdb.git Fix a double free when re-allocating a buffer to size 0. PR 27797 * libbfd.c (bfd_realloc_or_free): Do not free a pointer than has been realloc'ed to size 0. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index cd904dac586..548ed9f57d3 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2021-04-30 Nick Clifton + + PR 27797 + * libbfd.c (bfd_realloc_or_free): Do not free a pointer than has + been realloc'ed to size 0. + 2021-04-30 Nick Clifton PR 27795 diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 9db14c3c22f..52c924560b2 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -312,7 +312,7 @@ bfd_realloc_or_free (void *ptr, bfd_size_type size) { void *ret = bfd_realloc (ptr, size); - if (ret == NULL) + if (ret == NULL && size > 0) free (ptr); return ret;