Commit deacbee2 authored by Daniel Salzman's avatar Daniel Salzman

Merge branch 'fixes' into 'master'

Fixes

See merge request !710
parents 97dc27b8 eab739f5
......@@ -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);
}
......
......@@ -1717,19 +1717,16 @@ int journal_scrape(journal_t *j)
WALK_LIST(del_one, to_del) {
txn->ret = j->db->db_api->del(txn->txn, (knot_db_val_t *)del_one->d);
}
md_update_journal_count(txn, -1);
if (!EMPTY_LIST(to_del)) {
md_update_journal_count(txn, -1);
}
md_del_last_inserter_zone(txn, j->zone);
txn->ret = j->db->db_api->txn_commit(txn->txn);
}
scrape_end:
WALK_LIST(del_one, to_del) {
free(del_one->d);
}
ptrlist_free(&to_del, NULL);
ptrlist_deep_free(&to_del, NULL);
return txn->ret;
}
......@@ -1805,6 +1802,8 @@ int journal_db_list_zones(journal_db_t **db, list_t *zones)
}
if (list_size(zones) != expected_count) {
txn->ret = KNOT_EMALF;
ptrlist_deep_free(zones, NULL);
init_list(zones);
}
return txn->ret;
}
......
......@@ -61,10 +61,12 @@ static int reconfigure_mapsize(const char *journal_path, size_t *mapsize)
struct stat st;
if (stat(data_mdb, &st) != 0 || st.st_size == 0) {
fprintf(stderr, "Journal does not exist: %s\n", journal_path);
free(data_mdb);
return KNOT_ENOENT;
}
*mapsize = st.st_size + st.st_size / 8; // 112.5% to allow opening when growing
free(data_mdb);
return KNOT_EOK;
}
......@@ -82,11 +84,13 @@ int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color)
ret = reconfigure_mapsize(jdb->path, &jdb->fslimit);
if (ret != KNOT_EOK) {
journal_db_close(&jdb);
return ret;
}
ret = journal_open_db(&jdb);
if (ret != KNOT_EOK) {
journal_db_close(&jdb);
return ret;
}
......@@ -98,6 +102,7 @@ int print_journal(char *path, knot_dname_t *name, uint32_t limit, bool color)
size_t buflen = 8192;
char *buff = malloc(buflen);
if (buff == NULL) {
journal_db_close(&jdb);
return KNOT_ENOMEM;
}
journal_t *j = journal_new();
......@@ -185,11 +190,13 @@ int list_zones(char *path)
ret = reconfigure_mapsize(jdb->path, &jdb->fslimit);
if (ret != KNOT_EOK) {
journal_db_close(&jdb);
return ret;
}
ret = journal_open_db(&jdb);
if (ret != KNOT_EOK) {
journal_db_close(&jdb);
return ret;
}
......
......@@ -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