diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2018-05-24 23:53:15 -0400 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2018-05-29 10:16:48 -0400 |
commit | 4a3d0a5a5d829c05868a34658eb45731dbb5112b (patch) | |
tree | e6600b9c33f8f5fea13a32e0253eb110edb17c7f | |
parent | fcfea0ae2d213383f38b06690b6cf1454f2ac82d (diff) | |
download | cygnal-4a3d0a5a5d829c05868a34658eb45731dbb5112b.tar.gz cygnal-4a3d0a5a5d829c05868a34658eb45731dbb5112b.tar.bz2 cygnal-4a3d0a5a5d829c05868a34658eb45731dbb5112b.zip |
Fix issue with malloc_extend_top
- when calculating a correction to align next brk to page boundary,
ensure that the correction is less than a page size
- if allocating the correction fails, ensure that the top size is
set to brk + sbrk_size (minus any front alignment made)
Signed-off-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r-- | newlib/libc/stdlib/mallocr.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c index ecc445f3d..26d1c89cc 100644 --- a/newlib/libc/stdlib/mallocr.c +++ b/newlib/libc/stdlib/mallocr.c @@ -2198,13 +2198,18 @@ static void malloc_extend_top(RARG nb) RDECL INTERNAL_SIZE_T nb; /* Guarantee the next brk will be at a page boundary */ correction += pagesz - ((POINTER_UINT)(brk + sbrk_size) & (pagesz - 1)); + /* To guarantee page boundary, correction should be less than pagesz */ + correction &= (pagesz - 1); + /* Allocate correction */ new_brk = (char*)(MORECORE (correction)); if (new_brk == (char*)(MORECORE_FAILURE)) { correction = 0; correction_failed = 1; - new_brk = brk; + new_brk = brk + sbrk_size; + if (front_misalign > 0) + new_brk -= (MALLOC_ALIGNMENT) - front_misalign; } sbrked_mem += correction; |