K_LIST *_k_free_list(K_LIST *list, KLIST_FFL_ARGS) { int i; CHKLIST(list); if (list->is_store) { quithere(1, "List %s can't %s() a store" KLIST_FFL, list->name, __func__, KLIST_FFL_PASS); } for (i = 0; i < list->item_mem_count; i++) free(list->item_memory[i]); free(list->item_memory); for (i = 0; i < list->data_mem_count; i++) free(list->data_memory[i]); free(list->data_memory); if (list->lock) { cklock_destroy(list->lock); free(list->lock); } // local_list lists are not stored in all_klists if (!list->local_list) { K_LISTS *klists, *klists_prev = NULL; // not locked :P if (!lock_check_init) { quitfrom(1, file, func, line, "in %s(), lock_check_lock has not been initialised!", __func__); } ck_wlock(&lock_check_lock); klists = all_klists; while (klists && klists->klist != list) { klists_prev = klists; klists = klists->next; } if (!klists) { quitfrom(1, file, func, line, "in %s(), list %s not in klists", __func__, list->name); } else { if (klists_prev) klists_prev->next = klists->next; else all_klists = klists->next; free(klists); } ck_wunlock(&lock_check_lock); } free(list); return NULL; }
static char *btc_data(char *json, size_t *len) { size_t off; char tmp[1024]; char *buf; APPEND_REALLOC_INIT(buf, off, *len); APPEND_REALLOC(buf, off, *len, "POST / HTTP/1.1\n"); ck_wlock(&btc_lock); snprintf(tmp, sizeof(tmp), "Authorization: Basic %s\n", btc_auth); APPEND_REALLOC(buf, off, *len, tmp); snprintf(tmp, sizeof(tmp), "Host: %s/\n", btc_server); ck_wunlock(&btc_lock); APPEND_REALLOC(buf, off, *len, tmp); APPEND_REALLOC(buf, off, *len, "Content-Type: application/json\n"); snprintf(tmp, sizeof(tmp), "Content-Length: %d\n\n", (int)strlen(json)); APPEND_REALLOC(buf, off, *len, tmp); APPEND_REALLOC(buf, off, *len, json); return buf; }
K_LIST *_k_new_list(const char *name, size_t siz, int allocate, int limit, bool do_tail, bool lock_only, bool without_lock, bool local_list, const char *name2, int cull_limit, KLIST_FFL_ARGS) { K_LIST *list; if (allocate < 1) quithere(1, "Invalid new list %s with allocate %d must be > 0", name, allocate); if (limit < 0) quithere(1, "Invalid new list %s with limit %d must be >= 0", name, limit); /* after culling, the first block of items are again allocated, * so there's no point culling a single block of items */ if (cull_limit > 0 && cull_limit <= allocate) quithere(1, "Invalid new list %s with cull_limit %d must be > allocate (%d)", name, cull_limit, allocate); list = calloc(1, sizeof(*list)); if (!list) quithere(1, "Failed to calloc list %s", name); list->master = list; list->is_store = false; list->is_lock_only = lock_only; list->local_list = local_list; if (without_lock) list->lock = NULL; else { list->lock = calloc(1, sizeof(*(list->lock))); if (!(list->lock)) quithere(1, "Failed to calloc lock for list %s", name); cklock_init(list->lock); } list->name = name; list->name2 = name2; list->siz = siz; list->allocate = allocate; list->limit = limit; list->do_tail = do_tail; list->cull_limit = cull_limit; list->next_store = list->prev_store = NULL; if (!(list->is_lock_only)) k_alloc_items(list, KLIST_FFL_PASS); /* Don't want to keep track of short lived (tree) lists * since they wont use locking anyway */ if (!list->local_list) { K_LISTS *klists; // not locked :P if (!lock_check_init) { quitfrom(1, file, func, line, "in %s(), lock_check_lock has not been initialised!", __func__); } klists = calloc(1, sizeof(*klists)); if (!klists) quithere(1, "Failed to calloc klists %s", name); klists->klist = list; ck_wlock(&lock_check_lock); klists->next = all_klists; all_klists = klists; ck_wunlock(&lock_check_lock); } return list; }