lkml.org 
[lkml]   [2010]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] radix_tree_destroy?
On Thu, Dec 16, 2010 at 08:27:41AM -0800, Dan Magenheimer wrote:
> +static void
> +radix_tree_node_destroy(struct radix_tree_node *node, unsigned int height,
> + void (*slot_free)(void *))
> +{
> + int i;
> +
> + if (height == 0)
> + return;
> + for (i = 0; i < RADIX_TREE_MAP_SIZE; i++) {
> + if (node->slots[i]) {
> + if (height > 1) {
> + radix_tree_node_destroy(node->slots[i],
> + height-1, slot_free);
> + radix_tree_node_free(node->slots[i]);
> + node->slots[i] = NULL;
> + } else
> + slot_free(node->slots[i]);
> + }
> + }
> +}
> +
> +void radix_tree_destroy(struct radix_tree_root *root, void (*slot_free)(void *))
> +{
> + if (root->rnode == NULL)
> + return;
> + if (root->height == 0)
> + slot_free(root->rnode);

Don't you want indirect_to_ptr(root->rnode) here? You probably also don't
want the callback in the !radix_tree_is_indirect_ptr() case.

> + else {
> + radix_tree_node_destroy(root->rnode, root->height, slot_free);
> + radix_tree_node_free(root->rnode);
> + root->height = 0;
> + }
> + root->rnode = NULL;
> +}

The above will handle the nodes, but what about the root? It looks like
you're at least going to leak tags on the root, so at the very least
you'd still want a root_tag_clear_all() here.


\
 
 \ /
  Last update: 2010-12-17 04:31    [W:0.099 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site