]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
update cfg_obj_attach/destroy
authorEvan Hunt <each@isc.org>
Tue, 21 Oct 2025 23:41:11 +0000 (16:41 -0700)
committerEvan Hunt <each@isc.org>
Thu, 23 Oct 2025 20:01:02 +0000 (13:01 -0700)
now that cfg_obj_destroy() has been simplified, we can use the
ISC_REFCOUNT macros to declare cfg_obj_attach() and _detach().

22 files changed:
bin/check/named-checkconf.c
bin/delv/delv.c
bin/dig/dighost.c
bin/dnssec/dnssec-keygen.c
bin/dnssec/dnssec-ksr.c
bin/named/config.c
bin/named/controlconf.c
bin/named/main.c
bin/named/server.c
bin/nsupdate/nsupdate.c
bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
bin/plugins/synthrecord.c
bin/rndc/rndc.c
bin/tests/system/hooks/driver/test-syncplugin.c
doc/misc/cfg_test.c
lib/isccfg/include/isccfg/cfg.h
lib/isccfg/namedconf.c
lib/isccfg/parser.c
tests/isccfg/duration_test.c
tests/isccfg/grammar_test.c
tests/isccfg/parser_test.c

index 4f7bfcee56069ef6744ef25f9d2b651b0ce1fc86..0c217efd924441b43538d8ddaa4ee1f26f785ab0 100644 (file)
@@ -745,7 +745,7 @@ main(int argc, char **argv) {
 
 cleanup:
        if (config != NULL) {
-               cfg_obj_destroy(&config);
+               cfg_obj_detach(&config);
        }
 
        if (parser != NULL) {
index 997c9fb73bd99e2148733e193581c8056da7ce52..dd53c825fa36c98af70383c437b04c1150881a03 100644 (file)
@@ -862,7 +862,7 @@ setup_dnsseckeys(dns_client_t *client, dns_view_t *toview) {
 
 cleanup:
        if (bindkeys != NULL) {
-               cfg_obj_destroy(&bindkeys);
+               cfg_obj_detach(&bindkeys);
        }
        if (parser != NULL) {
                cfg_parser_destroy(&parser);
index a79bf61f9dca597be96e0b5f734aa95b19541d47..51949c2cc9fdffbffd9718681773d255b3f0436e 100644 (file)
@@ -1119,7 +1119,7 @@ read_confkey(void) {
 cleanup:
        if (pctx != NULL) {
                if (file != NULL) {
-                       cfg_obj_destroy(&file);
+                       cfg_obj_detach(&file);
                }
                cfg_parser_destroy(&pctx);
        }
index 04b8a8056fafa8f27b2ee5e5d4bcc8b70bc32f92..ab53148b44950ce4c9e01aa59649a4021f0a9f94 100644 (file)
@@ -1199,7 +1199,7 @@ main(int argc, char **argv) {
                        }
 
                        dns_kasp_detach(&kasp);
-                       cfg_obj_destroy(&config);
+                       cfg_obj_detach(&config);
                        cfg_parser_destroy(&parser);
                }
        } else {
index 073bbda1a92de972739afa0bd0c26f51892bb54a..0a43fd889acc708c8c786baed4f37d80b0376e97 100644 (file)
@@ -187,7 +187,7 @@ getkasp(ksr_ctx_t *ksr, dns_kasp_t **kasp) {
        if (ISC_LIST_EMPTY(dns_kasp_keys(*kasp))) {
                fatal("dnssec-policy '%s' has no keys configured", ksr->policy);
        }
-       cfg_obj_destroy(&config);
+       cfg_obj_detach(&config);
        cfg_parser_destroy(&parser);
 }
 
index d08e94c959fba926b3b0e5842ed1b3c66aba423e..d7022be01bacecd9afc73b490d803e6fb3d9fe56 100644 (file)
@@ -467,7 +467,7 @@ named_config_parsefile(cfg_parser_t *parser, cfg_obj_t **conf) {
 
 cleanup:
        if (*conf) {
-               cfg_obj_destroy(conf);
+               cfg_obj_detach(conf);
        }
 
 out:
index 26b0fb91975898ce00e4767dd4ce58870d799c30..0ae02c8891ed33f340a663da43cd2c19854475fc 100644 (file)
@@ -861,7 +861,7 @@ cleanup:
                free_controlkey(keyid, mctx);
        }
        if (config != NULL) {
-               cfg_obj_destroy(&config);
+               cfg_obj_detach(&config);
        }
        if (pctx != NULL) {
                cfg_parser_destroy(&pctx);
index 6751b39432616166c3b862fee960e3ddda7a3352..5f171385c8e2c20edcf4ce1473e0a2521a7ee157 100644 (file)
@@ -616,7 +616,7 @@ printversion(bool verbose) {
        if (cfg_obj_isstring(obj)) {
                printf("  geoip-directory:      %s\n", cfg_obj_asstring(obj));
        }
-       cfg_obj_destroy(&config);
+       cfg_obj_detach(&config);
        isc_mem_detach(&geoip_mctx);
 #endif /* HAVE_GEOIP2 */
 }
index b361ab13fb34be1b7e064b8d299b9cf95cf17415..936d3979754cad20fc1b2b523e0bd760e94af5d5 100644 (file)
@@ -2544,7 +2544,7 @@ cleanup:
                dns_zone_detach(&zone);
        }
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
        if (dnsforwarders != NULL) {
                dns_forwarders_detach(&dnsforwarders);
@@ -2785,7 +2785,7 @@ catz_reconfigure(dns_catz_entry_t *entry, void *arg1, void *arg2) {
 
 cleanup:
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
 
        dns_zone_detach(&zone);
@@ -7615,7 +7615,7 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data, isc_buffer_t **text,
 
 cleanup:
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
 
        return result;
@@ -7696,14 +7696,14 @@ for_all_newzone_cfgs(newzone_cfg_cb_t callback, cfg_obj_t *config,
                /*
                 * Destroy the configuration object created in this iteration.
                 */
-               cfg_obj_destroy(&zconfigobj);
+               cfg_obj_detach(&zconfigobj);
        }
 
        if (text != NULL) {
                isc_buffer_free(&text);
        }
        if (zconfigobj != NULL) {
-               cfg_obj_destroy(&zconfigobj);
+               cfg_obj_detach(&zconfigobj);
        }
        mdb_cursor_close(cursor);
 
@@ -7841,7 +7841,7 @@ cleanup:
        UNLOCK(&view->new_zone_lock);
 
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
        if (text != NULL) {
                isc_buffer_free(&text);
@@ -9342,10 +9342,10 @@ cleanup:
                cfg_parser_destroy(&parser);
        }
        if (bindkeys != NULL) {
-               cfg_obj_destroy(&bindkeys);
+               cfg_obj_detach(&bindkeys);
        }
        if (config != NULL) {
-               cfg_obj_destroy(&config);
+               cfg_obj_detach(&config);
        }
 
        return result;
@@ -9579,7 +9579,7 @@ shutdown_server(void *arg) {
                cfg_aclconfctx_detach(&server->aclctx);
        }
 
-       cfg_obj_destroy(&named_g_defaultconfig);
+       cfg_obj_detach(&named_g_defaultconfig);
 
        (void)named_server_saventa(server);
 
@@ -13014,7 +13014,7 @@ cleanup:
        }
 
        if (nzf_config != NULL) {
-               cfg_obj_destroy(&nzf_config);
+               cfg_obj_detach(&nzf_config);
        }
 
        return result;
@@ -13145,7 +13145,7 @@ cleanup:
        }
 
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
        if (view != NULL) {
                dns_view_detach(&view);
@@ -13189,7 +13189,7 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config,
 
                e = UNCONST(elt);
                ISC_LIST_UNLINK(*list, e, link);
-               cfg_obj_destroy(&e->obj);
+               cfg_obj_detach(&e->obj);
                isc_mem_put(pctx->mctx, e, sizeof(*e));
                result = ISC_R_SUCCESS;
                break;
@@ -13715,7 +13715,7 @@ cleanup:
                (void)putnull(text);
        }
        if (zoneconf != NULL) {
-               cfg_obj_destroy(&zoneconf);
+               cfg_obj_detach(&zoneconf);
        }
        if (view != NULL) {
                dns_view_detach(&view);
@@ -14214,7 +14214,7 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex,
 cleanup:
 #ifdef HAVE_LMDB
        if (nzconfig != NULL) {
-               cfg_obj_destroy(&nzconfig);
+               cfg_obj_detach(&nzconfig);
        }
 #endif /* HAVE_LMDB */
        if (isc_buffer_usedlength(*text) > 0) {
@@ -14233,13 +14233,13 @@ newzone_cfgctx_destroy(void **cfgp) {
        cfg = *cfgp;
 
        if (cfg->config != NULL) {
-               cfg_obj_destroy(&cfg->config);
+               cfg_obj_detach(&cfg->config);
        }
        if (cfg->vconfig != NULL) {
-               cfg_obj_destroy(&cfg->vconfig);
+               cfg_obj_detach(&cfg->vconfig);
        }
        if (cfg->nzf_config != NULL) {
-               cfg_obj_destroy(&cfg->nzf_config);
+               cfg_obj_detach(&cfg->nzf_config);
        }
 
        if (cfg->aclctx != NULL) {
index c9d9ce0adff00c49b4a2b064ce336d73e78c6c75..585dc80b91dd5363e9ad85827517b07c95662e1f 100644 (file)
@@ -604,7 +604,7 @@ read_sessionkey(isc_mem_t *mctx) {
 cleanup:
        if (pctx != NULL) {
                if (sessionkey != NULL) {
-                       cfg_obj_destroy(&sessionkey);
+                       cfg_obj_detach(&sessionkey);
                }
                cfg_parser_destroy(&pctx);
        }
index 8b99c6c4bc56503ad83a6a5a216a44e7d390b97b..5d1cf06e524c6d102e37bc1baa90d71de690dc32 100644 (file)
@@ -300,7 +300,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
 
 cleanup:
        if (param_obj != NULL) {
-               cfg_obj_destroy(&param_obj);
+               cfg_obj_detach(&param_obj);
        }
        if (parser != NULL) {
                cfg_parser_destroy(&parser);
@@ -383,7 +383,7 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
 
 cleanup:
        if (param_obj != NULL) {
-               cfg_obj_destroy(&param_obj);
+               cfg_obj_detach(&param_obj);
        }
        if (parser != NULL) {
                cfg_parser_destroy(&parser);
index b9a2b52d5497534704259058d800651b8534def7..ad2ef52f3ac9e7c947e6c40f62aa0fa62bbab90f 100644 (file)
@@ -303,7 +303,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
 
 cleanup:
        if (param_obj != NULL) {
-               cfg_obj_destroy(&param_obj);
+               cfg_obj_detach(&param_obj);
        }
        if (parser != NULL) {
                cfg_parser_destroy(&parser);
@@ -387,7 +387,7 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
 
 cleanup:
        if (param_obj != NULL) {
-               cfg_obj_destroy(&param_obj);
+               cfg_obj_detach(&param_obj);
        }
        if (parser != NULL) {
                cfg_parser_destroy(&parser);
index e963cdad5b018a01d79420861f6286de45903361..5c5f34bf8925419a4ad9be2768c0507c5e5df76b 100644 (file)
@@ -593,7 +593,7 @@ synthrecord_parseconfig(synthrecord_t *inst, const char *parameters,
 
 cleanup:
        if (synthrecordcfg != NULL) {
-               cfg_obj_destroy(&synthrecordcfg);
+               cfg_obj_detach(&synthrecordcfg);
        }
 
        if (parser != NULL) {
index 6aa1e4e67b2641d8aa06761382ba0ca0c561cb3d..3204e30a6367fb414f272816740987bb6de77842 100644 (file)
@@ -999,7 +999,7 @@ main(int argc, char **argv) {
 
        isccc_ccmsg_invalidate(&rndc_ccmsg);
 
-       cfg_obj_destroy(&config);
+       cfg_obj_detach(&config);
        cfg_parser_destroy(&pctx);
 
        isc_mem_put(isc_g_mctx, args, argslen);
index 86bea21cf409f28cb9c3542440b888b342578d56..09856fd2ccf02d029d379311ba559c26a846ba0b 100644 (file)
@@ -217,7 +217,7 @@ cleanup:
        }
 
        if (syncplugincfg != NULL) {
-               cfg_obj_destroy(&syncplugincfg);
+               cfg_obj_detach(&syncplugincfg);
        }
 
        if (parser != NULL) {
index db596e3df8fcf8f4f64107ea211785111e0ea844..60b28bc159342bc08a9f72dd3713ea38031ff586 100644 (file)
@@ -146,7 +146,7 @@ main(int argc, char **argv) {
 
                cfg_print(cfg, output, NULL);
 
-               cfg_obj_destroy(&cfg);
+               cfg_obj_detach(&cfg);
 
                cfg_parser_destroy(&pctx);
        }
index 77576fcf2b48ca115e3d33b2aa6121795551432b..8e861655a50330d35809df40b7358407c16e2be6 100644 (file)
@@ -550,23 +550,6 @@ cfg_obj_istype(const cfg_obj_t *obj, const cfg_type_t *type);
  * Return true iff 'obj' is of type 'type'.
  */
 
-void
-cfg_obj_attach(cfg_obj_t *src, cfg_obj_t **dest);
-/*%<
- * Reference a configuration object.
- */
-
-void
-cfg_obj_destroy(cfg_obj_t **obj);
-/*%<
- * Delete a reference to a configuration object; destroy the object if
- * there are no more references.
- *
- * Require:
- * \li     '*obj' is a valid cfg_obj_t.
- * \li     'mctx' is a valid isc_mem_t.
- */
-
 void
 cfg_obj_log(const cfg_obj_t *obj, int level, const char *fmt, ...)
        ISC_FORMAT_PRINTF(3, 4);
@@ -633,3 +616,5 @@ cfg_pluginlist_foreach(const cfg_obj_t *config, const cfg_obj_t *list,
  *     'list'
  * \li first 'callback' return value which was not #ISC_R_SUCCESS otherwise
  */
+
+ISC_REFCOUNT_DECL(cfg_obj);
index 46e0c54d6df625b27edef85b1ebd87a29500b655..ce30d4b948cf6f8070c4bfba1689b0fea8b3bcc2 100644 (file)
        } while (0)
 
 /*% Clean up a configuration object if non-NULL. */
-#define CLEANUP_OBJ(obj)                         \
-       do {                                     \
-               if ((obj) != NULL)               \
-                       cfg_obj_destroy(&(obj)); \
+#define CLEANUP_OBJ(obj)                        \
+       do {                                    \
+               if ((obj) != NULL)              \
+                       cfg_obj_detach(&(obj)); \
        } while (0)
 
 /*%
index 9042493bb098d1b058a28ff61797a642f4436a78..822ccc83a20610e555400c0684cb949a3318147f 100644 (file)
        } while (0)
 
 /* Clean up a configuration object if non-NULL. */
-#define CLEANUP_OBJ(obj)                         \
-       do {                                     \
-               if ((obj) != NULL)               \
-                       cfg_obj_destroy(&(obj)); \
+#define CLEANUP_OBJ(obj)                        \
+       do {                                    \
+               if ((obj) != NULL)              \
+                       cfg_obj_detach(&(obj)); \
        } while (0)
 
 /* cfg_obj_t magic number */
@@ -1973,7 +1973,7 @@ create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) {
 static void
 free_listelt(isc_mem_t *mctx, cfg_listelt_t *elt) {
        if (elt->obj != NULL) {
-               cfg_obj_destroy(&elt->obj);
+               cfg_obj_detach(&elt->obj);
        }
        isc_mem_put(mctx, elt, sizeof(*elt));
 }
@@ -2305,7 +2305,7 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
                                CHECK(parser_openfile(pctx, g.gl_pathv[i]));
                        }
 
-                       cfg_obj_destroy(&includename);
+                       cfg_obj_detach(&includename);
                        globfree(&g);
 
                        goto redo;
@@ -2333,7 +2333,7 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
                         */
                        CHECK(cfg_parse_obj(pctx, &cfg_type_unsupported,
                                            &eltobj));
-                       cfg_obj_destroy(&eltobj);
+                       cfg_obj_detach(&eltobj);
                        CHECK(parse_semicolon(pctx));
                        continue;
                }
@@ -3769,7 +3769,7 @@ map_symtabitem_destroy(char *key, unsigned int type, isc_symvalue_t symval,
        UNUSED(type);
        UNUSED(userarg);
 
-       cfg_obj_destroy(&obj);
+       cfg_obj_detach(&obj);
 }
 
 static isc_result_t
@@ -3812,37 +3812,25 @@ cfg_obj_istype(const cfg_obj_t *obj, const cfg_type_t *type) {
 /*
  * Destroy 'obj', a configuration object created in 'pctx'.
  */
-void
-cfg_obj_destroy(cfg_obj_t **objp) {
-       REQUIRE(objp != NULL && *objp != NULL);
-       REQUIRE((*objp)->magic == CFGOBJ_MAGIC);
-
-       cfg_obj_t *obj = *objp;
-       *objp = NULL;
-
-       if (isc_refcount_decrement(&obj->references) == 1) {
-               obj->magic = 0;
-
-               if (obj->file != NULL) {
-                       cfg_obj_destroy(&obj->file);
-               }
+static void
+cfg__obj_destroy(cfg_obj_t *obj) {
+       REQUIRE(obj != NULL);
+       REQUIRE(obj->magic == CFGOBJ_MAGIC);
 
-               obj->type->rep->free(obj);
+       obj->magic = 0;
 
-               isc_refcount_destroy(&obj->references);
-               isc_mem_putanddetach(&obj->mctx, obj, sizeof(cfg_obj_t));
+       if (obj->file != NULL) {
+               cfg_obj_detach(&obj->file);
        }
-}
 
-void
-cfg_obj_attach(cfg_obj_t *src, cfg_obj_t **dest) {
-       REQUIRE(src != NULL);
-       REQUIRE(dest != NULL && *dest == NULL);
+       obj->type->rep->free(obj);
 
-       isc_refcount_increment(&src->references);
-       *dest = src;
+       isc_refcount_destroy(&obj->references);
+       isc_mem_putanddetach(&obj->mctx, obj, sizeof(cfg_obj_t));
 }
 
+ISC_REFCOUNT_IMPL(cfg_obj, cfg__obj_destroy);
+
 static void
 free_noop(cfg_obj_t *obj) {
        UNUSED(obj);
index a9524a0c4ae3c89b17e2af4ac06beb0baba41e14..4454933a1cd06696371d41c875b458ad259d0f5e 100644 (file)
@@ -192,7 +192,7 @@ ISC_RUN_TEST_IMPL(duration) {
                        assert_int_equal(cmp, 0);
                }
 
-               cfg_obj_destroy(&c1);
+               cfg_obj_detach(&c1);
                cfg_parser_destroy(&p1);
        }
 }
index d2424b2afe71657bfb206ade62a66ea0a03be55e..ac06a7e49aff0aba7cf8ab11e2c71af1e2dd2b70 100644 (file)
@@ -144,7 +144,7 @@ test__query_source_print(const char *config, const char *expected) {
        output_conf->type->print(&pctx, output_conf);
        assert_text(expected);
 
-       cfg_obj_destroy(parser, &output_conf);
+       cfg_obj_detach(parser, &output_conf);
        cfg_parser_reset(parser);
        cfg_parser_destroy(&parser);
 }
index 7efc320dae43bb40647a5f855058340c7e8e56a7..8ace4ea4f4071b6b8229bab6dc5d4423f18a6d4a 100644 (file)
@@ -102,7 +102,7 @@ ISC_RUN_TEST_IMPL(addzoneconf) {
                strlcat(buf, ";", sizeof(buf));
                assert_string_equal(tests[i], buf);
 
-               cfg_obj_destroy(&conf);
+               cfg_obj_detach(&conf);
                cfg_parser_reset(p);
        }
 
@@ -141,8 +141,8 @@ ISC_RUN_TEST_IMPL(parse_buffer) {
        assert_int_equal(result, ISC_R_SUCCESS);
        assert_int_equal(p2->line, 104);
 
-       cfg_obj_destroy(&c1);
-       cfg_obj_destroy(&c2);
+       cfg_obj_detach(&c1);
+       cfg_obj_detach(&c2);
 
        cfg_parser_destroy(&p1);
        cfg_parser_destroy(&p2);