You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@commons.apache.org by gs...@apache.org on 2003/10/31 20:09:35 UTC
svn commit: rev 65 - commons/serf/branches/gen2/buckets
Author: gstein
Date: Fri Oct 31 11:09:35 2003
New Revision: 65
Modified:
commons/serf/branches/gen2/buckets/buckets.c
Log:
Fix a problem with zeroing node->size.
* gen2/buckets/buckets.c:
(DEBUG_DOUBLE_FREE): new define to enable double-free checking. leaving
this off can speed up allocation/freeing by a little bit.
(serf_bucket_mem_alloc): if we're looking for double-frees, then the
node size was reset before it was placed into the free list. put it
back to STANDARD_NODE_SIZE.
(serf_bucket_mem_free): only set the size to zero if the double-free
checking is enabled. only do the check when enabled.
Modified: commons/serf/branches/gen2/buckets/buckets.c
==============================================================================
--- commons/serf/branches/gen2/buckets/buckets.c (original)
+++ commons/serf/branches/gen2/buckets/buckets.c Fri Oct 31 11:09:35 2003
@@ -95,6 +95,11 @@
*/
#define ALLOC_AMT (8192 - APR_MEMNODE_T_SIZE)
+/* Define DEBUG_DOUBLE_FREE if you're interested in debugging double-free
+ * calls to serf_bucket_mem_free().
+ */
+#define DEBUG_DOUBLE_FREE
+
struct serf_bucket_alloc_t {
apr_pool_t *pool;
@@ -251,6 +256,13 @@
/* just pull a node off our freelist */
node = allocator->freelist;
allocator->freelist = node->u.next;
+#ifdef DEBUG_DOUBLE_FREE
+ /* When we free an item, we set its size to zero. Thus, when
+ * we return it to the caller, we must ensure the size is set
+ * properly.
+ */
+ node->size = STANDARD_NODE_SIZE;
+#endif
}
else {
apr_memnode_t *active = allocator->blocks;
@@ -298,16 +310,20 @@
node->u.next = allocator->freelist;
allocator->freelist = node;
+#ifdef DEBUG_DOUBLE_FREE
/* note that this thing was freed. */
node->size = 0;
}
else if (node->size == 0) {
/* damn thing was freed already. */
abort();
+#endif
}
else {
+#ifdef DEBUG_DOUBLE_FREE
/* note that this thing was freed. */
node->size = 0;
+#endif
/* now free it */
apr_allocator_free(allocator->allocator, node->u.memnode);