aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-minimal.c
diff options
context:
space:
mode:
Diffstat (limited to 'elf/dl-minimal.c')
-rw-r--r--elf/dl-minimal.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index d1619cf..3a51df3 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -104,9 +104,10 @@ malloc (size_t n)
void * weak_function
calloc (size_t nmemb, size_t size)
{
- size_t total = nmemb * size;
- void *result = malloc (total);
- return memset (result, '\0', total);
+ /* New memory from the trivial malloc above is always already cleared.
+ (We make sure that's true in the rare occasion it might not be,
+ by clearing memory in free, below.) */
+ return malloc (nmemb * size);
}
/* This will rarely be called. */
@@ -115,7 +116,12 @@ free (void *ptr)
{
/* We can free only the last block allocated. */
if (ptr == alloc_last_block)
- alloc_ptr = alloc_last_block;
+ {
+ /* Since this is rare, we clear the freed block here
+ so that calloc can presume malloc returns cleared memory. */
+ memset (alloc_last_block, '\0', alloc_ptr - alloc_last_block);
+ alloc_ptr = alloc_last_block;
+ }
}
/* This is only called with the most recent block returned by malloc. */