public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Fix issue with malloc_extend_top
@ 2018-05-29 14:17 Jeff Johnston
  0 siblings, 0 replies; only message in thread
From: Jeff Johnston @ 2018-05-29 14:17 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4a3d0a5a5d829c05868a34658eb45731dbb5112b

commit 4a3d0a5a5d829c05868a34658eb45731dbb5112b
Author: Jeff Johnston <jjohnstn@redhat.com>
Date:   Thu May 24 23:53:15 2018 -0400

    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>

Diff:
---
 newlib/libc/stdlib/mallocr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
index ecc445f..26d1c89 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-05-29 14:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29 14:17 [newlib-cygwin] Fix issue with malloc_extend_top Jeff Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).