From: Evan Hunt Date: Tue, 21 Oct 2025 23:41:11 +0000 (-0700) Subject: update cfg_obj_attach/destroy X-Git-Tag: v9.21.15~43^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6de1d0dbc4101f24ead3578eacb0fecf22b60152;p=thirdparty%2Fbind9.git update cfg_obj_attach/destroy now that cfg_obj_destroy() has been simplified, we can use the ISC_REFCOUNT macros to declare cfg_obj_attach() and _detach(). --- diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 4f7bfcee560..0c217efd924 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -745,7 +745,7 @@ main(int argc, char **argv) { cleanup: if (config != NULL) { - cfg_obj_destroy(&config); + cfg_obj_detach(&config); } if (parser != NULL) { diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 997c9fb73bd..dd53c825fa3 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -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); diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index a79bf61f9dc..51949c2cc9f 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -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); } diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 04b8a8056fa..ab53148b449 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -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 { diff --git a/bin/dnssec/dnssec-ksr.c b/bin/dnssec/dnssec-ksr.c index 073bbda1a92..0a43fd889ac 100644 --- a/bin/dnssec/dnssec-ksr.c +++ b/bin/dnssec/dnssec-ksr.c @@ -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); } diff --git a/bin/named/config.c b/bin/named/config.c index d08e94c959f..d7022be01ba 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -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: diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 26b0fb91975..0ae02c8891e 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -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); diff --git a/bin/named/main.c b/bin/named/main.c index 6751b394326..5f171385c8e 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -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 */ } diff --git a/bin/named/server.c b/bin/named/server.c index b361ab13fb3..936d3979754 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -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) { diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index c9d9ce0adff..585dc80b91d 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -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); } diff --git a/bin/plugins/filter-a.c b/bin/plugins/filter-a.c index 8b99c6c4bc5..5d1cf06e524 100644 --- a/bin/plugins/filter-a.c +++ b/bin/plugins/filter-a.c @@ -300,7 +300,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters, cleanup: if (param_obj != NULL) { - cfg_obj_destroy(¶m_obj); + cfg_obj_detach(¶m_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(¶m_obj); + cfg_obj_detach(¶m_obj); } if (parser != NULL) { cfg_parser_destroy(&parser); diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index b9a2b52d549..ad2ef52f3ac 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -303,7 +303,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters, cleanup: if (param_obj != NULL) { - cfg_obj_destroy(¶m_obj); + cfg_obj_detach(¶m_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(¶m_obj); + cfg_obj_detach(¶m_obj); } if (parser != NULL) { cfg_parser_destroy(&parser); diff --git a/bin/plugins/synthrecord.c b/bin/plugins/synthrecord.c index e963cdad5b0..5c5f34bf892 100644 --- a/bin/plugins/synthrecord.c +++ b/bin/plugins/synthrecord.c @@ -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) { diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 6aa1e4e67b2..3204e30a636 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -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); diff --git a/bin/tests/system/hooks/driver/test-syncplugin.c b/bin/tests/system/hooks/driver/test-syncplugin.c index 86bea21cf40..09856fd2ccf 100644 --- a/bin/tests/system/hooks/driver/test-syncplugin.c +++ b/bin/tests/system/hooks/driver/test-syncplugin.c @@ -217,7 +217,7 @@ cleanup: } if (syncplugincfg != NULL) { - cfg_obj_destroy(&syncplugincfg); + cfg_obj_detach(&syncplugincfg); } if (parser != NULL) { diff --git a/doc/misc/cfg_test.c b/doc/misc/cfg_test.c index db596e3df8f..60b28bc1593 100644 --- a/doc/misc/cfg_test.c +++ b/doc/misc/cfg_test.c @@ -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); } diff --git a/lib/isccfg/include/isccfg/cfg.h b/lib/isccfg/include/isccfg/cfg.h index 77576fcf2b4..8e861655a50 100644 --- a/lib/isccfg/include/isccfg/cfg.h +++ b/lib/isccfg/include/isccfg/cfg.h @@ -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); diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 46e0c54d6df..ce30d4b948c 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -42,10 +42,10 @@ } 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) /*% diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index 9042493bb09..822ccc83a20 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -88,10 +88,10 @@ } 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); diff --git a/tests/isccfg/duration_test.c b/tests/isccfg/duration_test.c index a9524a0c4ae..4454933a1cd 100644 --- a/tests/isccfg/duration_test.c +++ b/tests/isccfg/duration_test.c @@ -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); } } diff --git a/tests/isccfg/grammar_test.c b/tests/isccfg/grammar_test.c index d2424b2afe7..ac06a7e49af 100644 --- a/tests/isccfg/grammar_test.c +++ b/tests/isccfg/grammar_test.c @@ -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); } diff --git a/tests/isccfg/parser_test.c b/tests/isccfg/parser_test.c index 7efc320dae4..8ace4ea4f40 100644 --- a/tests/isccfg/parser_test.c +++ b/tests/isccfg/parser_test.c @@ -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);