]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache/api: pass memory context in kr_cache_insert_rr
authorMarek Vavruša <mvavrusa@cloudflare.com>
Sat, 14 Jul 2018 00:11:04 +0000 (17:11 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
The cache changes in 2.4.0 require query to be present with a memory
context initialized for splicing records.

lib/cache/api.c

index a7d796a8d2c87988629bfb51f8b13b8ec63b1642..cf21d2a84dcd809a5ed776c55d6a8ebaf5988435 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "contrib/cleanup.h"
 #include "contrib/ucw/lib.h"
+#include "contrib/ucw/mempool.h"
 #include "lib/cache/api.h"
 #include "lib/cache/cdb_lmdb.h"
 #include "lib/defines.h"
@@ -163,9 +164,25 @@ int kr_cache_insert_rr(struct kr_cache *cache, const knot_rrset_t *rr, const kno
        if (err <= 0) {
                return kr_ok();
        }
-       ssize_t written = stash_rrset(cache, NULL, rr, rrsig, timestamp, rank, NULL, NULL, scope);
-               /* Zone's NSEC* parames aren't updated, but that's probably OK
-                * for kr_cache_insert_rr() */
+
+       /* Create a context for the cache write, as it requires memory context. */
+       struct kr_request request = {
+               .pool = {
+                       .ctx = mp_new(64),
+                       .alloc = (knot_mm_alloc_t) mp_alloc
+               }
+       };
+       struct kr_query query = {
+               .request = &request,
+       };
+
+       ssize_t written = stash_rrset(cache, &query, rr, rrsig, timestamp, rank, NULL, NULL, scope);
+
+       /* Release the memory pool */
+       mp_delete (request.pool.ctx);
+
+       /* Zone's NSEC* parames aren't updated, but that's probably OK
+        * for kr_cache_insert_rr() */
        if (written >= 0) {
                return kr_ok();
        }