From 4ac4a35648915218f078e9302b61fb07b4b191bc Mon Sep 17 00:00:00 2001 From: kanoi Date: Sun, 3 Jan 2016 14:04:16 +1100 Subject: [PATCH] ckdb - release the knode item back to the free list when removing an item from a tree --- src/ckdb.h | 2 +- src/ktree.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 63074072..abb7a1d6 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.4" -#define CKDB_VERSION DB_VERSION"-1.902" +#define CKDB_VERSION DB_VERSION"-1.910" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ktree.c b/src/ktree.c index 3b1142c7..b13c5585 100644 --- a/src/ktree.c +++ b/src/ktree.c @@ -1053,11 +1053,21 @@ DBG("@remove after balance=%d :(\n", (int)cmp); return; } -void _remove_from_ktree_free(K_TREE *root, K_ITEM *data, bool chklock, KTREE_FFL_ARGS) +void _remove_from_ktree_free(K_TREE *tree, K_ITEM *data, bool chklock, KTREE_FFL_ARGS) { K_TREE_CTX ctx[1]; + K_NODE *knode; + K_ITEM *kitem; - _remove_from_ktree(root, data, ctx, chklock, KTREE_FFL_PASS); + _remove_from_ktree(tree, data, ctx, chklock, KTREE_FFL_PASS); + + if (ctx[0]) { + knode = (K_NODE *)(ctx[0]); + kitem = knode->kitem; + // _nolock since _remove_from_ktree() already tested it + k_unlink_item_nolock(tree->node_store, kitem); + k_add_head_nolock(tree->node_free, kitem); + } } static void free_ktree_sub(K_NODE *knode, void (*free_funct)(void *))