]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: avoid leaking memory
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 26 Jan 2018 16:31:52 +0000 (17:31 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 26 Jan 2018 16:31:52 +0000 (17:31 +0100)
Also guard all allocations in cache against this, via assert.
(Except in cases that would segfault anyway.)

lib/cache.c
lib/cache/entry_rr.c

index e8a52c286dc16b02a45d4dbfb48a94724ef789ce..5ea2bf77ecbc7dc9d498ac1b1a778b0b2efda404 100644 (file)
@@ -841,6 +841,7 @@ static int answer_simple_hit(kr_layer_t *ctx, knot_pkt_t *pkt, uint16_t type,
        /* Materialize the sets for the answer in (pseudo-)packet. */
        struct answer ans;
        memset(&ans, 0, sizeof(ans));
+       ans.mm = &pkt->mm;
        ret = entry2answer(&ans, AR_ANSWER, eh, eh_bound,
                           qry->sname, type, new_ttl);
        CHECK_RET(ret);
index 47e1c6e6ed0d914d10156196dc393284bfc77e6c..b0019def41f84f4030fe4903c5e804da946da8b9 100644 (file)
@@ -50,6 +50,7 @@ static int rdataset_materialize(knot_rdataset_t * restrict rds, const void * con
                const void *data_bound, uint32_t ttl, knot_mm_t *pool)
 {
        assert(rds && data && data_bound && data_bound > data && !rds->data);
+       assert(pool); /* not required, but that's our current usage; guard leaks */
        const void *d = data; /* iterates over the cache data */
        {
                uint8_t rr_count;