Avoid stompling on n->names during unbind_all

This commit is contained in:
Tony Garnock-Jones 2011-01-01 21:30:24 -05:00
parent f67d46efdb
commit dae85b8b15
1 changed files with 9 additions and 2 deletions

11
node.c
View File

@ -47,11 +47,15 @@ node_class_t *lookup_node_class(cmsg_bytes_t name) {
return nc;
}
static void init_node_names(node_t *n) {
init_hashtable(&n->names, 5, NULL, NULL);
}
node_t *new_node(node_class_t *nc, sexp_t *args) {
node_t *n = nc->construct(nc, args);
n->refcount = ZERO_REFCOUNT();
n->node_class = nc;
init_hashtable(&n->names, 5, NULL, NULL);
init_node_names(n);
return n;
}
@ -95,7 +99,10 @@ static void unbind_on_destroy(void *context, cmsg_bytes_t key, void *value) {
}
void unbind_all_names_for_node(node_t *n) {
hashtable_foreach(&n->names, unbind_on_destroy, NULL);
hashtable_t names = n->names;
init_node_names(n);
hashtable_foreach(&names, unbind_on_destroy, NULL);
destroy_hashtable(&names);
}
int post_node(cmsg_bytes_t node, cmsg_bytes_t name, sexp_t *body) {