/** * b1_node_free() - destroy a node * @node: node to destroy * * This destroys the given node and releases all linked resources. This implies * a call to b1_node_destroy(), if not already done by the caller. * * Return: NULL is returned. */ _c_public_ B1Node *b1_node_free(B1Node *node) { CRBNode *n; if (!node) return NULL; assert(node->owner); b1_node_release(node); while ((n = c_rbtree_first(&node->implementations))) { B1Implementation *implementation = c_container_of(n, B1Implementation, rb); c_rbtree_remove(&node->implementations, n); b1_interface_unref(implementation->interface); free(implementation); } /* if the node name is set, it means this node is owned by a message or * peer object, which will be responsibly for cleaning it up */ if (!node->name && node->id != BUS1_HANDLE_INVALID) { b1_node_destroy(node); c_rbtree_remove(&node->owner->nodes, &node->rb); } b1_peer_unref(node->owner); free(node); return NULL; }
static void b1_handle_free(CRef *ref, void *userdata) { B1Handle *handle = userdata; assert(!handle->live); c_rbtree_remove_init(&handle->holder->handles, &handle->rb); b1_peer_unref(handle->holder); free(handle); }
/** * b1_node_free() - destroy a node * @node: node to destroy * * This destroys the given node and releases all linked resources. This implies * a call to b1_node_destroy(), if not already done by the caller. * * Return: NULL is returned. */ _c_public_ B1Node *b1_node_free(B1Node *node) { if (!node) return NULL; c_rbtree_remove_init(&node->owner->nodes, &node->rb_nodes); b1_node_destroy(node); b1_handle_unref(node->handle); b1_peer_unref(node->owner); free(node); return NULL; }
/** * b1_handle_unref() - release reference * @handle: handle to release reference to, or NULL * * Release a single reference to an handle. If this is the last reference, the * handle is freed. * * If NULL is passed, this is a no-op. * * Return: NULL is returned. */ _c_public_ B1Handle *b1_handle_unref(B1Handle *handle) { if (!handle) return NULL; assert(handle->n_ref > 0); if (--handle->n_ref > 0) return NULL; b1_handle_release(handle); if (handle->id != BUS1_HANDLE_INVALID) { assert(handle->holder); c_rbtree_remove(&handle->holder->handles, &handle->rb); } b1_peer_unref(handle->holder); free(handle); return NULL; }