summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/malloc/realloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc/realloc.c')
-rw-r--r--libc/stdlib/malloc/realloc.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index 4d56565aa..ec57b874e 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
@@ -46,6 +46,11 @@ realloc (void *mem, size_t new_size)
allocation unit (SIZE is already guaranteed to be so).*/
new_size = HEAP_ADJUST_SIZE (new_size + MALLOC_HEADER_SIZE);
+ if (new_size < sizeof (struct heap_free_area))
+ /* Because we sometimes must use a freed block to hold a free-area node,
+ we must make sure that every allocated block can hold one. */
+ new_size = HEAP_ADJUST_SIZE (sizeof (struct heap_free_area));
+
MALLOC_DEBUG (1, "realloc: 0x%lx, %d (base = 0x%lx, total_size = %d)",
(long)mem, new_size, (long)base_mem, size);