summaryrefslogtreecommitdiff
path: root/src/rax.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-09-06 13:11:47 +0200
committerantirez <antirez@gmail.com>2017-12-01 10:24:24 +0100
commit439120c62076718e8f7e7e602c623febaec6f04a (patch)
tree71f295abb31dcd630f1963835c415fad9ff02527 /src/rax.c
parentec9bbe96bf47ae1f104c51cc6078eb72ca43cef0 (diff)
downloadredis-439120c62076718e8f7e7e602c623febaec6f04a.tar.gz
Streams: implement stream object release.
Diffstat (limited to 'src/rax.c')
-rw-r--r--src/rax.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/rax.c b/src/rax.c
index 3ead27ed7..442e7bfef 100644
--- a/src/rax.c
+++ b/src/rax.c
@@ -1093,28 +1093,36 @@ int raxRemove(rax *rax, unsigned char *s, size_t len, void **old) {
/* This is the core of raxFree(): performs a depth-first scan of the
* tree and releases all the nodes found. */
-void raxRecursiveFree(rax *rax, raxNode *n) {
+void raxRecursiveFree(rax *rax, raxNode *n, void (*free_callback)(void*)) {
debugnode("free traversing",n);
int numchildren = n->iscompr ? 1 : n->size;
raxNode **cp = raxNodeLastChildPtr(n);
while(numchildren--) {
raxNode *child;
memcpy(&child,cp,sizeof(child));
- raxRecursiveFree(rax,child);
+ raxRecursiveFree(rax,child,free_callback);
cp--;
}
debugnode("free depth-first",n);
+ if (free_callback && n->iskey && !n->isnull)
+ free_callback(raxGetData(n));
rax_free(n);
rax->numnodes--;
}
-/* Free a whole radix tree. */
-void raxFree(rax *rax) {
- raxRecursiveFree(rax,rax->head);
+/* Free a whole radix tree, calling the specified callback in order to
+ * free the auxiliary data. */
+void raxFreeWithCallback(rax *rax, void (*free_callback)(void*)) {
+ raxRecursiveFree(rax,rax->head,free_callback);
assert(rax->numnodes == 0);
rax_free(rax);
}
+/* Free a whole radix tree. */
+void raxFree(rax *rax) {
+ raxFreeWithCallback(rax,NULL);
+}
+
/* ------------------------------- Iterator --------------------------------- */
/* Initialize a Rax iterator. This call should be performed a single time