Commit 7f94fe8d authored by Libor Peltan's avatar Libor Peltan

moved ptrlist_deep_free() to contrib

parent 97dc27b8
......@@ -218,3 +218,17 @@ void ptrlist_rem(ptrnode_t *node, knot_mm_t *mm)
rem_node(&node->n);
mm_free(mm, node);
}
/**
* ptrlist_deep_free - free all nodes incl referenced data
* @list: list nodes
* @mm: memory context
*/
void ptrlist_deep_free(list_t *l, knot_mm_t *mm)
{
ptrnode_t *n;
WALK_LIST(n, *l) {
mm_free(mm, n->d);
}
ptrlist_free(l, mm);
}
......@@ -79,4 +79,5 @@ typedef struct ptrnode {
ptrnode_t *ptrlist_add(list_t *, void *, knot_mm_t *);
void ptrlist_free(list_t *, knot_mm_t *);
void ptrlist_rem(ptrnode_t *node, knot_mm_t *mm);
void ptrlist_deep_free(list_t *, knot_mm_t *);
......@@ -322,16 +322,6 @@ static key_params_t *keyval2params(const knot_db_val_t *key, const knot_db_val_t
#define KEYS_RO 0x0
#define KEYS_RW 0x1
// TODO move elsewhere
static void ptrlist_deep_free(list_t *l)
{
ptrnode_t *n;
WALK_LIST(n, *l) {
free(n->d);
}
ptrlist_free(l, NULL);
}
// TODO move elsewhere
static void va_free(void *p, ...)
{
......@@ -377,7 +367,7 @@ int kasp_db_list_keys(kasp_db_t *db, const knot_dname_t *zone_name, list_t *dst)
db_api->txn_abort(txn);
if (ret != KNOT_EOK) {
ptrlist_deep_free(dst);
ptrlist_deep_free(dst, NULL);
return ret;
}
return (EMPTY_LIST(*dst) ? KNOT_ENOENT : KNOT_EOK);
......@@ -448,7 +438,7 @@ int kasp_db_delete_all(kasp_db_t *db, const knot_dname_t *zone_name)
break;
}
}
ptrlist_deep_free(&allkeys);
ptrlist_deep_free(&allkeys, NULL);
if (ret == KNOT_EOK) {
knot_db_val_t key = make_key(KASPDBKEY_NSEC3SALT, zone_name, NULL);
......
......@@ -113,15 +113,6 @@ static void kaspkey2params(knot_kasp_key_t *key, key_params_t *params)
params->timing = key->timing;
}
static void ptrlist_deep_free(list_t *l)
{
ptrnode_t *n;
WALK_LIST(n, *l) {
free(n->d);
}
ptrlist_free(l, NULL);
}
int kasp_zone_load(knot_kasp_zone_t *zone,
const knot_dname_t *zone_name,
kasp_db_t *kdb)
......@@ -181,7 +172,7 @@ kzl_salt:
zone->nsec3_salt_created = sc;
kzl_end:
ptrlist_deep_free(&key_params);
ptrlist_deep_free(&key_params, NULL);
if (ret != KNOT_EOK) {
free(dkeys);
}
......
......@@ -89,12 +89,12 @@ int main(int argc, char *argv[])
params = ((ptrnode_t *)HEAD(l))->d;
ok(params_eq(params, &params1), "kasp_db: key params equal 1");
free_params
ptrlist_deep_free(&l);
ptrlist_deep_free(&l, NULL);
ret = kasp_db_list_keys(db, zone2, &l);
is_int(KNOT_ENOENT, ret, "kasp_db: list keys 1 enoent");
is_int(0, list_size(&l), "kasp_db: list keys reports no keys 1");
ptrlist_deep_free(&l);
ptrlist_deep_free(&l, NULL);
ret = kasp_db_share_key(db, zone1, zone2, params1.id);
is_int(KNOT_EOK, ret, "kasp_db: share key eok");
......@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
is_int(1, list_size(&l), "kasp_db: list keys reports one key 2");
params = ((ptrnode_t *)HEAD(l))->d;
free_params
ptrlist_deep_free(&l);
ptrlist_deep_free(&l, NULL);
ret = kasp_db_add_key(db, zone2, &params2);
is_int(KNOT_EOK, ret, "kasp_db: add key 2 eok");
......@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
free_params
params = ((ptrnode_t *)HEAD(l))->d;
free_params
ptrlist_deep_free(&l);
ptrlist_deep_free(&l, NULL);
ret = kasp_db_delete_key(db, zone1, params1.id, &ignore);
is_int(KNOT_EOK, ret, "kasp_db: delete key 1 eok");
......@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
ret = kasp_db_list_keys(db, zone1, &l);
is_int(KNOT_ENOENT, ret, "kasp_db: list keys 2 enoent");
is_int(list_size(&l), 0, "kasp_db: list keys reports no keys 2");
ptrlist_deep_free(&l);
ptrlist_deep_free(&l, NULL);
kasp_db_close(&db);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment