{
struct ec_node_weakref *node = (struct ec_node_weakref *)gen_node;
- // XXX check node type
-
assert(node != NULL);
- if (child == NULL)
- return -EINVAL;
+ if (child == NULL) {
+ errno = EINVAL;
+ goto fail;
+ }
- node->child = child;
+ if (ec_node_check_type(gen_node, &ec_node_weakref_type) < 0)
+ goto fail;
- // XXX else it breaks the dump()
- //TAILQ_INSERT_TAIL(&gen_node->children, child, next); // XXX really needed?
+ node->child = child;
return 0;
+
+fail:
+ ec_node_free(child);
+ return -1;
}
struct ec_node *ec_node_weakref(const char *id, struct ec_node *child)