[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.
- [GNUnet-SVN] [libmicrohttpd] branch master updated (d12ed49f -> 55dc42e6), gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 04/10: memorypool: comments minor improvements, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 05/10: MHD_pool_reallocate(): never allocate additional buffer when shrinking,
gnunet <=
- [GNUnet-SVN] [libmicrohttpd] 07/10: transmit_error_response(): discard read buffer to free space for error response, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 09/10: try_ready_chunked_body(): remove useless loop, use know free memory size instead of guessing, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 01/10: memorypool: fixed MHD_pool_reset(), gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 03/10: memorypool: re-commit memory on W32 when resetting pool, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 06/10: test_long_header: use power of two for size to properly test allocations, test various buffer sizes, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 02/10: memorypool: round mmap allocation for page size, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 10/10: Optimised read buffer allocation, gnunet, 2019/06/17
- [GNUnet-SVN] [libmicrohttpd] 08/10: process_request_body(): do not move data if nothing was processed, gnunet, 2019/06/17