From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59456 invoked by alias); 29 May 2018 14:17:31 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 52006 invoked by uid 447); 29 May 2018 14:17:04 -0000 Date: Tue, 29 May 2018 14:17:00 -0000 Message-ID: <20180529141704.52003.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix issue with malloc_extend_top X-Act-Checkin: newlib-cygwin X-Git-Author: Jeff Johnston X-Git-Refname: refs/heads/master X-Git-Oldrev: fcfea0ae2d213383f38b06690b6cf1454f2ac82d X-Git-Newrev: 4a3d0a5a5d829c05868a34658eb45731dbb5112b X-SW-Source: 2018-q2/txt/msg00006.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4a3d0a5a5d829c05868a34658eb45731dbb5112b commit 4a3d0a5a5d829c05868a34658eb45731dbb5112b Author: Jeff Johnston 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 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;