diff mbox

malloc/malloc.c: Avoid calling sbrk unnecessarily with zero

Message ID 1402674104-13759-1-git-send-email-will.newton@linaro.org
State Accepted
Commit 51a7380b8968251a49a4c5b0bc7ed1af5b0512c6
Headers show

Commit Message

Will Newton June 13, 2014, 3:41 p.m. UTC
Due to my bad review suggestion for the fix for BZ #15089 a check
was removed from systrim to prevent sbrk being called with a zero
argument. Add the check back to avoid this useless work.

ChangeLog:

2014-06-13  Will Newton  <will.newton@linaro.org>

	* malloc/malloc.c (systrim): If extra is zero then return
	early.
---
 malloc/malloc.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Siddhesh Poyarekar June 18, 2014, 9:15 a.m. UTC | #1
On Fri, Jun 13, 2014 at 04:41:44PM +0100, Will Newton wrote:
> Due to my bad review suggestion for the fix for BZ #15089 a check
> was removed from systrim to prevent sbrk being called with a zero
> argument. Add the check back to avoid this useless work.
> 
> ChangeLog:
> 
> 2014-06-13  Will Newton  <will.newton@linaro.org>
> 
> 	* malloc/malloc.c (systrim): If extra is zero then return
> 	early.

Looks good to me.

Siddhesh

> ---
>  malloc/malloc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index d8fd8b4..41fd76a 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -2749,6 +2749,9 @@ systrim (size_t pad, mstate av)
>    /* Release in pagesize units, keeping at least one page */
>    extra = (top_area - pad) & ~(pagesz - 1);
>  
> +  if (extra == 0)
> +    return 0;
> +
>    /*
>       Only proceed if end of memory is where we last set it.
>       This avoids problems if there were foreign sbrk calls.
> -- 
> 1.9.3
>
diff mbox

Patch

diff --git a/malloc/malloc.c b/malloc/malloc.c
index d8fd8b4..41fd76a 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2749,6 +2749,9 @@  systrim (size_t pad, mstate av)
   /* Release in pagesize units, keeping at least one page */
   extra = (top_area - pad) & ~(pagesz - 1);
 
+  if (extra == 0)
+    return 0;
+
   /*
      Only proceed if end of memory is where we last set it.
      This avoids problems if there were foreign sbrk calls.