gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 05/10: MHD_pool_reallocate(): never allocat


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 05/10: MHD_pool_reallocate(): never allocate additional buffer when shrinking
Date: Mon, 17 Jun 2019 20:35:48 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 3cb0b6cf17e2cc6cd62133a0beffa998b1e53c23
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Jun 16 22:57:10 2019 +0300

    MHD_pool_reallocate(): never allocate additional buffer when shrinking
---
 src/microhttpd/memorypool.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 27c949fc..6f74db83 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -321,15 +321,16 @@ MHD_pool_reallocate (struct MemoryPool *pool,
   if (0 != old_size)
     { /* Need to save some data */
       const size_t old_offset = (uint8_t*)old - pool->memory;
+      const bool shrinking = (old_size > new_size);
       /* Try resizing in-place */
+      if (shrinking)
+        { /* Shrinking in-place, zero-out freed part */
+          memset ((uint8_t*)old + new_size, 0, old_size - new_size);
+        }
       if (pool->pos == ROUND_TO_ALIGN (old_offset + old_size))
         { /* "old" block is the last allocated block */
           const size_t new_apos = ROUND_TO_ALIGN (old_offset + new_size);
-          if (old_size > new_size)
-            { /* Shrinking in-place, zero-out freed part */
-              memset ((uint8_t*)old + new_size, 0, old_size - new_size);
-            }
-          else
+          if (!shrinking)
             { /* Grow in-place, check for enough space. */
               if ( (new_apos > pool->end) ||
                    (new_apos < pool->pos) ) /* Value wrap */
@@ -339,6 +340,8 @@ MHD_pool_reallocate (struct MemoryPool *pool,
           pool->pos = new_apos;
           return old;
         }
+      if (shrinking)
+        return old; /* Resized in-place, freed part remains allocated */
     }
   /* Need to allocate new block */
   asize = ROUND_TO_ALIGN (new_size);

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]