/* * \brief Internal call to allocate a CLICON handle. * * There may be different variants of handles with some common options. * So far the only common options is a MAGIC cookie for sanity checks and * CLICON options */ clicon_handle clicon_handle_init0(int size) { struct clicon_handle *ch; clicon_handle h = NULL; if ((ch = malloc(size)) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; } memset(ch, 0, size); ch->ch_magic = CLICON_MAGIC; if ((ch->ch_copt = hash_init()) == NULL){ clicon_handle_exit((clicon_handle)ch); goto done; } if ((ch->ch_data = hash_init()) == NULL){ clicon_handle_exit((clicon_handle)ch); goto done; } h = (clicon_handle)ch; done: return h; }
/*! Deallocates a backend handle, including all client structs * @Note: handle 'h' cannot be used in calls after this * @see backend_client_rm */ int backend_handle_exit(clicon_handle h) { struct client_entry *ce; /* only delete client structs, not close sockets, etc, see backend_client_rm WHY NOT? */ while ((ce = backend_client_list(h)) != NULL){ if (ce->ce_s){ close(ce->ce_s); ce->ce_s = 0; } backend_client_delete(h, ce); } clicon_handle_exit(h); /* frees h and options (and streams) */ return 0; }