You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2008/04/07 11:58:49 UTC
svn commit: r645436 - /apr/apr/trunk/memory/unix/apr_pools.c
Author: jorton
Date: Mon Apr 7 02:58:48 2008
New Revision: 645436
URL: http://svn.apache.org/viewvc?rev=645436&view=rev
Log:
Factor out node free space calculation, and fix off-by-one in the use
thereof:
* memory/unix/apr_pools.c (node_free_space): New macro.
(apr_palloc, psprintf_flush): Use it; correctly compare against
free space using <= rather than <.
Submitted by: Maxim Yegorushkin <maxim.yegorushkin gmail.com>, jorton
Modified:
apr/apr/trunk/memory/unix/apr_pools.c
Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=645436&r1=645435&r2=645436&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Mon Apr 7 02:58:48 2008
@@ -619,6 +619,9 @@
node->next->ref = node->ref; \
} while (0)
+/* Returns the amount of free space in the given node. */
+#define node_free_space(node_) ((apr_size_t)(node_->endp - node_->first_avail))
+
/*
* Memory allocation
*/
@@ -633,7 +636,7 @@
active = pool->active;
/* If the active node has enough bytes left, use it. */
- if (size < (apr_size_t)(active->endp - active->first_avail)) {
+ if (size <= node_free_space(active)) {
mem = active->first_avail;
active->first_avail += size;
@@ -641,7 +644,7 @@
}
node = active->next;
- if (size < (apr_size_t)(node->endp - node->first_avail)) {
+ if (size <= node_free_space(node)) {
list_remove(node);
}
else {
@@ -943,8 +946,7 @@
size = APR_PSPRINTF_MIN_STRINGSIZE;
node = active->next;
- if (!ps->got_a_new_node
- && size < (apr_size_t)(node->endp - node->first_avail)) {
+ if (!ps->got_a_new_node && size <= node_free_space(node)) {
list_remove(node);
list_insert(node, active);