Commit eacfbe92 authored by Vladimír Čunát's avatar Vladimír Čunát

*_free() fixups

parent 3533d4fc
......@@ -1679,7 +1679,7 @@ static int wrk_resolve(lua_State *L)
/* Add OPT RR */
pkt->opt_rr = knot_rrset_copy(worker->engine->resolver.opt_rr, NULL);
if (!pkt->opt_rr) {
knot_pkt_free(&pkt);
knot_pkt_free(pkt);
return kr_error(ENOMEM);
}
if (options->DNSSEC_WANT) {
......@@ -1693,8 +1693,8 @@ static int wrk_resolve(lua_State *L)
/* Create task and start with a first question */
struct qr_task *task = worker_resolve_start(worker, pkt, *options);
if (!task) {
knot_rrset_free(&pkt->opt_rr, NULL);
knot_pkt_free(&pkt);
knot_rrset_free(pkt->opt_rr, NULL);
knot_pkt_free(pkt);
lua_pushstring(L, "couldn't create a resolution request");
lua_error(L);
}
......@@ -1709,8 +1709,8 @@ static int wrk_resolve(lua_State *L)
/* Start execution */
int ret = worker_resolve_exec(task, pkt);
lua_pushboolean(L, ret == 0);
knot_rrset_free(&pkt->opt_rr, NULL);
knot_pkt_free(&pkt);
knot_rrset_free(pkt->opt_rr, NULL);
knot_pkt_free(pkt);
return 1;
}
......
......@@ -457,11 +457,6 @@ ffi.metatype( knot_rrset_t, {
-- Destructor for packet accepts pointer to pointer
local knot_pkt_t = ffi.typeof('knot_pkt_t')
local packet_ptr = ffi.new('knot_pkt_t *[1]')
local function pkt_free(pkt)
packet_ptr[0] = pkt
knot.knot_pkt_free(packet_ptr)
end
-- Helpers for reading/writing 16-bit numbers from packet wire
local function pkt_u16(pkt, off, val)
......@@ -547,7 +542,7 @@ ffi.metatype( knot_pkt_t, {
pkt.parsed = 0
end
return ffi.gc(pkt[0], pkt_free)
return ffi.gc(pkt[0], knot.knot_pkt_free)
end,
__tostring = function(pkt)
return pkt:tostring()
......
......@@ -325,7 +325,7 @@ static knot_pkt_t *zi_query_create(zone_import_ctx_t *z_import, knot_rrset_t *rr
knot_wire_set_id(query->wire, msgid);
int err = knot_pkt_parse(query, 0);
if (err != KNOT_EOK) {
knot_pkt_free(&query);
knot_pkt_free(query);
return NULL;
}
......@@ -354,7 +354,7 @@ static int zi_rrset_import(zone_import_ctx_t *z_import, knot_rrset_t *rr)
/* Create "pseudo answer". */
knot_pkt_t *answer = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, pool);
if (!answer) {
knot_pkt_free(&query);
knot_pkt_free(query);
return -1;
}
knot_pkt_put_question(answer, dname, rrclass, rrtype);
......@@ -369,8 +369,8 @@ static int zi_rrset_import(zone_import_ctx_t *z_import, knot_rrset_t *rr)
* resolving - qr_task & request_ctx. */
struct qr_task *task = worker_resolve_start(worker, query, options);
if (!task) {
knot_pkt_free(&query);
knot_pkt_free(&answer);
knot_pkt_free(query);
knot_pkt_free(answer);
return -1;
}
......@@ -443,8 +443,8 @@ static int zi_rrset_import(zone_import_ctx_t *z_import, knot_rrset_t *rr)
cleanup:
knot_pkt_free(&query);
knot_pkt_free(&answer);
knot_pkt_free(query);
knot_pkt_free(answer);
worker_task_finalize(task, state);
return state == (is_referral ? KR_STATE_PRODUCE : KR_STATE_DONE) ? 0 : -1;
}
......
......@@ -149,7 +149,7 @@ int entry2answer(struct answer *ans, int id,
fail:
assert(/*false*/!ret);
/* Cleanup the item that we might've (partially) written to. */
knot_rrset_free(&ans->rrsets[id].set.rr, ans->mm);
knot_rrset_free(ans->rrsets[id].set.rr, ans->mm);
knot_rdataset_clear(&ans->rrsets[id].sig_rds, ans->mm);
memset(&ans->rrsets[id], 0, sizeof(ans->rrsets[id]));
return kr_error(ret);
......
......@@ -505,7 +505,8 @@ int nsec1_src_synth(struct key *k, struct answer *ans, const knot_dname_t *clenc
ret = kr_ok();
clean_wild:
if (arw->set.rr) { /* we may have matched AR_NSEC */
knot_rrset_free(&arw->set.rr, ans->mm);
knot_rrset_free(arw->set.rr, ans->mm);
arw->set.rr = NULL;
knot_rdataset_clear(&arw->sig_rds, ans->mm);
}
return ret;
......
......@@ -88,7 +88,7 @@ static int insert_ta(map_t *trust_anchors, const knot_dname_t *name,
}
/* Merge-in new key data */
if (!ta_rr || (rdlen > 0 && knot_rrset_add_rdata(ta_rr, rdata, rdlen, NULL) != 0)) {
knot_rrset_free(&ta_rr, NULL);
knot_rrset_free(ta_rr, NULL);
return kr_error(ENOMEM);
}
if(VERBOSE_STATUS) {
......@@ -161,7 +161,7 @@ static int del_record(const char *k, void *v, void *ext)
{
knot_rrset_t *ta_rr = v;
if (ta_rr) {
knot_rrset_free(&ta_rr, NULL);
knot_rrset_free(ta_rr, NULL);
}
return 0;
}
......
......@@ -221,7 +221,8 @@ static int validate_keyset(struct kr_request *req, knot_pkt_t *answer, bool has_
int ret = knot_rdataset_merge(&qry->zone_cut.key->rrs,
&rr->rrs, qry->zone_cut.pool);
if (ret != 0) {
knot_rrset_free(&qry->zone_cut.key, qry->zone_cut.pool);
knot_rrset_free(qry->zone_cut.key, qry->zone_cut.pool);
qry->zone_cut.key = NULL;
return ret;
}
updated_key = true;
......@@ -245,7 +246,8 @@ static int validate_keyset(struct kr_request *req, knot_pkt_t *answer, bool has_
};
int ret = kr_dnskeys_trusted(&vctx, qry->zone_cut.trust_anchor);
if (ret != 0) {
knot_rrset_free(&qry->zone_cut.key, qry->zone_cut.pool);
knot_rrset_free(qry->zone_cut.key, qry->zone_cut.pool);
qry->zone_cut.key = NULL;
return ret;
}
......@@ -279,7 +281,7 @@ static knot_rrset_t *update_ds(struct kr_zonecut *cut, const knot_pktsection_t *
}
}
if (ret != 0) {
knot_rrset_free(&new_ds, cut->pool);
knot_rrset_free(new_ds, cut->pool);
return NULL;
}
}
......
......@@ -90,11 +90,9 @@ void kr_zonecut_deinit(struct kr_zonecut *cut)
if (cut->nsset) {
trie_apply(cut->nsset, free_addr_set_cb, cut->pool);
trie_free(cut->nsset);
cut->nsset = NULL;
}
knot_rrset_free(&cut->key, cut->pool);
knot_rrset_free(&cut->trust_anchor, cut->pool);
cut->name = NULL;
knot_rrset_free(cut->key, cut->pool);
knot_rrset_free(cut->trust_anchor, cut->pool);
}
void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name)
......@@ -153,14 +151,14 @@ int kr_zonecut_copy_trust(struct kr_zonecut *dst, const struct kr_zonecut *src)
if (src->trust_anchor) {
ta_copy = knot_rrset_copy(src->trust_anchor, dst->pool);
if (!ta_copy) {
knot_rrset_free(&key_copy, dst->pool);
knot_rrset_free(key_copy, dst->pool);
return kr_error(ENOMEM);
}
}
knot_rrset_free(&dst->key, dst->pool);
knot_rrset_free(dst->key, dst->pool);
dst->key = key_copy;
knot_rrset_free(&dst->trust_anchor, dst->pool);
knot_rrset_free(dst->trust_anchor, dst->pool);
dst->trust_anchor = ta_copy;
return kr_ok();
......@@ -381,7 +379,7 @@ static int fetch_secure_rrset(knot_rrset_t **rr, struct kr_cache *cache,
return kr_error(ESTALE);
}
/* materialize a new RRset */
knot_rrset_free(rr, pool);
knot_rrset_free(*rr, pool);
*rr = mm_alloc(pool, sizeof(knot_rrset_t));
if (*rr == NULL) {
return kr_error(ENOMEM);
......@@ -396,7 +394,8 @@ static int fetch_secure_rrset(knot_rrset_t **rr, struct kr_cache *cache,
KNOT_CLASS_IN, new_ttl);
ret = kr_cache_materialize(&(*rr)->rrs, &peek, pool);
if (ret < 0) {
knot_rrset_free(rr, pool);
knot_rrset_free(*rr, pool);
*rr = NULL;
return ret;
}
......
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