From 6cb40a679b23b07b9fe0c43147d300b630deec70 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 30 Apr 2021 14:04:08 +0100 Subject: [PATCH] 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. --- bfd/ChangeLog | 6 ++++++ bfd/libbfd.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index cd904dac58..548ed9f57d 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 9db14c3c22..52c924560b 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; -- 2.34.1