diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 1cca74d861..13c5ec7593 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -108,7 +108,7 @@ add(char *key, int value) { isc_symvalue_t symvalue; if (sym_mctx == NULL) { - isc_mem_create(&sym_mctx); + isc_mem_create("check-tool", &sym_mctx); } if (symtab == NULL) { diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 5f5f635ecd..98a73cf338 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -619,7 +619,7 @@ main(int argc, char **argv) { } isc_commandline_reset = true; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) { switch (c) { diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index fb49f842d6..b91192bed3 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -535,7 +535,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); if (!quiet) { RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS); } diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index 6f6fce3913..5965c30b82 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -108,6 +108,7 @@ main(int argc, char **argv) { bool keyonly = false; bool quiet = false; int len; + const char *name = argv[0]; keydef = keyfile = RNDC_KEYFILE; @@ -226,7 +227,7 @@ main(int argc, char **argv) { } algname = dst_hmac_algorithm_totext(alg); - isc_mem_create(&mctx); + isc_mem_create(name, &mctx); isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret)); generate_key(mctx, alg, keysize, &key_txtbuffer); diff --git a/bin/confgen/tsig-keygen.c b/bin/confgen/tsig-keygen.c index ff0195b97b..344608dd34 100644 --- a/bin/confgen/tsig-keygen.c +++ b/bin/confgen/tsig-keygen.c @@ -212,7 +212,7 @@ main(int argc, char **argv) { /* Use canonical algorithm name */ algname = dst_hmac_algorithm_totext(alg); - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); if (keyname == NULL) { const char *suffix = NULL; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 0cafbcdf68..b0651e3941 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1352,7 +1352,6 @@ setup_libs(void) { ISC_LOGMODULE_DEFAULT); isc_log_setdebuglevel(0); - isc_mem_setname(mctx, "dig"); mainloop = isc_loop_main(loopmgr); } diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index ecab56dd67..457d5c5ac5 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -1080,7 +1080,7 @@ main(int argc, char *argv[]) { setfatalcallback(cleanup); - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index 81050bd1fd..4421a4574f 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -376,7 +376,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-importkey.c b/bin/dnssec/dnssec-importkey.c index fa6cb4fe92..8f81481cef 100644 --- a/bin/dnssec/dnssec-importkey.c +++ b/bin/dnssec/dnssec-importkey.c @@ -308,7 +308,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index e358eb98ff..62fa240030 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -149,7 +149,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index b63ccb7740..b0679b03e4 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -812,7 +812,7 @@ main(int argc, char **argv) { } isc_commandline_reset = true; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { switch (ch) { diff --git a/bin/dnssec/dnssec-ksr.c b/bin/dnssec/dnssec-ksr.c index e35c5f6ca6..826e635bb5 100644 --- a/bin/dnssec/dnssec-ksr.c +++ b/bin/dnssec/dnssec-ksr.c @@ -1326,7 +1326,7 @@ main(int argc, char *argv[]) { .now = isc_stdtime_now(), }; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index 9dbbb3cf84..b2d7201180 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -82,7 +82,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/dnssec/dnssec-settime.c b/bin/dnssec/dnssec-settime.c index cb99e54066..72d4662f4f 100644 --- a/bin/dnssec/dnssec-settime.c +++ b/bin/dnssec/dnssec-settime.c @@ -244,7 +244,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); setup_logging(); diff --git a/bin/dnssec/dnssec-verify.c b/bin/dnssec/dnssec-verify.c index cd29431223..536dedb48a 100644 --- a/bin/dnssec/dnssec-verify.c +++ b/bin/dnssec/dnssec-verify.c @@ -202,7 +202,7 @@ main(int argc, char *argv[]) { } isc_commandline_reset = true; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_commandline_errprint = false; diff --git a/bin/named/dlz_dlopen_driver.c b/bin/named/dlz_dlopen_driver.c index 5c0dd1f962..95f4ddd366 100644 --- a/bin/named/dlz_dlopen_driver.c +++ b/bin/named/dlz_dlopen_driver.c @@ -222,7 +222,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[], return ISC_R_FAILURE; } - isc_mem_create(&mctx); + isc_mem_create("dlz", &mctx); cd = isc_mem_get(mctx, sizeof(*cd)); *cd = (dlopen_data_t){ .mctx = mctx, diff --git a/bin/named/main.c b/bin/named/main.c index 5cc6fb625d..8ee2edf576 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -608,7 +608,7 @@ printversion(bool verbose) { #if defined(HAVE_GEOIP2) #define RTC(x) RUNTIME_CHECK((x) == ISC_R_SUCCESS) isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("geoip", &mctx); RTC(cfg_parser_create(mctx, &parser)); RTC(named_config_parsedefaults(parser, &config)); RTC(cfg_map_get(config, "options", &defaults)); @@ -1453,7 +1453,6 @@ main(int argc, char *argv[]) { } setup(); - isc_mem_setname(named_g_mctx, "main"); INSIST(named_g_server != NULL); /* diff --git a/bin/tests/system/makejournal.c b/bin/tests/system/makejournal.c index eb85ad25a5..47e69c2892 100644 --- a/bin/tests/system/makejournal.c +++ b/bin/tests/system/makejournal.c @@ -76,7 +76,7 @@ main(int argc, char **argv) { journal = argv[4]; isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); logconfig = isc_logconfig_get(); isc_log_createandusechannel( diff --git a/bin/tests/system/rsabigexponent/bigkey.c b/bin/tests/system/rsabigexponent/bigkey.c index 57072297d0..1a43916615 100644 --- a/bin/tests/system/rsabigexponent/bigkey.c +++ b/bin/tests/system/rsabigexponent/bigkey.c @@ -105,7 +105,7 @@ main(int argc, char **argv) { exit(EXIT_FAILURE); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); dns_log_init(); diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index ec0ecccf5e..dda2cc82c9 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -139,7 +139,7 @@ main(int argc, char *argv[]) { } isc_commandline_reset = true; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { switch (ch) { diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index c9e5406fc3..8e21e5bf06 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -375,7 +375,7 @@ main(int argc, char *argv[]) { fatal("no file specified"); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); CHECKM(dns_dt_open(argv[0], dns_dtmode_file, mctx, &handle), "dns_dt_openfile"); diff --git a/bin/tools/named-journalprint.c b/bin/tools/named-journalprint.c index c8fcc2b75e..78dda92683 100644 --- a/bin/tools/named-journalprint.c +++ b/bin/tools/named-journalprint.c @@ -93,7 +93,7 @@ main(int argc, char **argv) { } file = argv[0]; - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); setup_logging(stderr); if (upgrade) { diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index 9772bb1a8d..71023bb926 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -170,7 +170,7 @@ main(int argc, char *argv[]) { exit(EXIT_SUCCESS); } - isc_mem_create(&mctx); + isc_mem_create(argv[0], &mctx); isc_lex_create(mctx, 256, &lex); /* diff --git a/doc/dev/dev.md b/doc/dev/dev.md index 9c85d3280f..82990665f4 100644 --- a/doc/dev/dev.md +++ b/doc/dev/dev.md @@ -449,7 +449,7 @@ memory has not been freed when BIND shuts down. To create a basic memory context, use: isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("name", &mctx); When holding a persistent reference to a memory context it is advisable to increment its reference counter using `isc_mem_attach()`. Do not just diff --git a/doc/misc/cfg_test.c b/doc/misc/cfg_test.c index 9a26acc194..d039bf07cf 100644 --- a/doc/misc/cfg_test.c +++ b/doc/misc/cfg_test.c @@ -61,7 +61,7 @@ main(int argc, char **argv) { unsigned int zonetype = 0; unsigned int pflags = 0; - isc_mem_create(&mctx); + isc_mem_create("misc", &mctx); setup_logging(); diff --git a/fuzz/dns_master_load.c b/fuzz/dns_master_load.c index 09717329fa..1683d088dd 100644 --- a/fuzz/dns_master_load.c +++ b/fuzz/dns_master_load.c @@ -48,7 +48,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { dns_rdatacallbacks_init(&callbacks); dns_db_t *db = NULL; - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); result = dns_db_create(mctx, ZONEDB_DEFAULT, dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); diff --git a/fuzz/dns_message_checksig.c b/fuzz/dns_message_checksig.c index e1ec609671..e1c2eeefb3 100644 --- a/fuzz/dns_message_checksig.c +++ b/fuzz/dns_message_checksig.c @@ -169,7 +169,7 @@ LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { fputs(c3, fd); fclose(fd); - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_loopmgr_create(mctx, 1, &loopmgr); diff --git a/fuzz/dns_message_parse.c b/fuzz/dns_message_parse.c index 05160b72e2..5f6069266e 100644 --- a/fuzz/dns_message_parse.c +++ b/fuzz/dns_message_parse.c @@ -36,7 +36,7 @@ static uint8_t render_buf[64 * 1024 - 1]; int LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); output = isc_mem_get(mctx, output_len); return 0; diff --git a/fuzz/dns_qp.c b/fuzz/dns_qp.c index 8b9fc08a6e..08a6c4d662 100644 --- a/fuzz/dns_qp.c +++ b/fuzz/dns_qp.c @@ -122,7 +122,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { TRACE("------------------------------------------------"); isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_mem_setdestroycheck(mctx, true); dns_qp_t *qp = NULL; diff --git a/fuzz/dns_rdata_fromtext.c b/fuzz/dns_rdata_fromtext.c index 24d3788dfe..8f2988e2c1 100644 --- a/fuzz/dns_rdata_fromtext.c +++ b/fuzz/dns_rdata_fromtext.c @@ -46,7 +46,7 @@ isc_lexspecials_t specials = { ['('] = 1, [')'] = 1, ['"'] = 1 }; int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_lex_t *lex = NULL; isc_token_t token; diff --git a/fuzz/dns_rdata_fromwire_text.c b/fuzz/dns_rdata_fromwire_text.c index 24db379651..cea16f5595 100644 --- a/fuzz/dns_rdata_fromwire_text.c +++ b/fuzz/dns_rdata_fromwire_text.c @@ -45,7 +45,7 @@ int LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { isc_lexspecials_t specials; - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_lex_create(mctx, 64, &lex); memset(specials, 0, sizeof(specials)); diff --git a/fuzz/isc_lex_getmastertoken.c b/fuzz/isc_lex_getmastertoken.c index 3de61307af..2a65705054 100644 --- a/fuzz/isc_lex_getmastertoken.c +++ b/fuzz/isc_lex_getmastertoken.c @@ -35,7 +35,7 @@ static isc_lex_t *lex = NULL; int LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_lex_create(mctx, 1024, &lex); return 0; diff --git a/fuzz/isc_lex_gettoken.c b/fuzz/isc_lex_gettoken.c index a41893e3e9..3acbe2ddba 100644 --- a/fuzz/isc_lex_gettoken.c +++ b/fuzz/isc_lex_gettoken.c @@ -28,7 +28,7 @@ static isc_lex_t *lex = NULL; int LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { - isc_mem_create(&mctx); + isc_mem_create("fuzz", &mctx); isc_lex_create(mctx, 1024, &lex); return 0; diff --git a/lib/dns/adb.c b/lib/dns/adb.c index ef37c987db..435150e380 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -1732,8 +1732,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, dns_adb_t **newadb) { dns_resolver_attach(view->resolver, &adb->res); isc_mem_attach(mem, &adb->mctx); - isc_mem_create(&adb->hmctx); - isc_mem_setname(adb->hmctx, "ADB_dynamic"); + isc_mem_create("ADB_dynamic", &adb->hmctx); isc_hashmap_create(adb->hmctx, ADB_HASH_BITS, &adb->names); isc_rwlock_init(&adb->names_lock); diff --git a/lib/dns/cache.c b/lib/dns/cache.c index d43865e98f..7084a3943b 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -100,8 +100,7 @@ cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, * This will be the cache memory context, which is subject * to cleaning when the configured memory limits are exceeded. */ - isc_mem_create(&tmctx); - isc_mem_setname(tmctx, "cache"); + isc_mem_create("cache", &tmctx); /* * This will be passed to RBTDB to use for heaps. This is separate @@ -109,8 +108,7 @@ cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, * heavy load and could otherwise cause the cache to be cleaned too * aggressively. */ - isc_mem_create(&hmctx); - isc_mem_setname(hmctx, "cache_heap"); + isc_mem_create("cache_heap", &hmctx); /* * For databases of type "qpcache" or "rbt" (which are the diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index 9962db728b..2851e3d0a7 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -190,8 +190,7 @@ static isc_mem_t *dst__mctx = NULL; void dst__lib_initialize(void) { - isc_mem_create(&dst__mctx); - isc_mem_setname(dst__mctx, "dst"); + isc_mem_create("dst", &dst__mctx); dst__hmacmd5_init(&dst_t_func[DST_ALG_HMACMD5]); dst__hmacsha1_init(&dst_t_func[DST_ALG_HMACSHA1]); diff --git a/lib/dns/message.c b/lib/dns/message.c index 2c44154406..3e92dcd03b 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -5070,15 +5070,15 @@ dns_message_createpools(isc_mem_t *mctx, isc_mempool_t **namepoolp, REQUIRE(namepoolp != NULL && *namepoolp == NULL); REQUIRE(rdspoolp != NULL && *rdspoolp == NULL); - isc_mempool_create(mctx, sizeof(dns_fixedname_t), namepoolp); + isc_mempool_create(mctx, sizeof(dns_fixedname_t), "dns_fixedname_pool", + namepoolp); isc_mempool_setfillcount(*namepoolp, NAME_FILLCOUNT); isc_mempool_setfreemax(*namepoolp, NAME_FREEMAX); - isc_mempool_setname(*namepoolp, "dns_fixedname_pool"); - isc_mempool_create(mctx, sizeof(dns_rdataset_t), rdspoolp); + isc_mempool_create(mctx, sizeof(dns_rdataset_t), "dns_rdataset_pool", + rdspoolp); isc_mempool_setfillcount(*rdspoolp, RDATASET_FILLCOUNT); isc_mempool_setfreemax(*rdspoolp, RDATASET_FREEMAX); - isc_mempool_setname(*rdspoolp, "dns_rdataset_pool"); } void diff --git a/lib/dns/view.c b/lib/dns/view.c index 0cdf603db3..e7d16b9f4a 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -536,8 +536,7 @@ dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr, return result; } - isc_mem_create(&mctx); - isc_mem_setname(mctx, "ADB"); + isc_mem_create("ADB", &mctx); dns_adb_create(mctx, view, &view->adb); isc_mem_detach(&mctx); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index cecad68725..7e61d6869c 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -19052,8 +19052,7 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp) { zmgr->mctxpool = isc_mem_cget(zmgr->mctx, zmgr->workers, sizeof(zmgr->mctxpool[0])); for (size_t i = 0; i < zmgr->workers; i++) { - isc_mem_create(&zmgr->mctxpool[i]); - isc_mem_setname(zmgr->mctxpool[i], "zonemgr-mctxpool"); + isc_mem_create("zonemgr-mctxpool", &zmgr->mctxpool[i]); } /* Key file I/O locks. */ diff --git a/lib/isc/crypto.c b/lib/isc/crypto.c index 604a6439b7..186149d60e 100644 --- a/lib/isc/crypto.c +++ b/lib/isc/crypto.c @@ -252,8 +252,7 @@ void isc__crypto_initialize(void) { uint64_t opts = OPENSSL_INIT_LOAD_CONFIG; - isc_mem_create(&isc__crypto_mctx); - isc_mem_setname(isc__crypto_mctx, "OpenSSL"); + isc_mem_create("OpenSSL", &isc__crypto_mctx); isc_mem_setdestroycheck(isc__crypto_mctx, false); #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 09382cfc02..fd4238f67b 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -200,17 +200,17 @@ mallocx(size_t size, int flags); extern volatile void *isc__mem_malloc; -#define isc_mem_create(cp) \ +#define isc_mem_create(name, cp) \ { \ - isc__mem_create((cp)_ISC_MEM_FILELINE); \ + isc__mem_create((name), (cp)_ISC_MEM_FILELINE); \ isc__mem_malloc = mallocx; \ ISC_INSIST(CMM_ACCESS_ONCE(isc__mem_malloc) != NULL); \ } #else -#define isc_mem_create(cp) isc__mem_create((cp)_ISC_MEM_FILELINE) +#define isc_mem_create(name, cp) isc__mem_create((name), (cp)_ISC_MEM_FILELINE) #endif void -isc__mem_create(isc_mem_t **_ISC_MEM_FLARG); +isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG); /*!< * \brief Create a memory context. @@ -219,9 +219,10 @@ isc__mem_create(isc_mem_t **_ISC_MEM_FLARG); * mctxp != NULL && *mctxp == NULL */ /*@}*/ -#define isc_mem_create_arena(cp) isc__mem_create_arena((cp)_ISC_MEM_FILELINE) +#define isc_mem_create_arena(name, cp) \ + isc__mem_create_arena((name), (cp)_ISC_MEM_FILELINE) void -isc__mem_create_arena(isc_mem_t **_ISC_MEM_FLARG); +isc__mem_create_arena(const char *name, isc_mem_t **_ISC_MEM_FLARG); /*!< * \brief Create a memory context that routs all its operations to a * dedicated jemalloc arena (when available). When jemalloc is not @@ -325,20 +326,6 @@ isc_mem_references(isc_mem_t *ctx); * Return the current reference count. */ -void -isc_mem_setname(isc_mem_t *ctx, const char *name); -/*%< - * Name 'ctx'. - * - * Notes: - * - *\li Only the first 15 characters of 'name' will be copied. - * - * Requires: - * - *\li 'ctx' is a valid ctx. - */ - const char * isc_mem_getname(isc_mem_t *ctx); /*%< @@ -373,11 +360,11 @@ isc_mem_renderjson(void *memobj0); * Memory pools */ -#define isc_mempool_create(c, s, mp) \ - isc__mempool_create((c), (s), (mp)_ISC_MEM_FILELINE) +#define isc_mempool_create(c, s, n, mp) \ + isc__mempool_create((c), (s), (n), (mp)_ISC_MEM_FILELINE) void isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, - isc_mempool_t **mpctxp _ISC_MEM_FLARG); + const char *name, isc_mempool_t **mpctxp _ISC_MEM_FLARG); /*%< * Create a memory pool. * @@ -402,17 +389,6 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp _ISC_MEM_FLARG); *\li The pool has no un"put" allocations outstanding */ -void -isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name); -/*%< - * Associate a name with a memory pool. At most 15 characters may be - *used. - * - * Requires: - *\li mpctx is a valid pool. - *\li name != NULL; - */ - /* * The following functions get/set various parameters. Note that due to * the unlocked nature of pools these are potentially random values diff --git a/lib/isc/log.c b/lib/isc/log.c index 6ffd454750..5aa98f684c 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -1551,7 +1551,7 @@ isc__log_initialize(void) { isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("log", &mctx); isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx)); *isc__lctx = (isc_log_t){ diff --git a/lib/isc/loop.c b/lib/isc/loop.c index 1c7cacb202..8f5da3c859 100644 --- a/lib/isc/loop.c +++ b/lib/isc/loop.c @@ -226,10 +226,7 @@ loop_init(isc_loop_t *loop, isc_loopmgr_t *loopmgr, uint32_t tid, UV_RUNTIME_CHECK(uv_prepare_init, r); uv_handle_set_data(&loop->quiescent, loop); - char name[16]; - snprintf(name, sizeof(name), "%s-%08" PRIx32, kind, tid); - isc_mem_create(&loop->mctx); - isc_mem_setname(loop->mctx, name); + isc_mem_create(kind, &loop->mctx); isc_refcount_init(&loop->references, 1); diff --git a/lib/isc/managers.c b/lib/isc/managers.c index 1695d5f6f9..0dc856b7cf 100644 --- a/lib/isc/managers.c +++ b/lib/isc/managers.c @@ -20,9 +20,8 @@ void isc_managers_create(isc_mem_t **mctxp, uint32_t workers, isc_loopmgr_t **loopmgrp, isc_nm_t **netmgrp) { REQUIRE(mctxp != NULL && *mctxp == NULL); - isc_mem_create(mctxp); + isc_mem_create("managers", mctxp); INSIST(*mctxp != NULL); - isc_mem_setname(*mctxp, "managers"); REQUIRE(loopmgrp != NULL && *loopmgrp == NULL); isc_loopmgr_create(*mctxp, workers, loopmgrp); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 25ab05b955..d8d67fa766 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -123,7 +123,7 @@ struct isc_mem { isc_mutex_t lock; bool checkfree; isc_refcount_t references; - char name[16]; + char *name; atomic_size_t inuse; atomic_bool hi_called; atomic_bool is_overmem; @@ -157,7 +157,7 @@ struct isc_mempool { /*%< Stats only. */ size_t gets; /*%< # of requests to this pool */ /*%< Debugging only. */ - char name[16]; /*%< printed name in stats reports */ + char *name; /*%< printed name in stats reports */ }; /* @@ -450,11 +450,12 @@ isc__mem_shutdown(void) { } static void -mem_create(isc_mem_t **ctxp, unsigned int debugging, unsigned int flags, - unsigned int jemalloc_flags) { +mem_create(const char *name, isc_mem_t **ctxp, unsigned int debugging, + unsigned int flags, unsigned int jemalloc_flags) { isc_mem_t *ctx = NULL; REQUIRE(ctxp != NULL && *ctxp == NULL); + REQUIRE(name != NULL); ctx = mallocx(sizeof(*ctx), jemalloc_flags); INSIST(ctx != NULL); @@ -466,6 +467,7 @@ mem_create(isc_mem_t **ctxp, unsigned int debugging, unsigned int flags, .jemalloc_flags = jemalloc_flags, .jemalloc_arena = ISC_MEM_ILLEGAL_ARENA, .checkfree = true, + .name = strdup(name), }; isc_mutex_init(&ctx->lock); @@ -542,6 +544,8 @@ mem_destroy(isc_mem_t *ctx) { } #endif /* if ISC_MEM_TRACKLINES */ + free(ctx->name); + isc_mutex_destroy(&ctx->lock); if (ctx->checkfree) { @@ -900,15 +904,6 @@ isc_mem_isovermem(isc_mem_t *ctx) { } } -void -isc_mem_setname(isc_mem_t *ctx, const char *name) { - REQUIRE(VALID_CONTEXT(ctx)); - - LOCK(&ctx->lock); - strlcpy(ctx->name, name, sizeof(ctx->name)); - UNLOCK(&ctx->lock); -} - const char * isc_mem_getname(isc_mem_t *ctx) { REQUIRE(VALID_CONTEXT(ctx)); @@ -926,13 +921,14 @@ isc_mem_getname(isc_mem_t *ctx) { void isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, - isc_mempool_t **restrict mpctxp FLARG) { + const char *name, isc_mempool_t **restrict mpctxp FLARG) { isc_mempool_t *restrict mpctx = NULL; size_t size = element_size; REQUIRE(VALID_CONTEXT(mctx)); REQUIRE(size > 0U); REQUIRE(mpctxp != NULL && *mpctxp == NULL); + REQUIRE(name != NULL); /* * Mempools are stored as a linked list of element. @@ -951,6 +947,7 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, .size = size, .freemax = 1, .fillcount = 1, + .name = strdup(name), }; #if ISC_MEM_TRACKLINES @@ -972,14 +969,6 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size, MCTXUNLOCK(mctx); } -void -isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name) { - REQUIRE(VALID_MEMPOOL(mpctx)); - REQUIRE(name != NULL); - - strlcpy(mpctx->name, name, sizeof(mpctx->name)); -} - void isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) { isc_mempool_t *restrict mpctx = NULL; @@ -1029,6 +1018,8 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) { mctx->poolcnt--; MCTXUNLOCK(mctx); + free(mpctx->name); + mpctx->magic = 0; isc_mem_putanddetach(&mpctx->mctx, mpctx, sizeof(isc_mempool_t)); @@ -1415,8 +1406,8 @@ error: #endif /* HAVE_JSON_C */ void -isc__mem_create(isc_mem_t **mctxp FLARG) { - mem_create(mctxp, isc_mem_debugging, isc_mem_defaultflags, 0); +isc__mem_create(const char *name, isc_mem_t **mctxp FLARG) { + mem_create(name, mctxp, isc_mem_debugging, isc_mem_defaultflags, 0); #if ISC_MEM_TRACKLINES if ((isc_mem_debugging & ISC_MEM_DEBUGTRACE) != 0) { fprintf(stderr, "create mctx %p func %s file %s line %u\n", @@ -1426,7 +1417,7 @@ isc__mem_create(isc_mem_t **mctxp FLARG) { } void -isc__mem_create_arena(isc_mem_t **mctxp FLARG) { +isc__mem_create_arena(const char *name, isc_mem_t **mctxp FLARG) { unsigned int arena_no = ISC_MEM_ILLEGAL_ARENA; RUNTIME_CHECK(mem_jemalloc_arena_create(&arena_no)); @@ -1438,7 +1429,7 @@ isc__mem_create_arena(isc_mem_t **mctxp FLARG) { * * https://github.com/jemalloc/jemalloc/issues/2483#issuecomment-1698173849 */ - mem_create(mctxp, isc_mem_debugging, isc_mem_defaultflags, + mem_create(name, mctxp, isc_mem_debugging, isc_mem_defaultflags, arena_no == ISC_MEM_ILLEGAL_ARENA ? 0 : MALLOCX_ARENA(arena_no) | MALLOCX_TCACHE_NONE); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 198083fdd4..a1ec3ab4e0 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -223,12 +223,12 @@ isc_netmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t **netmgrp) { isc_mem_attach(loop->mctx, &worker->mctx); isc_mempool_create(worker->mctx, sizeof(isc_nmsocket_t), - &worker->nmsocket_pool); + "nmsocket_pool", &worker->nmsocket_pool); isc_mempool_setfreemax(worker->nmsocket_pool, ISC_NM_NMSOCKET_MAX); isc_mempool_create(worker->mctx, sizeof(isc__nm_uvreq_t), - &worker->uvreq_pool); + "uvreq_pool", &worker->uvreq_pool); isc_mempool_setfreemax(worker->uvreq_pool, ISC_NM_UVREQS_MAX); isc_loop_attach(loop, &worker->loop); diff --git a/lib/isc/uv.c b/lib/isc/uv.c index 431cecbf48..59330e2d40 100644 --- a/lib/isc/uv.c +++ b/lib/isc/uv.c @@ -132,8 +132,7 @@ void isc__uv_initialize(void) { #if UV_VERSION_HEX >= UV_VERSION(1, 38, 0) int r; - isc_mem_create(&isc__uv_mctx); - isc_mem_setname(isc__uv_mctx, "uv"); + isc_mem_create("uv", &isc__uv_mctx); isc_mem_setdestroycheck(isc__uv_mctx, false); r = uv_replace_allocator(isc__uv_malloc, isc__uv_realloc, diff --git a/lib/isc/xml.c b/lib/isc/xml.c index 495c294689..664a6e8fe8 100644 --- a/lib/isc/xml.c +++ b/lib/isc/xml.c @@ -52,8 +52,7 @@ void isc__xml_initialize(void) { #ifdef HAVE_LIBXML2 #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS - isc_mem_create(&isc__xml_mctx); - isc_mem_setname(isc__xml_mctx, "libxml2"); + isc_mem_create("libxml2", &isc__xml_mctx); isc_mem_setdestroycheck(isc__xml_mctx, false); RUNTIME_CHECK(xmlMemSetup(isc__xml_free, isc__xml_malloc, diff --git a/lib/ns/client.c b/lib/ns/client.c index da97367883..cdc5a49e09 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -2645,8 +2645,7 @@ ns_clientmgr_create(ns_server_t *sctx, isc_loopmgr_t *loopmgr, ns_clientmgr_t *manager = NULL; isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); - isc_mem_setname(mctx, "clientmgr"); + isc_mem_create("clientmgr", &mctx); manager = isc_mem_get(mctx, sizeof(*manager)); *manager = (ns_clientmgr_t){ diff --git a/tests/bench/compress.c b/tests/bench/compress.c index f6c51afea1..59b8759c4d 100644 --- a/tests/bench/compress.c +++ b/tests/bench/compress.c @@ -43,7 +43,7 @@ main(void) { isc_buffer_t buf; isc_mem_t *mctx = NULL; - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); static dns_fixedname_t fixedname[65536]; unsigned int count = 0; diff --git a/tests/bench/load-names.c b/tests/bench/load-names.c index 9957bbc543..67aa7ad5a0 100644 --- a/tests/bench/load-names.c +++ b/tests/bench/load-names.c @@ -420,7 +420,7 @@ main(int argc, char *argv[]) { isc_rwlock_init(&rwl); - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); if (argc != 2) { fprintf(stderr, @@ -494,7 +494,7 @@ main(int argc, char *argv[]) { isc_mem_t *mem = NULL; void *map = NULL; - isc_mem_create(&mem); + isc_mem_create("test", &mem); map = fun->new(mem); size_t nitems = lines / (nthreads + 1); diff --git a/tests/bench/qp-dump.c b/tests/bench/qp-dump.c index 476cab2bfc..33bccc5ec8 100644 --- a/tests/bench/qp-dump.c +++ b/tests/bench/qp-dump.c @@ -161,7 +161,7 @@ main(int argc, char *argv[]) { exit(EXIT_SUCCESS); } - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); filename = argv[0]; result = isc_file_getsize(filename, &fileoff); diff --git a/tests/bench/qplookups.c b/tests/bench/qplookups.c index ed31ecf318..aeb3e8b54c 100644 --- a/tests/bench/qplookups.c +++ b/tests/bench/qplookups.c @@ -197,7 +197,7 @@ main(int argc, char **argv) { usage(); } - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); dns_qp_create(mctx, &methods, NULL, &qp); diff --git a/tests/bench/qpmulti.c b/tests/bench/qpmulti.c index d2d5d5f8b7..07c151e6c6 100644 --- a/tests/bench/qpmulti.c +++ b/tests/bench/qpmulti.c @@ -876,7 +876,7 @@ main(void) { } INSIST(nloops > 1); - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); isc_mem_setdestroycheck(mctx, true); init_logging(); init_items(mctx); diff --git a/tests/dns/qpdb_test.c b/tests/dns/qpdb_test.c index 4b1de18f7d..1fcb968dc7 100644 --- a/tests/dns/qpdb_test.c +++ b/tests/dns/qpdb_test.c @@ -132,7 +132,7 @@ ISC_LOOP_TEST_IMPL(overmempurge_bigrdata) { isc_stdtime_t now = isc_stdtime_now(); size_t i; - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); result = dns_db_create(mctx2, CACHEDB_DEFAULT, dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, @@ -183,7 +183,7 @@ ISC_LOOP_TEST_IMPL(overmempurge_longname) { isc_stdtime_t now = isc_stdtime_now(); size_t i; - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); result = dns_db_create(mctx2, CACHEDB_DEFAULT, dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, diff --git a/tests/isc/mem_test.c b/tests/isc/mem_test.c index 823e46ca94..c58d6b81f7 100644 --- a/tests/isc/mem_test.c +++ b/tests/isc/mem_test.c @@ -56,8 +56,8 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { unsigned int i, j; int rval; - isc_mempool_create(mctx, 24, &mp1); - isc_mempool_create(mctx, 31, &mp2); + isc_mempool_create(mctx, 24, "mp1", &mp1); + isc_mempool_create(mctx, 31, "mp2", &mp2); isc_mempool_setfreemax(mp1, MP1_FREEMAX); isc_mempool_setfillcount(mp1, MP1_FILLCNT); @@ -114,7 +114,7 @@ ISC_RUN_TEST_IMPL(isc_mem_get) { isc_mempool_destroy(&mp1); isc_mempool_destroy(&mp2); - isc_mempool_create(mctx, 2, &mp1); + isc_mempool_create(mctx, 2, "mp1", &mp1); tmp = isc_mempool_get(mp1); assert_non_null(tmp); @@ -183,7 +183,7 @@ ISC_RUN_TEST_IMPL(isc_mem_inuse) { void *ptr; mctx2 = NULL; - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); before = isc_mem_inuse(mctx2); ptr = isc_mem_allocate(mctx2, 1024000); @@ -291,7 +291,7 @@ ISC_RUN_TEST_IMPL(isc_mem_reallocate) { ISC_RUN_TEST_IMPL(isc_mem_overmem) { isc_mem_t *omctx = NULL; - isc_mem_create(&omctx); + isc_mem_create("test", &omctx); assert_non_null(omctx); isc_mem_setwater(omctx, 1024, 512); @@ -337,7 +337,7 @@ ISC_RUN_TEST_IMPL(isc_mem_noflags) { assert_int_equal(result, ISC_R_SUCCESS); isc_mem_debugging = 0; - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); isc__mem_printactive(mctx2, f); @@ -373,7 +373,7 @@ ISC_RUN_TEST_IMPL(isc_mem_recordflag) { result = isc_stdio_open("mem.output", "w", &f); assert_int_equal(result, ISC_R_SUCCESS); - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); @@ -437,7 +437,7 @@ ISC_RUN_TEST_IMPL(isc_mem_traceflag) { assert_non_null(f); isc_mem_debugging = ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGTRACE; - isc_mem_create(&mctx2); + isc_mem_create("test", &mctx2); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); isc__mem_printactive(mctx2, f); diff --git a/tests/libtest/isc.c b/tests/libtest/isc.c index 92a3d8afac..4c2fcc6f2c 100644 --- a/tests/libtest/isc.c +++ b/tests/libtest/isc.c @@ -72,7 +72,7 @@ setup_workers(void **state ISC_ATTR_UNUSED) { int setup_mctx(void **state ISC_ATTR_UNUSED) { isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - isc_mem_create(&mctx); + isc_mem_create("test", &mctx); return 0; }