This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][BZ 15089] Fixes malloc_trim always trims for large padding


Hi OndÅej!

Thanks for the reply! Here is the patch with the change as you asked.

Cheers,

Fernando J V da Silva



2013/12/3 OndÅej BÃlka <neleai@seznam.cz>:
> On Thu, Nov 21, 2013 at 09:11:20PM -0200, Fernando J V da Silva wrote:
>> Hi Will!
>>
>> Ah, Ok! I just got confused... Thanks for explaining!
>> Here is the patch again, now with the changes you requested in the
>> first e-mail and with ChangeLog inside the commit message.
>>
>> Cheers,
>>
> A changed patch no longer applies as we added LIBC_PROBE in meantime.
>
> Could you send patch that replaces deleted if by if (1) and then I could
> fix formatting.
From 18aa066d8a781176f20e5f39030330e9d041bff5 Mon Sep 17 00:00:00 2001
From: Fernando J. V. da Silva <fernandojvdasilva@gmail.com>
Date: Fri, 6 Dec 2013 01:40:50 -0200
Subject: [PATCH] Fix BZ #15089: malloc_trim always trim for large padding.

At systrim(), if the heap top size is bigger than requested pad, then
doesn't calculate size to call sbrk().

2013-11-21 Fernando J. V. da Silva <fernandojvdasilva@gmail.com>

        [BZ #15089]
        * malloc/malloc.c: Exit systrim() if pad is bigger than heap top size.
---
 malloc/malloc.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index be472b2..42f7389 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2712,15 +2712,19 @@ static int systrim(size_t pad, mstate av)
   char* current_brk;     /* address returned by pre-check sbrk call */
   char* new_brk;         /* address returned by post-check sbrk call */
   size_t pagesz;
+  long  top_area;
 
   pagesz = GLRO(dl_pagesize);
   top_size = chunksize(av->top);
 
   /* Release in pagesize units, keeping at least one page */
-  extra = (top_size - pad - MINSIZE - 1) & ~(pagesz - 1);
+  top_area = top_size - MINSIZE - 1;
+  if (top_area <= pad)
+    return 0;
 
-  if (extra > 0) {
+  extra = (top_area - pad) & ~(pagesz - 1);
 
+  if (1) {
     /*
       Only proceed if end of memory is where we last set it.
       This avoids problems if there were foreign sbrk calls.
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]