gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36643 - in libmicrohttpd: . src/include src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r36643 - in libmicrohttpd: . src/include src/microhttpd
Date: Fri, 6 Nov 2015 22:56:46 +0100

Author: grothoff
Date: 2015-11-06 22:56:46 +0100 (Fri, 06 Nov 2015)
New Revision: 36643

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/include/microhttpd.h
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/memorypool.c
   libmicrohttpd/src/microhttpd/memorypool.h
Log:
-fix shrinkage

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2015-11-04 23:05:33 UTC (rev 36642)
+++ libmicrohttpd/ChangeLog     2015-11-06 21:56:46 UTC (rev 36643)
@@ -1,3 +1,6 @@
+Fri Nov  6 22:54:38 CET 2015
+       Fixing the buffer shrinkage issue, this time with test. -CG
+
 Tue Nov  3 23:24:52 CET 2015
        Undoing change from Sun Oct 25 15:29:23 CET 2015
        as the original code was counter-intuitive but

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2015-11-04 23:05:33 UTC (rev 
36642)
+++ libmicrohttpd/src/include/microhttpd.h      2015-11-06 21:56:46 UTC (rev 
36643)
@@ -130,7 +130,7 @@
  * Current version of the library.
  * 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00094600
+#define MHD_VERSION 0x00094601
 
 /**
  * MHD-internal return code for "YES".

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2015-11-04 23:05:33 UTC (rev 
36642)
+++ libmicrohttpd/src/microhttpd/connection.c   2015-11-06 21:56:46 UTC (rev 
36643)
@@ -2559,14 +2559,15 @@
               /* can try to keep-alive */
               connection->version = NULL;
               connection->state = MHD_CONNECTION_INIT;
-              /* read_buffer_size is correct here, as we want to
-                 preserve the entire read buffer allocation, even
-                 if in terms of the data we only care to preserve
-                 up to "read_buffer_offset" */
+              /* Reset the read buffer to the starting size,
+                 preserving the bytes we have already read. */
               connection->read_buffer
                 = MHD_pool_reset (connection->pool,
                                   connection->read_buffer,
-                                  connection->read_buffer_size);
+                                  connection->read_buffer_offset,
+                                  connection->daemon->pool_size / 2);
+              connection->read_buffer_size
+                = connection->daemon->pool_size / 2;
             }
          connection->client_aware = MHD_NO;
           connection->client_context = NULL;

Modified: libmicrohttpd/src/microhttpd/memorypool.c
===================================================================
--- libmicrohttpd/src/microhttpd/memorypool.c   2015-11-04 23:05:33 UTC (rev 
36642)
+++ libmicrohttpd/src/microhttpd/memorypool.c   2015-11-06 21:56:46 UTC (rev 
36643)
@@ -219,7 +219,8 @@
   if ((pool->end < old_size) || (pool->end < asize))
     return NULL;                /* unsatisfiable or bogus request */
 
-  if ((pool->pos >= old_size) && (&pool->memory[pool->pos - old_size] == old))
+  if ( (pool->pos >= old_size) &&
+       (&pool->memory[pool->pos - old_size] == old) )
     {
       /* was the previous allocation - optimize! */
       if (pool->pos + asize - old_size <= pool->end)
@@ -251,32 +252,40 @@
 
 /**
  * Clear all entries from the memory pool except
- * for @a keep of the given @a size.
+ * for @a keep of the given @a size. The pointer
+ * returned should be a buffer of @a new_size where
+ * the first @a copy_bytes are from @a keep.
  *
  * @param pool memory pool to use for the operation
  * @param keep pointer to the entry to keep (maybe NULL)
- * @param size how many bytes need to be kept at this address
+ * @param copy_bytes how many bytes need to be kept at this address
+ * @param new_size how many bytes should the allocation we return have?
+ *                 (should be larger or equal to @a copy_bytes)
  * @return addr new address of @a keep (if it had to change)
  */
 void *
 MHD_pool_reset (struct MemoryPool *pool,
                void *keep,
-               size_t size)
+               size_t copy_bytes,
+                size_t new_size)
 {
   if (NULL != keep)
     {
       if (keep != pool->memory)
         {
-          memmove (pool->memory, keep, size);
+          memmove (pool->memory,
+                   keep,
+                   copy_bytes);
           keep = pool->memory;
         }
     }
   pool->end = pool->size;
-  memset (&pool->memory[size],
+  /* technically not needed, but safer to zero out */
+  memset (&pool->memory[copy_bytes],
          0,
-         pool->size - size);
+         pool->size - copy_bytes);
   if (NULL != keep)
-    pool->pos = ROUND_TO_ALIGN(size);
+    pool->pos = ROUND_TO_ALIGN (new_size);
   return keep;
 }
 

Modified: libmicrohttpd/src/microhttpd/memorypool.h
===================================================================
--- libmicrohttpd/src/microhttpd/memorypool.h   2015-11-04 23:05:33 UTC (rev 
36642)
+++ libmicrohttpd/src/microhttpd/memorypool.h   2015-11-06 21:56:46 UTC (rev 
36643)
@@ -99,16 +99,21 @@
 
 /**
  * Clear all entries from the memory pool except
- * for "keep" of the given "size".
+ * for @a keep of the given @a copy_bytes.  The pointer
+ * returned should be a buffer of @a new_size where
+ * the first @a copy_bytes are from @a keep.
  *
  * @param pool memory pool to use for the operation
  * @param keep pointer to the entry to keep (maybe NULL)
- * @param size how many bytes need to be kept at this address
- * @return addr new address of "keep" (if it had to change)
+ * @param copy_bytes how many bytes need to be kept at this address
+ * @param new_size how many bytes should the allocation we return have?
+ *                 (should be larger or equal to @a copy_bytes)
+ * @return addr new address of @a keep (if it had to change)
  */
 void *
 MHD_pool_reset (struct MemoryPool *pool,
                void *keep,
-               size_t size);
+               size_t copy_bytes,
+                size_t new_size);
 
 #endif




reply via email to

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