From 6d87d3b9a527dc1b514e47143de7fd3455205fd4 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sat, 6 Feb 2010 15:52:27 +0100 Subject: [PATCH] Use same test for full tree in tree_fast_alloc_node and tree_prune. Otherwise the alloc in tree_prune may fail. --- uct/tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/uct/tree.c b/uct/tree.c index 1a7f19d..0722823 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -28,7 +28,10 @@ tree_fast_alloc_node(struct tree *t) struct tree_node *n = NULL; unsigned long old_size =__sync_fetch_and_add(&t->nodes_size, sizeof(*n)); - if (old_size + sizeof(*n) <= t->max_tree_size) + /* The test below works even if max_tree_size is not a + * multiple of the node size because tree_init() allocates + * space for an extra node. */ + if (old_size < t->max_tree_size) n = (struct tree_node *)(t->nodes + old_size); return n; } -- 2.11.4.GIT