]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
*_free() fixups
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 4 Jul 2018 13:38:25 +0000 (15:38 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 14 Aug 2018 08:36:11 +0000 (10:36 +0200)
daemon/bindings.c
daemon/lua/kres.lua
daemon/zimport.c
lib/cache/entry_rr.c
lib/cache/nsec1.c
lib/dnssec/ta.c
lib/layer/validate.c
lib/zonecut.c

index ee5ba62a2a08fb079704036b81876ee5c97e4099..5922c519e17fa6a7b759e261d75f6aaae169d140 100644 (file)
@@ -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;
 }
 
index 16a5f493119e89d515274995b81870e68fd0e1f8..69cc8a6b57ee957761c7bbd2abaffa134c620cec 100644 (file)
@@ -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()
index e19d3b5578d19bd8fd9be2baacc3ef4ec2e296c6..94f25f807bc0fe7cc6ceec973ee235f43f34dbbe 100644 (file)
@@ -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;
 }
index 34c133135ada87ee4551b72a4841265a90e794b6..af2e95736133a976a110752842a0eeb6796fdca9 100644 (file)
@@ -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);
index 2db41556bfa3ae700886599526738e89a53bf372..752871bf98d810b31e4457d9065ea5abc3f8f80a 100644 (file)
@@ -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;
index 38f71f06144f89a5d020ec698113eac6958e7776..323d89b478cffa52d1d14ae21757adccd37fee5f 100644 (file)
@@ -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;
 }
index 583c5f4efe6c0cb3168c7889e3776aab21231ccb..6111f6b0bcf893ccde43799a8e564c1e6003f7ec 100644 (file)
@@ -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;
                }
        }
index 8ba28a9ac9bfdeac4fafe0a5f7992be25ab04fab..d1699f09897fc21aa416b7d2aea0914bee870058 100644 (file)
@@ -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;
        }