]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Pass a memory context in to dns_cache_create
authorMark Andrews <marka@isc.org>
Wed, 27 Mar 2024 00:32:25 +0000 (11:32 +1100)
committerMark Andrews <marka@isc.org>
Tue, 4 Jun 2024 12:42:05 +0000 (12:42 +0000)
(cherry picked from commit 87e3b9dbf378c67a3e6822cedebbac0d57f0c64e)

bin/named/server.c
lib/dns/cache.c
lib/dns/include/dns/cache.h

index 97b4118d3b299fc2df99a859768ec4beaf26e6b1..fe65ddbae927c3bf00c1b205cf810e21d1b0a3f0 100644 (file)
@@ -4740,18 +4740,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                         * view but is not yet configured.  If it is not the
                         * view name but not a forward reference either, then it
                         * is simply a named cache that is not shared.
-                        *
-                        * We use two separate memory contexts for the
-                        * cache, for the main cache memory and the heap
-                        * memory.
                         */
-                       isc_mem_create(&cmctx);
-                       isc_mem_setname(cmctx, "cache");
-                       CHECK(dns_cache_create(cmctx, named_g_taskmgr,
+                       CHECK(dns_cache_create(mctx, named_g_taskmgr,
                                               named_g_timermgr, view->rdclass,
                                               cachename, "rbt", 0, NULL,
                                               &cache));
-                       isc_mem_detach(&cmctx);
                }
                nsc = isc_mem_get(mctx, sizeof(*nsc));
                nsc->cache = NULL;
index 40732e9180eb81558f1ab0cf96fc8c671e6d7ea2..cb7f35a95fde27820be18d211e6bc5976f81d83a 100644 (file)
@@ -127,7 +127,7 @@ struct dns_cache {
        /* Unlocked. */
        unsigned int magic;
        isc_mutex_t lock;
-       isc_mem_t *mctx;  /* Main cache memory */
+       isc_mem_t *mctx;  /* Memory context for the dns_cache object */
        isc_mem_t *hmctx; /* Heap memory */
        isc_mem_t *tmctx; /* Tree memory */
        isc_taskmgr_t *taskmgr;
@@ -331,7 +331,7 @@ cache_free(dns_cache_t *cache) {
 }
 
 isc_result_t
-dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
+dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
                 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
                 const char *cachename, const char *db_type,
                 unsigned int db_argc, char **db_argv, dns_cache_t **cachep) {
@@ -341,31 +341,31 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
 
        REQUIRE(cachep != NULL);
        REQUIRE(*cachep == NULL);
-       REQUIRE(cmctx != NULL);
+       REQUIRE(mctx != NULL);
        REQUIRE(taskmgr != NULL || strcmp(db_type, "rbt") != 0);
        REQUIRE(cachename != NULL);
 
-       cache = isc_mem_get(cmctx, sizeof(*cache));
+       cache = isc_mem_get(mctx, sizeof(*cache));
        *cache = (dns_cache_t){
-               .db_type = isc_mem_strdup(cmctx, db_type),
+               .db_type = isc_mem_strdup(mctx, db_type),
                .rdclass = rdclass,
                .db_argc = db_argc,
                .name = cachename == NULL ? NULL
-                                         : isc_mem_strdup(cmctx, cachename),
+                                         : isc_mem_strdup(mctx, cachename),
                .magic = CACHE_MAGIC,
        };
 
-       isc_mem_attach(cmctx, &cache->mctx);
+       isc_mutex_init(&cache->lock);
+       isc_mem_attach(mctx, &cache->mctx);
 
        if (taskmgr != NULL) {
                isc_taskmgr_attach(taskmgr, &cache->taskmgr);
        }
 
-       isc_mutex_init(&cache->lock);
        isc_refcount_init(&cache->references, 1);
        isc_refcount_init(&cache->live_tasks, 1);
 
-       result = isc_stats_create(cmctx, &cache->stats,
+       result = isc_stats_create(mctx, &cache->stats,
                                  dns_cachestatscounter_max);
        if (result != ISC_R_SUCCESS) {
                goto cleanup;
@@ -382,7 +382,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
        }
 
        if (cache->db_argc != 0) {
-               cache->db_argv = isc_mem_get(cmctx,
+               cache->db_argv = isc_mem_get(mctx,
                                             cache->db_argc * sizeof(char *));
 
                for (i = 0; i < cache->db_argc; i++) {
@@ -390,7 +390,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
                }
 
                for (i = extra; i < cache->db_argc; i++) {
-                       cache->db_argv[i] = isc_mem_strdup(cmctx,
+                       cache->db_argv[i] = isc_mem_strdup(mctx,
                                                           db_argv[i - extra]);
                }
        }
index 5b15a79c7c14d16e8adcc007477010327a067e14..e5c6e49be93262b633a2b19335b02f9b382fb981 100644 (file)
@@ -56,7 +56,7 @@ ISC_LANG_BEGINDECLS
  ***   Functions
  ***/
 isc_result_t
-dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
+dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
                 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
                 const char *cachename, const char *db_type,
                 unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
@@ -68,7 +68,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
  *
  * Requires:
  *
- *\li  'cmctx' are valid memory contexts.
+ *\li  'mctx' is a valid memory context.
  *
  *\li  'taskmgr' is a valid task manager (if 'db_type' is "rbt").
  *
@@ -77,6 +77,8 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
  *     periodic cleaning of the cache will take place.
  *
  *\li  'cachename' is a valid string.  This must not be NULL.
+
+ *\li  'mctx' is a valid memory context.
  *
  *\li  'cachep' is a valid pointer, and *cachep == NULL
  *