From: Vladimír Čunát Date: Fri, 26 Jan 2018 16:31:52 +0000 (+0100) Subject: cache: avoid leaking memory X-Git-Tag: v2.0.0~6^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed532c7a029eacd074fd16ff7573dd126983600c;p=thirdparty%2Fknot-resolver.git cache: avoid leaking memory Also guard all allocations in cache against this, via assert. (Except in cases that would segfault anyway.) --- diff --git a/lib/cache.c b/lib/cache.c index e8a52c286..5ea2bf77e 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -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); diff --git a/lib/cache/entry_rr.c b/lib/cache/entry_rr.c index 47e1c6e6e..b0019def4 100644 --- a/lib/cache/entry_rr.c +++ b/lib/cache/entry_rr.c @@ -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;