static void traverse_postorder(BTREE_NODE_p_t node,BTREE_VISIT_PROC_p_t visit_proc){ if (node!=NULL) { traverse_postorder(node->left,visit_proc); traverse_postorder(node->right, visit_proc); visit_proc(node->data); } }
void traverse_postorder(struct tree *node) { if (node == NULL) return; traverse_postorder(node->left); traverse_postorder(node->right); #ifndef TWO_DIMENSION traverse_postorder(node->up); traverse_postorder(node->down); #endif print_node(node); }
void macro_store_delete(rbtree_t* store) { if(!store) return; traverse_postorder(store, del_macro, NULL); free(store); }
void neg_cache_delete(struct val_neg_cache* neg) { if(!neg) return; lock_basic_destroy(&neg->lock); /* delete all the zones in the tree */ traverse_postorder(&neg->tree, &neg_clear_zones, NULL); free(neg); }
void infra_delete(struct infra_cache* infra) { if(!infra) return; slabhash_delete(infra->hosts); slabhash_delete(infra->domain_rates); traverse_postorder(&infra->domain_limits, domain_limit_free, NULL); free(infra); }
/** clear zones on cache deletion */ static void neg_clear_zones(rbnode_t* n, void* ATTR_UNUSED(arg)) { struct val_neg_zone* z = (struct val_neg_zone*)n; /* delete all the rrset entries in the tree */ traverse_postorder(&z->tree, &neg_clear_datas, NULL); free(z->nsec3_salt); free(z->name); free(z); }
void local_zones_delete(struct local_zones* zones) { if(!zones) return; lock_rw_destroy(&zones->lock); /* walk through zones and delete them all */ traverse_postorder(&zones->ztree, lzdel, NULL); free(zones); }
void ub_ctx_delete(struct ub_ctx* ctx) { struct alloc_cache* a, *na; int do_stop = 1; if(!ctx) return; /* see if bg thread is created and if threads have been killed */ /* no locks, because those may be held by terminated threads */ /* for processes the read pipe is closed and we see that on read */ #ifdef HAVE_PTHREAD if(ctx->created_bg && ctx->dothread) { if(pthread_kill(ctx->bg_tid, 0) == ESRCH) { /* thread has been killed */ do_stop = 0; } } #endif /* HAVE_PTHREAD */ if(do_stop) ub_stop_bg(ctx); libworker_delete_event(ctx->event_worker); modstack_desetup(&ctx->mods, ctx->env); a = ctx->alloc_list; while(a) { na = a->super; a->super = &ctx->superalloc; alloc_clear(a); free(a); a = na; } local_zones_delete(ctx->local_zones); lock_basic_destroy(&ctx->qqpipe_lock); lock_basic_destroy(&ctx->rrpipe_lock); lock_basic_destroy(&ctx->cfglock); tube_delete(ctx->qq_pipe); tube_delete(ctx->rr_pipe); if(ctx->env) { slabhash_delete(ctx->env->msg_cache); rrset_cache_delete(ctx->env->rrset_cache); infra_delete(ctx->env->infra_cache); config_delete(ctx->env->cfg); edns_known_options_delete(ctx->env); auth_zones_delete(ctx->env->auth_zones); free(ctx->env); } ub_randfree(ctx->seed_rnd); alloc_clear(&ctx->superalloc); traverse_postorder(&ctx->queries, delq, NULL); free(ctx); #ifdef USE_WINSOCK WSACleanup(); #endif }
void anchors_delete(struct val_anchors* anchors) { if(!anchors) return; lock_unprotect(&anchors->lock, anchors->autr); lock_unprotect(&anchors->lock, anchors); lock_basic_destroy(&anchors->lock); traverse_postorder(anchors->tree, anchors_delfunc, NULL); free(anchors->tree); regional_destroy(anchors->region); autr_global_delete(anchors->autr); free(anchors); }
BTREE_ID_t BTREE_traverse_tree(BTREE_ID_t tree,BTREE_TRAVERSE_ORDER_e_t order,BTREE_VISIT_PROC_p_t visit_proc){ switch (order) { case BTREE_PREORDER: traverse_preorder(tree->root, visit_proc); break; case BTREE_INORDER: traverse_inorder(tree->root, visit_proc); break; case BTREE_POSTORDER: traverse_postorder(tree->root,visit_proc); break; default: CDA_ASSERT(CDA_FALSE); break; } return tree; }
static void hints_del_tree(struct iter_hints* hints) { traverse_postorder(&hints->tree, &delhintnode, NULL); }
void ub_ctx_delete(struct ub_ctx* ctx) { struct alloc_cache* a, *na; if(!ctx) return; /* stop the bg thread */ lock_basic_lock(&ctx->cfglock); if(ctx->created_bg) { uint8_t* msg; uint32_t len; uint32_t cmd = UB_LIBCMD_QUIT; lock_basic_unlock(&ctx->cfglock); lock_basic_lock(&ctx->qqpipe_lock); (void)tube_write_msg(ctx->qq_pipe, (uint8_t*)&cmd, (uint32_t)sizeof(cmd), 0); lock_basic_unlock(&ctx->qqpipe_lock); lock_basic_lock(&ctx->rrpipe_lock); while(tube_read_msg(ctx->rr_pipe, &msg, &len, 0)) { /* discard all results except a quit confirm */ if(context_serial_getcmd(msg, len) == UB_LIBCMD_QUIT) { free(msg); break; } free(msg); } lock_basic_unlock(&ctx->rrpipe_lock); /* if bg worker is a thread, wait for it to exit, so that all * resources are really gone. */ lock_basic_lock(&ctx->cfglock); if(ctx->dothread) { lock_basic_unlock(&ctx->cfglock); ub_thread_join(ctx->bg_tid); } else { lock_basic_unlock(&ctx->cfglock); } } else { lock_basic_unlock(&ctx->cfglock); } modstack_desetup(&ctx->mods, ctx->env); a = ctx->alloc_list; while(a) { na = a->super; a->super = &ctx->superalloc; alloc_clear(a); free(a); a = na; } local_zones_delete(ctx->local_zones); lock_basic_destroy(&ctx->qqpipe_lock); lock_basic_destroy(&ctx->rrpipe_lock); lock_basic_destroy(&ctx->cfglock); tube_delete(ctx->qq_pipe); tube_delete(ctx->rr_pipe); if(ctx->env) { slabhash_delete(ctx->env->msg_cache); rrset_cache_delete(ctx->env->rrset_cache); infra_delete(ctx->env->infra_cache); config_delete(ctx->env->cfg); free(ctx->env); } ub_randfree(ctx->seed_rnd); alloc_clear(&ctx->superalloc); traverse_postorder(&ctx->queries, delq, NULL); free(ctx); #ifdef USE_WINSOCK WSACleanup(); #endif }
static void fwd_del_tree(struct iter_forwards* fwd) { if(fwd->tree) traverse_postorder(fwd->tree, &delfwdnode, NULL); free(fwd->tree); }