From 1b716a39f51200027388d90290488a648a8ccf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 5 Sep 2019 18:40:57 +0200 Subject: [PATCH 1/5] Simplify isc_mem_create() to always use defaults and never fail Previously, the isc_mem_create() and isc_mem_createx() functions took `max_size` and `target_size` as first two arguments. Those values were never used in the BIND 9 code. The refactoring removes those arguments and let BIND 9 always use the default values. Previously, the isc_mem_create() and isc_mem_createx() functions could have failed because of failed memory allocation. As this was no longer true and the functions have always returned ISC_R_SUCCESS, the have been refactored to return void. --- conftools/perllib/dnsconf/DNSConf.i | 6 +----- doc/design/logging | 4 ++-- doc/dev/dev.md | 7 ++++--- lib/isc/include/isc/mem.h | 22 ++++------------------ lib/isc/mem.c | 26 ++++++++------------------ 5 files changed, 19 insertions(+), 46 deletions(-) diff --git a/conftools/perllib/dnsconf/DNSConf.i b/conftools/perllib/dnsconf/DNSConf.i index 3238acb850..6e1161a746 100644 --- a/conftools/perllib/dnsconf/DNSConf.i +++ b/conftools/perllib/dnsconf/DNSConf.i @@ -60,8 +60,7 @@ int ctx_init(void) { goto done; } - if (isc_mem_create(0, 0, &ctx.mem) != ISC_R_SUCCESS) - goto done; + isc_mem_create(&ctx.mem); if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS) goto done; @@ -337,6 +336,3 @@ struct DNSConf { %readonly dns_c_ctx_t *confctx; }; - - - diff --git a/doc/design/logging b/doc/design/logging index 84767954c6..ef96992028 100644 --- a/doc/design/logging +++ b/doc/design/logging @@ -282,8 +282,8 @@ rudimentary initialization of both. isc_log_t *lctx; isc_logconfig_t *lcfg; - if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) || - isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) + isc_mem_create(&mctx); + if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) oops_it_didnt_work(); 3) Initalize any additional libraries. The convention for the name of diff --git a/doc/dev/dev.md b/doc/dev/dev.md index de3177fe18..d769d6f18b 100644 --- a/doc/dev/dev.md +++ b/doc/dev/dev.md @@ -504,7 +504,7 @@ memory has not been freed when BIND shuts down. To create a basic memory context, use: isc_mem_t *mctx = NULL; - result = isc_mem_create(0, 0, &mctx); + isc_mem_create(&mctx); (The zeroes are tuning parameters, `max_size` and `target_size`: Any allocations smaller than `max_size` will be satisfied by getting @@ -1069,9 +1069,10 @@ the following steps need to be taken to initialize it. isc_log_t *lctx; isc_logconfig_t *lcfg; - if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) || - isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) + isc_mem_create(&mctx); + if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) { oops_it_didnt_work(); + } 1. Initalize any additional libraries. The convention for the name of the initialization function is `{library}_log_init()`, with a pointer to diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 75ba5a6505..804e00ad02 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -252,30 +252,16 @@ struct isc_mempool { } while (0) /*@{*/ -isc_result_t -isc_mem_create(size_t max_size, size_t target_size, - isc_mem_t **mctxp); +void +isc_mem_create(isc_mem_t **mctxp); -isc_result_t -isc_mem_createx(size_t max_size, size_t target_size, - isc_memalloc_t memalloc, isc_memfree_t memfree, +void +isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, isc_mem_t **mctxp, unsigned int flags); /*!< * \brief Create a memory context. * - * 'max_size' and 'target_size' are tuning parameters. When - * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size' - * will be satisfied by getting blocks of size 'target_size' from the - * system allocator and breaking them up into pieces; larger allocations - * will use the system allocator directly. If 'max_size' and/or - * 'target_size' are zero, default values will be * used. When - * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored. - * - * 'max_size' is also used to size the statistics arrays and the array - * used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting - * 'max_size' too low can have detrimental effects on performance. - * * A memory context created using isc_mem_createx() will obtain * memory from the system by calling 'memalloc' and 'memfree', * passing them the argument 'arg'. A memory context created diff --git a/lib/isc/mem.c b/lib/isc/mem.c index fcfce23503..494578f075 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -725,9 +725,8 @@ initialize_action(void) { * Public. */ -isc_result_t -isc_mem_createx(size_t init_max_size, size_t target_size, - isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, +void +isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, isc_mem_t **ctxp, unsigned int flags) { isc__mem_t *ctx; @@ -748,10 +747,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, isc_mutex_init(&ctx->lock); } - if (init_max_size == 0U) - ctx->max_size = DEF_MAX_SIZE; - else - ctx->max_size = init_max_size; + ctx->max_size = DEF_MAX_SIZE; ctx->flags = flags; isc_refcount_init(&ctx->references, 1); memset(ctx->name, 0, sizeof(ctx->name)); @@ -798,10 +794,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats); if ((flags & ISC_MEMFLAG_INTERNAL) != 0) { - if (target_size == 0U) - ctx->mem_target = DEF_MEM_TARGET; - else - ctx->mem_target = target_size; + ctx->mem_target = DEF_MEM_TARGET; ctx->freelists = (memalloc)(arg, ctx->max_size * sizeof(element *)); RUNTIME_CHECK(ctx->freelists != NULL); @@ -830,8 +823,6 @@ isc_mem_createx(size_t init_max_size, size_t target_size, UNLOCK(&contextslock); *ctxp = (isc_mem_t *)ctx; - - return (ISC_R_SUCCESS); } static void @@ -2371,11 +2362,10 @@ isc_mem_renderjson(void *memobj0) { } #endif /* HAVE_JSON_C */ -isc_result_t -isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) { - return (isc_mem_createx(init_max_size, target_size, - default_memalloc, default_memfree, - NULL, mctxp, isc_mem_defaultflags)); +void +isc_mem_create(isc_mem_t **mctxp) { + isc_mem_createx(default_memalloc, default_memfree, + NULL, mctxp, isc_mem_defaultflags); } void * From 6bd2eb06cbbba09c24e7ab5d5323343c5c2a881f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 5 Sep 2019 18:35:03 +0200 Subject: [PATCH 2/5] Add a semantic patch to make refactor the isc_mem_create() --- cocci/isc_mem_create_never_fail.spatch | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 cocci/isc_mem_create_never_fail.spatch diff --git a/cocci/isc_mem_create_never_fail.spatch b/cocci/isc_mem_create_never_fail.spatch new file mode 100644 index 0000000000..e526506ec1 --- /dev/null +++ b/cocci/isc_mem_create_never_fail.spatch @@ -0,0 +1,95 @@ +@@ +statement S; +expression E; +@@ + +- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S; ++ isc_mem_create(E); + +@@ +statement S; +expression V, E; +@@ + +- V = isc_mem_create(0, 0, E); +- if (V == ISC_R_SUCCESS) S ++ isc_mem_create(E); ++ S + + +@@ +statement S; +expression V, E; +@@ + +- V = isc_mem_create(0, 0, E); +- if (V != ISC_R_SUCCESS) S ++ isc_mem_create(E); + +@@ +expression V, E; +@@ + +- V = isc_mem_create(0, 0, E); +- check_result(V, ...); ++ isc_mem_create(E); + +@@ +statement S; +expression V, E, C; +@@ + +- if (C) { V = isc_mem_create(0, 0, E); } +- if (V != ISC_R_SUCCESS) S ++ if (C) { isc_mem_create(E); } + +@@ +expression E; +@@ + +- RUNTIME_CHECK(isc_mem_create(0, 0, E) == ISC_R_SUCCESS); ++ isc_mem_create(E); + +@@ +expression E; +@@ + +- RUNCHECK(isc_mem_create(0, 0, E)); ++ isc_mem_create(E); + +@@ +expression E; +@@ + +- CHECK(isc_mem_create(0, 0, E), ...); ++ isc_mem_create(E); + +@@ +expression E; +@@ + +- CHECK(isc_mem_create(0, 0, E)); ++ isc_mem_create(E); + +@@ +expression V, E; +@@ + +- V = isc_mem_create(0, 0, E); +- assert_int_equal(V, ISC_R_SUCCESS); ++ isc_mem_create(E); + +@@ +expression E; +statement S; +@@ + +- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S ++ isc_mem_create(E); + +@@ +expression E; +@@ + +- DO(..., isc_mem_create(0, 0, E)); ++ isc_mem_create(E); From 4957255d139fd780c9ae9c3885696e8aa85c43f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 5 Sep 2019 18:40:57 +0200 Subject: [PATCH 3/5] Use the semantic patch to change the usage isc_mem_create() to new API --- bin/check/check-tool.c | 4 +- bin/check/named-checkconf.c | 2 +- bin/check/named-checkzone.c | 2 +- bin/confgen/ddns-confgen.c | 2 +- bin/confgen/rndc-confgen.c | 2 +- bin/delv/delv.c | 4 +- bin/dig/dighost.c | 3 +- bin/dnssec/dnssec-cds.c | 5 +-- bin/dnssec/dnssec-dsfromkey.c | 5 +-- bin/dnssec/dnssec-importkey.c | 4 +- bin/dnssec/dnssec-keyfromlabel.c | 2 +- bin/dnssec/dnssec-keygen.c | 2 +- bin/dnssec/dnssec-revoke.c | 4 +- bin/dnssec/dnssec-settime.c | 4 +- bin/dnssec/dnssec-signzone.c | 4 +- bin/dnssec/dnssec-verify.c | 4 +- bin/named/main.c | 5 +-- bin/named/server.c | 4 +- bin/named/unix/dlz_dlopen_driver.c | 4 +- bin/named/win32/dlz_dlopen_driver.c | 2 +- bin/nsupdate/nsupdate.c | 3 +- bin/pkcs11/pkcs11-tokens.c | 5 +-- bin/rndc/rndc.c | 2 +- bin/tests/cfg_test.c | 2 +- bin/tests/makejournal.c | 2 +- bin/tests/optional/adb_test.c | 2 +- bin/tests/optional/byaddr_test.c | 2 +- bin/tests/optional/byname_test.c | 2 +- bin/tests/optional/db_test.c | 2 +- bin/tests/optional/gsstest.c | 2 +- bin/tests/optional/inter_test.c | 2 +- bin/tests/optional/lex_test.c | 2 +- bin/tests/optional/log_test.c | 2 +- bin/tests/optional/master_test.c | 2 +- bin/tests/optional/mempool_test.c | 2 +- bin/tests/optional/nsecify.c | 4 +- bin/tests/optional/ratelimiter_test.c | 2 +- bin/tests/optional/rbt_test.c | 7 +--- bin/tests/optional/shutdown_test.c | 4 +- bin/tests/optional/sig0_test.c | 2 +- bin/tests/optional/sock_test.c | 2 +- bin/tests/optional/sym_test.c | 2 +- bin/tests/optional/task_test.c | 2 +- bin/tests/optional/timer_test.c | 2 +- bin/tests/optional/zone_test.c | 2 +- bin/tests/system/pipelined/pipequeries.c | 2 +- bin/tests/system/rsabigexponent/bigkey.c | 2 +- bin/tests/system/tkey/keycreate.c | 2 +- bin/tests/system/tkey/keydelete.c | 2 +- bin/tests/wire_test.c | 2 +- bin/tools/dnstap-read.c | 2 +- bin/tools/mdig.c | 2 +- bin/tools/named-journalprint.c | 2 +- bin/tools/named-rrchecker.c | 2 +- contrib/dlz/bin/dlzbdb/dlzbdb.c | 6 +-- fuzz/dns_rdata_fromwire_text.c | 2 +- fuzz/fuzz.h | 2 +- lib/dns/client.c | 4 +- lib/dns/dnstap.c | 8 ++-- lib/dns/geoip2.c | 6 +-- lib/dns/lib.c | 4 +- lib/dns/name.c | 11 +++-- lib/dns/resolver.c | 7 +--- lib/dns/tests/db_test.c | 9 ++--- lib/dns/tests/dnstest.c | 2 +- lib/dns/view.c | 6 +-- lib/dns/zone.c | 5 +-- lib/irs/context.c | 4 +- lib/irs/tests/resconf_test.c | 5 +-- lib/isc/tests/heap_test.c | 3 +- lib/isc/tests/ht_test.c | 10 ++--- lib/isc/tests/isctest.c | 2 +- lib/isc/tests/lex_test.c | 6 +-- lib/isc/tests/mem_test.c | 51 +++++++----------------- lib/isc/tests/random_test.c | 4 +- lib/isc/tests/task_test.c | 3 +- lib/isccfg/tests/parser_test.c | 2 +- lib/ns/client.c | 12 ++---- lib/ns/lib.c | 6 +-- lib/ns/tests/nstest.c | 2 +- lib/samples/nsprobe.c | 4 +- lib/samples/resolve.c | 12 +----- lib/samples/sample-async.c | 4 +- lib/samples/sample-request.c | 6 +-- lib/samples/sample-update.c | 6 +-- 85 files changed, 117 insertions(+), 246 deletions(-) diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index c88adb8550..e9ab4eb633 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -127,9 +127,7 @@ add(char *key, int value) { isc_symvalue_t symvalue; if (sym_mctx == NULL) { - result = isc_mem_create(0, 0, &sym_mctx); - if (result != ISC_R_SUCCESS) - return; + isc_mem_create(&sym_mctx); } if (symtab == NULL) { diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 2da105e52b..a0dea04667 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -585,7 +585,7 @@ main(int argc, char **argv) { } isc_commandline_reset = true; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&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 11d494a2e3..de6bb94b8e 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -517,7 +517,7 @@ main(int argc, char **argv) { InitSockets(); #endif - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); if (!quiet) RUNTIME_CHECK(setup_logging(mctx, errout, &lctx) == ISC_R_SUCCESS); diff --git a/bin/confgen/ddns-confgen.c b/bin/confgen/ddns-confgen.c index 45603f0757..af5b0b3b65 100644 --- a/bin/confgen/ddns-confgen.c +++ b/bin/confgen/ddns-confgen.c @@ -207,7 +207,7 @@ main(int argc, char **argv) { /* Use canonical algorithm name */ algname = alg_totext(alg); - DO("create memory context", isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); if (keyname == NULL) { const char *suffix = NULL; diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index ad2536e0c8..30d4cf99e0 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -209,7 +209,7 @@ main(int argc, char **argv) { keysize = alg_bits(alg); algname = alg_totext(alg); - DO("create memory context", isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret)); generate_key(mctx, alg, keysize, &key_txtbuffer); diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 78e0d15d8d..7155d4b299 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -1642,9 +1642,7 @@ main(int argc, char *argv[]) { if (result != ISC_R_SUCCESS) fatal("dns_lib_init failed: %d", result); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("failed to create mctx"); + isc_mem_create(&mctx); CHECK(isc_appctx_create(mctx, &actx)); CHECK(isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr)); diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 3a21d6516f..62da6e3a73 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1365,8 +1365,7 @@ setup_libs(void) { if (!have_ipv6 && !have_ipv4) fatal("can't find either v4 or v6 networking"); - result = isc_mem_create(0, 0, &mctx); - check_result(result, "isc_mem_create"); + isc_mem_create(&mctx); isc_mem_setname(mctx, "dig", NULL); result = isc_log_create(mctx, &lctx, &logconfig); diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index 673442c4ae..9b362630fa 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -1074,10 +1074,7 @@ main(int argc, char *argv[]) { int ch; char *endp; - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - fatal("out of memory"); - } + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index d6f44d8566..b598d91d0e 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -350,10 +350,7 @@ main(int argc, char **argv) { usage(); } - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - fatal("out of memory"); - } + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-importkey.c b/bin/dnssec/dnssec-importkey.c index 494535bd10..c97bfe3624 100644 --- a/bin/dnssec/dnssec-importkey.c +++ b/bin/dnssec/dnssec-importkey.c @@ -300,9 +300,7 @@ main(int argc, char **argv) { if (argc == 1) usage(); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("out of memory"); + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index 888d34bc09..e9dfe36f4f 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -163,7 +163,7 @@ main(int argc, char **argv) { if (argc == 1) usage(); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 2fad3fb285..85362db2a1 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -259,7 +259,7 @@ main(int argc, char **argv) { } isc_commandline_reset = true; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); isc_stdtime_get(&now); diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index cb4b2a2ce4..1d9fa1680a 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -88,9 +88,7 @@ main(int argc, char **argv) { if (argc == 1) usage(); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("Out of memory"); + isc_mem_create(&mctx); #if HAVE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-settime.c b/bin/dnssec/dnssec-settime.c index 654b96f6ce..bcf32c72b7 100644 --- a/bin/dnssec/dnssec-settime.c +++ b/bin/dnssec/dnssec-settime.c @@ -167,9 +167,7 @@ main(int argc, char **argv) { if (argc == 1) usage(); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("Out of memory"); + isc_mem_create(&mctx); setup_logging(mctx, &log); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 56c85a0759..005e7fe810 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -3230,9 +3230,7 @@ main(int argc, char *argv[]) { check_result(isc_app_start(), "isc_app_start"); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("out of memory"); + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/dnssec/dnssec-verify.c b/bin/dnssec/dnssec-verify.c index 420bf979b8..483577ef4f 100644 --- a/bin/dnssec/dnssec-verify.c +++ b/bin/dnssec/dnssec-verify.c @@ -209,9 +209,7 @@ main(int argc, char *argv[]) { isc_commandline_reset = true; check_result(isc_app_start(), "isc_app_start"); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - fatal("out of memory"); + isc_mem_create(&mctx); #if USE_PKCS11 pk11_result_register(); diff --git a/bin/named/main.c b/bin/named/main.c index 565dfe1253..de914870cc 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -1462,10 +1462,7 @@ main(int argc, char *argv[]) { named_g_chrootdir); } - result = isc_mem_create(0, 0, &named_g_mctx); - if (result != ISC_R_SUCCESS) - named_main_earlyfatal("isc_mem_create() failed: %s", - isc_result_totext(result)); + isc_mem_create(&named_g_mctx); isc_mem_setname(named_g_mctx, "main", NULL); setup(); diff --git a/bin/named/server.c b/bin/named/server.c index 9c3bd99e3c..5f9fdd21e2 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -4349,9 +4349,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, * cache, for the main cache memory and the heap * memory. */ - CHECK(isc_mem_create(0, 0, &cmctx)); + isc_mem_create(&cmctx); isc_mem_setname(cmctx, "cache", NULL); - CHECK(isc_mem_create(0, 0, &hmctx)); + isc_mem_create(&hmctx); isc_mem_setname(hmctx, "cache_heap", NULL); CHECK(dns_cache_create(cmctx, hmctx, named_g_taskmgr, named_g_timermgr, view->rdclass, diff --git a/bin/named/unix/dlz_dlopen_driver.c b/bin/named/unix/dlz_dlopen_driver.c index c1e2f8905b..3b3682e46d 100644 --- a/bin/named/unix/dlz_dlopen_driver.c +++ b/bin/named/unix/dlz_dlopen_driver.c @@ -225,9 +225,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[], return (ISC_R_FAILURE); } - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - return (result); + isc_mem_create(&mctx); cd = isc_mem_get(mctx, sizeof(*cd)); memset(cd, 0, sizeof(*cd)); diff --git a/bin/named/win32/dlz_dlopen_driver.c b/bin/named/win32/dlz_dlopen_driver.c index d6dd10e67a..d981aaf585 100644 --- a/bin/named/win32/dlz_dlopen_driver.c +++ b/bin/named/win32/dlz_dlopen_driver.c @@ -224,7 +224,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[], return (ISC_R_FAILURE); } - isc_mem_create(0, 0, &mctx); + isc_mem_create(&mctx); cd = isc_mem_get(mctx, sizeof(*cd)); memset(cd, 0, sizeof(*cd)); diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 378a78d24e..f403095e6b 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -3269,8 +3269,7 @@ main(int argc, char **argv) { pre_parse_args(argc, argv); - result = isc_mem_create(0, 0, &gmctx); - check_result(result, "isc_mem_create"); + isc_mem_create(&gmctx); parse_args(argc, argv); diff --git a/bin/pkcs11/pkcs11-tokens.c b/bin/pkcs11/pkcs11-tokens.c index 6971084d6e..82584e1a84 100644 --- a/bin/pkcs11/pkcs11-tokens.c +++ b/bin/pkcs11/pkcs11-tokens.c @@ -65,10 +65,7 @@ main(int argc, char *argv[]) { exit(1); } - if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) { - fprintf(stderr, "isc_mem_create() failed\n"); - exit(1); - } + isc_mem_create(&mctx); pk11_result_register(); diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 6f9c9b307c..29733ca409 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -930,7 +930,7 @@ main(int argc, char **argv) { serial = isc_random32(); - DO("create memory context", isc_mem_create(0, 0, &rndc_mctx)); + isc_mem_create(&rndc_mctx); DO("create socket manager", isc_socketmgr_create(rndc_mctx, &socketmgr)); DO("create task manager", isc_taskmgr_create(rndc_mctx, 1, 0, &taskmgr)); DO("create task", isc_task_create(taskmgr, 0, &task)); diff --git a/bin/tests/cfg_test.c b/bin/tests/cfg_test.c index d16b3bd699..349c07eb1b 100644 --- a/bin/tests/cfg_test.c +++ b/bin/tests/cfg_test.c @@ -70,7 +70,7 @@ main(int argc, char **argv) { unsigned int zonetype = 0; unsigned int pflags = 0; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_log_create(mctx, &lctx, &lcfg); check_result(result, "isc_log_create()"); diff --git a/bin/tests/makejournal.c b/bin/tests/makejournal.c index 7d206dddc8..95a6609bb3 100644 --- a/bin/tests/makejournal.c +++ b/bin/tests/makejournal.c @@ -96,7 +96,7 @@ main(int argc, char **argv) { journal = argv[4]; isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); CHECK(dst_lib_init(mctx, NULL)); dst_active = true; diff --git a/bin/tests/optional/adb_test.c b/bin/tests/optional/adb_test.c index 0461d7d7d1..1dcdeff0fd 100644 --- a/bin/tests/optional/adb_test.c +++ b/bin/tests/optional/adb_test.c @@ -295,7 +295,7 @@ main(int argc, char **argv) { /* * EVERYTHING needs a memory context. */ - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); cmp = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp) diff --git a/bin/tests/optional/byaddr_test.c b/bin/tests/optional/byaddr_test.c index 1cd0e61661..b72f508708 100644 --- a/bin/tests/optional/byaddr_test.c +++ b/bin/tests/optional/byaddr_test.c @@ -87,7 +87,7 @@ main(int argc, char *argv[]) { dns_result_register(); mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); while ((ch = isc_commandline_parse(argc, argv, "nvw:")) != -1) { switch (ch) { diff --git a/bin/tests/optional/byname_test.c b/bin/tests/optional/byname_test.c index 4299650ec0..ccff87a5fe 100644 --- a/bin/tests/optional/byname_test.c +++ b/bin/tests/optional/byname_test.c @@ -201,7 +201,7 @@ main(int argc, char *argv[]) { dns_result_register(); mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) { switch (ch) { diff --git a/bin/tests/optional/db_test.c b/bin/tests/optional/db_test.c index b30e01ec54..af3dd9cc43 100644 --- a/bin/tests/optional/db_test.c +++ b/bin/tests/optional/db_test.c @@ -362,7 +362,7 @@ main(int argc, char *argv[]) { dns_result_register(); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(dns_dbtable_create(mctx, dns_rdataclass_in, &dbtable) == ISC_R_SUCCESS); diff --git a/bin/tests/optional/gsstest.c b/bin/tests/optional/gsstest.c index 43742c839c..49f0a507d3 100644 --- a/bin/tests/optional/gsstest.c +++ b/bin/tests/optional/gsstest.c @@ -445,7 +445,7 @@ main(int argc, char *argv[]) { dns_result_register(); mctx = NULL; - RUNCHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_setcontext(lctx); diff --git a/bin/tests/optional/inter_test.c b/bin/tests/optional/inter_test.c index e6b08b4cef..a054eba31d 100644 --- a/bin/tests/optional/inter_test.c +++ b/bin/tests/optional/inter_test.c @@ -30,7 +30,7 @@ main(int argc, char **argv) { UNUSED(argc); UNUSED(argv); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_interfaceiter_create(mctx, &iter); if (result != ISC_R_SUCCESS) goto cleanup; diff --git a/bin/tests/optional/lex_test.c b/bin/tests/optional/lex_test.c index c6940255e9..93b4baa608 100644 --- a/bin/tests/optional/lex_test.c +++ b/bin/tests/optional/lex_test.c @@ -90,7 +90,7 @@ main(int argc, char *argv[]) { } } - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_lex_create(mctx, 256, &lex) == ISC_R_SUCCESS); if (masterfile) { diff --git a/bin/tests/optional/log_test.c b/bin/tests/optional/log_test.c index d57bcf015a..23ee80323f 100644 --- a/bin/tests/optional/log_test.c +++ b/bin/tests/optional/log_test.c @@ -106,7 +106,7 @@ main(int argc, char **argv) { lctx = NULL; lcfg = NULL; - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); CHECK(isc_log_create(mctx, &lctx, &lcfg)); CHECK(isc_log_settag(lcfg, progname)); diff --git a/bin/tests/optional/master_test.c b/bin/tests/optional/master_test.c index 0054ab4a0f..7806ded6ec 100644 --- a/bin/tests/optional/master_test.c +++ b/bin/tests/optional/master_test.c @@ -57,7 +57,7 @@ main(int argc, char *argv[]) { UNUSED(argc); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); if (argv[1]) { isc_buffer_init(&source, argv[1], strlen(argv[1])); diff --git a/bin/tests/optional/mempool_test.c b/bin/tests/optional/mempool_test.c index 3474856e32..bc359f41f3 100644 --- a/bin/tests/optional/mempool_test.c +++ b/bin/tests/optional/mempool_test.c @@ -31,7 +31,7 @@ main(int argc, char *argv[]) { isc_mutex_init(&lock); mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); mp1 = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, 24, &mp1) == ISC_R_SUCCESS); diff --git a/bin/tests/optional/nsecify.c b/bin/tests/optional/nsecify.c index e39da005d6..8a7f912812 100644 --- a/bin/tests/optional/nsecify.c +++ b/bin/tests/optional/nsecify.c @@ -186,12 +186,10 @@ nsecify(char *filename) { int main(int argc, char *argv[]) { int i; - isc_result_t result; dns_result_register(); - result = isc_mem_create(0, 0, &mctx); - check_result(result, "isc_mem_create()"); + isc_mem_create(&mctx); argc--; argv++; diff --git a/bin/tests/optional/ratelimiter_test.c b/bin/tests/optional/ratelimiter_test.c index 3e9df9b16d..5bb0f081a6 100644 --- a/bin/tests/optional/ratelimiter_test.c +++ b/bin/tests/optional/ratelimiter_test.c @@ -101,7 +101,7 @@ main(int argc, char *argv[]) { isc_app_start(); isc_interval_set(&linterval, 1, 0); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_taskmgr_create(mctx, 3, 0, &taskmgr) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == diff --git a/bin/tests/optional/rbt_test.c b/bin/tests/optional/rbt_test.c index 404c019778..0fdd5ab5e6 100644 --- a/bin/tests/optional/rbt_test.c +++ b/bin/tests/optional/rbt_test.c @@ -277,12 +277,7 @@ main(int argc, char **argv) { */ isc_mem_debugging = ISC_MEM_DEBUGRECORD; - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - printf("isc_mem_create: %s: exiting\n", - dns_result_totext(result)); - exit(1); - } + isc_mem_create(&mctx); result = dns_rbt_create(mctx, delete_name, NULL, &rbt); if (result != ISC_R_SUCCESS) { diff --git a/bin/tests/optional/shutdown_test.c b/bin/tests/optional/shutdown_test.c index 42b898c505..6c533dc992 100644 --- a/bin/tests/optional/shutdown_test.c +++ b/bin/tests/optional/shutdown_test.c @@ -178,9 +178,9 @@ main(int argc, char *argv[]) { printf("%u workers\n", workers); mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); mctx2 = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx2) == ISC_R_SUCCESS); + isc_mem_create(&mctx2); RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &task_manager) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_timermgr_create(mctx, &timer_manager) == diff --git a/bin/tests/optional/sig0_test.c b/bin/tests/optional/sig0_test.c index 5cf9dd8c86..175edd80cd 100644 --- a/bin/tests/optional/sig0_test.c +++ b/bin/tests/optional/sig0_test.c @@ -207,7 +207,7 @@ main(int argc, char *argv[]) { isc_mutex_init(&lock); mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); while ((ch = isc_commandline_parse(argc, argv, "vp:")) != -1) { switch (ch) { diff --git a/bin/tests/optional/sock_test.c b/bin/tests/optional/sock_test.c index 96b9602292..15ea571c2c 100644 --- a/bin/tests/optional/sock_test.c +++ b/bin/tests/optional/sock_test.c @@ -286,7 +286,7 @@ main(int argc, char *argv[]) { * EVERYTHING needs a memory context. */ mctx = NULL; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); /* * The task manager is independent (other than memory context) diff --git a/bin/tests/optional/sym_test.c b/bin/tests/optional/sym_test.c index adf15adc23..aec15f25f4 100644 --- a/bin/tests/optional/sym_test.c +++ b/bin/tests/optional/sym_test.c @@ -59,7 +59,7 @@ main(int argc, char *argv[]) { } } - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_symtab_create(mctx, 691, undefine_action, NULL, case_sensitive, &st) == ISC_R_SUCCESS); diff --git a/bin/tests/optional/task_test.c b/bin/tests/optional/task_test.c index 73daf55956..9a680c0cc7 100644 --- a/bin/tests/optional/task_test.c +++ b/bin/tests/optional/task_test.c @@ -77,7 +77,7 @@ main(int argc, char *argv[]) { workers = 2; printf("%u workers\n", workers); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) == ISC_R_SUCCESS); diff --git a/bin/tests/optional/timer_test.c b/bin/tests/optional/timer_test.c index a36eced82d..6122aca33e 100644 --- a/bin/tests/optional/timer_test.c +++ b/bin/tests/optional/timer_test.c @@ -107,7 +107,7 @@ main(int argc, char *argv[]) { workers = 2; printf("%u workers\n", workers); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx1) == ISC_R_SUCCESS); + isc_mem_create(&mctx1); RUNTIME_CHECK(isc_taskmgr_create(mctx1, workers, 0, &manager) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_timermgr_create(mctx1, &timgr) == ISC_R_SUCCESS); diff --git a/bin/tests/optional/zone_test.c b/bin/tests/optional/zone_test.c index e9b07d9bc7..9a266e979e 100644 --- a/bin/tests/optional/zone_test.c +++ b/bin/tests/optional/zone_test.c @@ -280,7 +280,7 @@ main(int argc, char **argv) { usage(); RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_taskmgr_create(mctx, 2, 0, &taskmgr) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS); diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 828fac4127..f04b7f0c04 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -268,7 +268,7 @@ main(int argc, char *argv[]) { isc_sockaddr_fromin(&dstaddr, &inaddr, port); mctx = NULL; - RUNCHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); lctx = NULL; lcfg = NULL; diff --git a/bin/tests/system/rsabigexponent/bigkey.c b/bin/tests/system/rsabigexponent/bigkey.c index 7533540e6d..d01d264832 100644 --- a/bin/tests/system/rsabigexponent/bigkey.c +++ b/bin/tests/system/rsabigexponent/bigkey.c @@ -101,7 +101,7 @@ main(int argc, char **argv) { dns_result_register(); - CHECK(isc_mem_create(0, 0, &mctx), "isc_mem_create()"); + isc_mem_create(&mctx); CHECK(dst_lib_init(mctx, NULL), "dst_lib_init()"); CHECK(isc_log_create(mctx, &log_, &logconfig), "isc_log_create()"); isc_log_setcontext(log_); diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c index f872d5e2c8..9ccb24ff32 100644 --- a/bin/tests/system/tkey/keycreate.c +++ b/bin/tests/system/tkey/keycreate.c @@ -227,7 +227,7 @@ main(int argc, char *argv[]) { mctx = NULL; isc_mem_debugging = ISC_MEM_DEBUGRECORD; - RUNCHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); log = NULL; logconfig = NULL; diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c index 0613f697a0..c96d38950c 100644 --- a/bin/tests/system/tkey/keydelete.c +++ b/bin/tests/system/tkey/keydelete.c @@ -166,7 +166,7 @@ main(int argc, char **argv) { dns_result_register(); mctx = NULL; - RUNCHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); log = NULL; logconfig = NULL; diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index 7e3570fdd9..191c4507aa 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -132,7 +132,7 @@ main(int argc, char *argv[]) { } isc_commandline_reset = true; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&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 94fc49a01c..77d964074b 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -342,7 +342,7 @@ main(int argc, char *argv[]) { if (argc < 1) fatal("no file specified"); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); dns_result_register(); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index 06870d51b1..29e2407705 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -2015,7 +2015,7 @@ main(int argc, char *argv[]) { preparse_args(argc, argv); mctx = NULL; - RUNCHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); lctx = NULL; lcfg = NULL; diff --git a/bin/tools/named-journalprint.c b/bin/tools/named-journalprint.c index 46af37ce0f..15d63aca98 100644 --- a/bin/tools/named-journalprint.c +++ b/bin/tools/named-journalprint.c @@ -67,7 +67,7 @@ main(int argc, char **argv) { file = argv[1]; - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS); result = dns_journal_print(mctx, file, stdout); diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index b80227baca..c9f9b4a595 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -146,7 +146,7 @@ main(int argc, char *argv[]) { if (doexit) exit(0); - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(isc_lex_create(mctx, 256, &lex) == ISC_R_SUCCESS); /* diff --git a/contrib/dlz/bin/dlzbdb/dlzbdb.c b/contrib/dlz/bin/dlzbdb/dlzbdb.c index c3cd51811e..d01a50a34b 100644 --- a/contrib/dlz/bin/dlzbdb/dlzbdb.c +++ b/contrib/dlz/bin/dlzbdb/dlzbdb.c @@ -668,11 +668,7 @@ open_lexer(void) { return ISC_R_SUCCESS; /* allocate memory for lexer, and verify it was allocated */ - result = isc_mem_create(0, 0, &lex_mctx); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "unexpected error creating lexer\n"); - return result; - } + isc_mem_create(&lex_mctx); /* create lexer */ result = isc_lex_create(lex_mctx, 1500, &lexer); diff --git a/fuzz/dns_rdata_fromwire_text.c b/fuzz/dns_rdata_fromwire_text.c index 628c71ed27..7b001f21f7 100644 --- a/fuzz/dns_rdata_fromwire_text.c +++ b/fuzz/dns_rdata_fromwire_text.c @@ -98,7 +98,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { rdtype = typelist[(*data++) % types]; size--; rdclass = classlist[(*data++) % classes]; size--; - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); CHECK(isc_lex_create(mctx, 64, &lex)); memset(specials, 0, sizeof(specials)); diff --git a/fuzz/fuzz.h b/fuzz/fuzz.h index 93b9b13d03..1db7b18f82 100644 --- a/fuzz/fuzz.h +++ b/fuzz/fuzz.h @@ -28,7 +28,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); static isc_mem_t *mctx = NULL; static void __attribute__((constructor)) init(void) { - RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); + isc_mem_create(&mctx); RUNTIME_CHECK(dst_lib_init(mctx, NULL) == ISC_R_SUCCESS); } diff --git a/lib/dns/client.c b/lib/dns/client.c index dd37900a71..3d17909132 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -413,9 +413,7 @@ dns_client_create(dns_client_t **clientp, unsigned int options) { unsigned int logdebuglevel = 0; #endif - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - return (result); + isc_mem_create(&mctx); result = isc_appctx_create(mctx, &actx); if (result != ISC_R_SUCCESS) goto cleanup; diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index a32bac2c56..7a4a01ea60 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -164,10 +164,9 @@ dt_init(void) { if (!dt_initialized) { int ret; - if (dt_mctx == NULL) - result = isc_mem_create(0, 0, &dt_mctx); - if (result != ISC_R_SUCCESS) - goto unlock; + if (dt_mctx == NULL) { + isc_mem_create(&dt_mctx); + } isc_mem_setname(dt_mctx, "dt", NULL); isc_mem_setdestroycheck(dt_mctx, false); @@ -177,7 +176,6 @@ dt_init(void) { else result = ISC_R_FAILURE; } -unlock: UNLOCK(&dt_mutex); return (result); diff --git a/lib/dns/geoip2.c b/lib/dns/geoip2.c index c2cd08a804..513e423fa5 100644 --- a/lib/dns/geoip2.c +++ b/lib/dns/geoip2.c @@ -108,10 +108,7 @@ state_key_init(void) { int ret; if (state_mctx == NULL) { - result = isc_mem_create(0, 0, &state_mctx); - } - if (result != ISC_R_SUCCESS) { - goto unlock; + isc_mem_create(&state_mctx); } isc_mem_setname(state_mctx, "geoip_state", NULL); isc_mem_setdestroycheck(state_mctx, false); @@ -123,7 +120,6 @@ state_key_init(void) { result = ISC_R_FAILURE; } } - unlock: UNLOCK(&key_mutex); } diff --git a/lib/dns/lib.c b/lib/dns/lib.c index e2b92a99d7..629d2151dc 100644 --- a/lib/dns/lib.c +++ b/lib/dns/lib.c @@ -54,9 +54,7 @@ initialize(void) { isc_refcount_init(&references, 0); - result = isc_mem_create(0, 0, &dns_g_mctx); - if (result != ISC_R_SUCCESS) - return; + isc_mem_create(&dns_g_mctx); dns_result_register(); result = dns_ecdb_register(dns_g_mctx, &dbimp); if (result != ISC_R_SUCCESS) diff --git a/lib/dns/name.c b/lib/dns/name.c index 03ec8f32c0..6e169bfa90 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1299,10 +1299,9 @@ totext_filter_proc_key_init(void) { if (!thread_key_initialized) { LOCK(&thread_key_mutex); - if (thread_key_mctx == NULL) - result = isc_mem_create(0, 0, &thread_key_mctx); - if (result != ISC_R_SUCCESS) - goto unlock; + if (thread_key_mctx == NULL) { + isc_mem_create(&thread_key_mctx); + } isc_mem_setname(thread_key_mctx, "threadkey", NULL); isc_mem_setdestroycheck(thread_key_mctx, false); @@ -1311,9 +1310,9 @@ totext_filter_proc_key_init(void) { free_specific) != 0) { result = ISC_R_FAILURE; isc_mem_detach(&thread_key_mctx); - } else + } else { thread_key_initialized = 1; - unlock: + } UNLOCK(&thread_key_mutex); } return (result); diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index dc29bccf3c..06787c0d64 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -9977,12 +9977,7 @@ dns_resolver_create(dns_view_t *view, * contention among multiple threads. Do this only when * enabling threads because it will be require more memory. */ - result = isc_mem_create(0, 0, &res->buckets[i].mctx); - if (result != ISC_R_SUCCESS) { - isc_task_detach(&res->buckets[i].task); - isc_mutex_destroy(&res->buckets[i].lock); - goto cleanup_buckets; - } + isc_mem_create(&res->buckets[i].mctx); isc_mem_setname(res->buckets[i].mctx, name, NULL); isc_task_setname(res->buckets[i].task, name, res); ISC_LIST_INIT(res->buckets[i].fctxs); diff --git a/lib/dns/tests/db_test.c b/lib/dns/tests/db_test.c index 6738a53a1f..851df601cb 100644 --- a/lib/dns/tests/db_test.c +++ b/lib/dns/tests/db_test.c @@ -69,8 +69,7 @@ getoriginnode_test(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); @@ -98,8 +97,7 @@ getsetservestalettl_test(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, &db); @@ -142,8 +140,7 @@ dns_dbfind_staleok_test(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache, dns_rdataclass_in, 0, NULL, &db); diff --git a/lib/dns/tests/dnstest.c b/lib/dns/tests/dnstest.c index ce83df60a2..e1d877f59c 100644 --- a/lib/dns/tests/dnstest.c +++ b/lib/dns/tests/dnstest.c @@ -142,7 +142,7 @@ dns_test_begin(FILE *logfile, bool start_managers) { } INSIST(dt_mctx == NULL); - CHECK(isc_mem_create(0, 0, &dt_mctx)); + isc_mem_create(&dt_mctx); /* Don't check the memory leaks as they hide the assertions */ isc_mem_setdestroycheck(dt_mctx, false); diff --git a/lib/dns/view.c b/lib/dns/view.c index cf6550b29d..ce2ca2e096 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -778,11 +778,7 @@ dns_view_createresolver(dns_view_t *view, view->attributes &= ~DNS_VIEWATTR_RESSHUTDOWN; isc_refcount_increment(&view->weakrefs); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - dns_resolver_shutdown(view->resolver); - return (result); - } + isc_mem_create(&mctx); result = dns_adb_create(mctx, view, timermgr, taskmgr, &view->adb); isc_mem_setname(mctx, "ADB", NULL); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 24430e610a..1904c26dc6 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -16775,16 +16775,13 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr) { static isc_result_t mctxinit(void **target, void *arg) { - isc_result_t result; isc_mem_t *mctx = NULL; UNUSED(arg); REQUIRE(target != NULL && *target == NULL); - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) - return (result); + isc_mem_create(&mctx); isc_mem_setname(mctx, "zonemgr-pool", NULL); *target = mctx; diff --git a/lib/irs/context.c b/lib/irs/context.c index c9d4b7d4c3..a359c1ee89 100644 --- a/lib/irs/context.c +++ b/lib/irs/context.c @@ -93,9 +93,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, { isc_result_t result; - result = isc_mem_create(0, 0, mctxp); - if (result != ISC_R_SUCCESS) - goto fail; + isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); if (result != ISC_R_SUCCESS) diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c index 81b601d52a..9b5a44ec6d 100644 --- a/lib/irs/tests/resconf_test.c +++ b/lib/irs/tests/resconf_test.c @@ -34,10 +34,7 @@ static isc_mem_t *mctx = NULL; static void setup_test() { - isc_result_t result; - - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); /* * the caller might run from another directory, but tests diff --git a/lib/isc/tests/heap_test.c b/lib/isc/tests/heap_test.c index 9cc043152a..b0b8e64481 100644 --- a/lib/isc/tests/heap_test.c +++ b/lib/isc/tests/heap_test.c @@ -58,8 +58,7 @@ isc_heap_delete_test(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_heap_create(mctx, compare, idx, 0, &heap); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/tests/ht_test.c b/lib/isc/tests/ht_test.c index ff7446cce1..9129365912 100644 --- a/lib/isc/tests/ht_test.c +++ b/lib/isc/tests/ht_test.c @@ -53,9 +53,8 @@ test_ht_full(int bits, uintptr_t count) { isc_mem_t *mctx = NULL; uintptr_t i; - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx, 0); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx, 0); result = isc_ht_init(&ht, mctx, bits); assert_int_equal(result, ISC_R_SUCCESS); @@ -207,9 +206,8 @@ test_ht_iterator() { unsigned char key[16]; size_t tksize; - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx, 0); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx, 0); result = isc_ht_init(&ht, mctx, 16); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/tests/isctest.c b/lib/isc/tests/isctest.c index 6878354a73..ed5801b56e 100644 --- a/lib/isc/tests/isctest.c +++ b/lib/isc/tests/isctest.c @@ -109,7 +109,7 @@ isc_test_begin(FILE *logfile, bool start_managers, isc_mem_debugging |= ISC_MEM_DEBUGRECORD; INSIST(mctx == NULL); - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); if (logfile != NULL) { isc_logdestination_t destination; diff --git a/lib/isc/tests/lex_test.c b/lib/isc/tests/lex_test.c index ab44d15162..462375ae93 100644 --- a/lib/isc/tests/lex_test.c +++ b/lib/isc/tests/lex_test.c @@ -41,8 +41,7 @@ lex_0xff(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); @@ -75,8 +74,7 @@ lex_setline(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_lex_create(mctx, 1024, &lex); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index 0181b02ae8..74c0fdf1fb 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -95,8 +95,7 @@ isc_mem_test(void **state) { UNUSED(state); - result = isc_mem_create(0, 0, &localmctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&localmctx); result = isc_mempool_create(localmctx, 24, &mp1); assert_int_equal(result, ISC_R_SUCCESS); @@ -169,10 +168,9 @@ isc_mem_test(void **state) { isc_mem_destroy(&localmctx); - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &localmctx, - ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &localmctx, + ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL); result = isc_mempool_create(localmctx, 2, &mp1); assert_int_equal(result, ISC_R_SUCCESS); @@ -191,7 +189,6 @@ isc_mem_test(void **state) { /* test TotalUse calculation */ static void isc_mem_total_test(void **state) { - isc_result_t result; isc_mem_t *mctx2 = NULL; size_t before, after; ssize_t diff; @@ -201,11 +198,8 @@ isc_mem_total_test(void **state) { /* Local alloc, free */ mctx2 = NULL; - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, + isc_mem_createx(default_memalloc, default_memfree, NULL, &mctx2, 0); - if (result != ISC_R_SUCCESS) { - goto out; - } before = isc_mem_total(mctx2); @@ -239,17 +233,12 @@ isc_mem_total_test(void **state) { /* 2048 +8 bytes extra for size_info */ assert_int_equal(diff, (2048 + 8) * 100000); - out: - if (mctx2 != NULL) { - isc_mem_destroy(&mctx2); - } - + isc_mem_destroy(&mctx2); } /* test InUse calculation */ static void isc_mem_inuse_test(void **state) { - isc_result_t result; isc_mem_t *mctx2 = NULL; size_t before, after; ssize_t diff; @@ -258,11 +247,8 @@ isc_mem_inuse_test(void **state) { UNUSED(state); mctx2 = NULL; - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx2, 0); - if (result != ISC_R_SUCCESS) { - goto out; - } + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx2, 0); before = isc_mem_inuse(mctx2); ptr = isc_mem_allocate(mctx2, 1024000); @@ -273,11 +259,7 @@ isc_mem_inuse_test(void **state) { assert_int_equal(diff, 0); - out: - if (mctx2 != NULL) { - isc_mem_destroy(&mctx2); - } - + isc_mem_destroy(&mctx2); } #if ISC_MEM_TRACKLINES @@ -296,9 +278,8 @@ isc_mem_noflags_test(void **state) { UNUSED(state); - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx2, 0); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx2, 0); isc_mem_debugging = 0; ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); @@ -343,9 +324,8 @@ isc_mem_recordflag_test(void **state) { UNUSED(state); - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx2, 0); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx2, 0); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); isc__mem_printactive(mctx2, f); @@ -388,10 +368,9 @@ isc_mem_traceflag_test(void **state) { UNUSED(state); - result = isc_mem_createx(0, 0, default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_createx(default_memalloc, default_memfree, + NULL, &mctx2, 0); isc_mem_debugging = ISC_MEM_DEBUGTRACE; - assert_int_equal(result, ISC_R_SUCCESS); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); isc__mem_printactive(mctx2, f); diff --git a/lib/isc/tests/random_test.c b/lib/isc/tests/random_test.c index 56f37ce025..c3877d9655 100644 --- a/lib/isc/tests/random_test.c +++ b/lib/isc/tests/random_test.c @@ -273,7 +273,6 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) { static void random_test(pvalue_func_t *func, isc_random_func test_func) { isc_mem_t *mctx = NULL; - isc_result_t result; uint32_t m; uint32_t j; uint32_t histogram[11] = { 0 }; @@ -287,8 +286,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) { tables_init(); - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); m = 1000; passed = 0; diff --git a/lib/isc/tests/task_test.c b/lib/isc/tests/task_test.c index 9a0b902e22..a47eb9ba36 100644 --- a/lib/isc/tests/task_test.c +++ b/lib/isc/tests/task_test.c @@ -708,8 +708,7 @@ manytasks(void **state) { isc_condition_init(&cv); isc_mem_debugging = ISC_MEM_DEBUGRECORD; - result = isc_mem_create(0, 0, &mctx); - assert_int_equal(result, ISC_R_SUCCESS); + isc_mem_create(&mctx); result = isc_taskmgr_create(mctx, 4, 0, &taskmgr); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isccfg/tests/parser_test.c b/lib/isccfg/tests/parser_test.c index d684c6b268..84e6e5fd03 100644 --- a/lib/isccfg/tests/parser_test.c +++ b/lib/isccfg/tests/parser_test.c @@ -71,7 +71,7 @@ setup() { isc_result_t result; isc_mem_debugging |= ISC_MEM_DEBUGRECORD; - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; diff --git a/lib/ns/client.c b/lib/ns/client.c index 4cad159a48..cac10a4c4d 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -3043,7 +3043,6 @@ client_timeout(isc_task_t *task, isc_event_t *event) { static isc_result_t get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) { isc_mem_t *clientmctx; - isc_result_t result; #if NMCTXS > 0 unsigned int nextmctx; #endif @@ -3054,10 +3053,9 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) { * Caller must be holding the manager lock. */ if ((manager->sctx->options & NS_SERVER_CLIENTTEST) != 0) { - result = isc_mem_create(0, 0, mctxp); - if (result == ISC_R_SUCCESS) - isc_mem_setname(*mctxp, "client", NULL); - return (result); + isc_mem_create(mctxp); + isc_mem_setname(*mctxp, "client", NULL); + return (ISC_R_SUCCESS); } #if NMCTXS > 0 nextmctx = manager->nextmctx++; @@ -3068,9 +3066,7 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) { clientmctx = manager->mctxpool[nextmctx]; if (clientmctx == NULL) { - result = isc_mem_create(0, 0, &clientmctx); - if (result != ISC_R_SUCCESS) - return (result); + isc_mem_create(&clientmctx); isc_mem_setname(clientmctx, "client", NULL); manager->mctxpool[nextmctx] = clientmctx; diff --git a/lib/ns/lib.c b/lib/ns/lib.c index 66e9025c06..c4c3fe6266 100644 --- a/lib/ns/lib.c +++ b/lib/ns/lib.c @@ -43,13 +43,9 @@ static isc_refcount_t references; static void initialize(void) { - isc_result_t result; - REQUIRE(initialize_done == false); - result = isc_mem_create(0, 0, &ns_g_mctx); - if (result != ISC_R_SUCCESS) - return; + isc_mem_create(&ns_g_mctx); isc_refcount_init(&references, 0); initialize_done = true; diff --git a/lib/ns/tests/nstest.c b/lib/ns/tests/nstest.c index 99d12205d1..e2ff80785e 100644 --- a/lib/ns/tests/nstest.c +++ b/lib/ns/tests/nstest.c @@ -237,7 +237,7 @@ ns_test_begin(FILE *logfile, bool start_managers) { } INSIST(mctx == NULL); - CHECK(isc_mem_create(0, 0, &mctx)); + isc_mem_create(&mctx); if (!dst_active) { CHECK(dst_lib_init(mctx, NULL)); diff --git a/lib/samples/nsprobe.c b/lib/samples/nsprobe.c index c672fb0705..0ca51dd718 100644 --- a/lib/samples/nsprobe.c +++ b/lib/samples/nsprobe.c @@ -215,9 +215,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, { isc_result_t result; - result = isc_mem_create(0, 0, mctxp); - if (result != ISC_R_SUCCESS) - goto fail; + isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); if (result != ISC_R_SUCCESS) diff --git a/lib/samples/resolve.c b/lib/samples/resolve.c index c2620d318f..1715c5c89e 100644 --- a/lib/samples/resolve.c +++ b/lib/samples/resolve.c @@ -113,11 +113,7 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, isc_region_t r; dns_secalg_t alg; - result = isc_mem_create(0, 0, mctxp); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to create mctx\n"); - exit(1); - } + isc_mem_create(mctxp); if (algname != NULL) { tr.base = algname; @@ -367,11 +363,7 @@ main(int argc, char *argv[]) { exit(1); } - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to crate mctx\n"); - exit(1); - } + isc_mem_create(&mctx); result = isc_appctx_create(mctx, &actx); if (result != ISC_R_SUCCESS) diff --git a/lib/samples/sample-async.c b/lib/samples/sample-async.c index 2d577a3ec5..cda22185fe 100644 --- a/lib/samples/sample-async.c +++ b/lib/samples/sample-async.c @@ -97,9 +97,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, { isc_result_t result; - result = isc_mem_create(0, 0, mctxp); - if (result != ISC_R_SUCCESS) - goto fail; + isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); if (result != ISC_R_SUCCESS) diff --git a/lib/samples/sample-request.c b/lib/samples/sample-request.c index 90e0827655..b053f39322 100644 --- a/lib/samples/sample-request.c +++ b/lib/samples/sample-request.c @@ -188,11 +188,7 @@ main(int argc, char *argv[]) { qmessage = NULL; rmessage = NULL; - result = isc_mem_create(0, 0, &mctx); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to create a memory context\n"); - exit(1); - } + isc_mem_create(&mctx); result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage); if (result == ISC_R_SUCCESS) { result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, diff --git a/lib/samples/sample-update.c b/lib/samples/sample-update.c index 6d47ab9d1f..9fa50c136d 100644 --- a/lib/samples/sample-update.c +++ b/lib/samples/sample-update.c @@ -240,11 +240,7 @@ main(int argc, char *argv[]) { fprintf(stderr, "dns_lib_init failed: %u\n", result); exit(1); } - result = isc_mem_create(0, 0, &umctx); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to crate mctx\n"); - exit(1); - } + isc_mem_create(&umctx); result = dns_client_create(&client, 0); if (result != ISC_R_SUCCESS) { From 19fbdef31e1343b653eb452852719a5d447a5bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 6 Sep 2019 11:31:15 +0200 Subject: [PATCH 4/5] Remove unused isc_mem_createx() function The isc_mem_createx() function was only used in the tests to eliminate using the default flags (which as of writing this commit message was ISC_MEMFLAG_INTERNAL and ISC_MEMFLAG_FILL). This commit removes the isc_mem_createx() function from the public API. --- lib/isc/include/isc/mem.h | 23 +---------- lib/isc/mem.c | 80 +++++++++++++++++-------------------- lib/isc/tests/Makefile.in | 5 ++- lib/isc/tests/ht_test.c | 21 +--------- lib/isc/tests/mem_test.c | 34 +++------------- lib/isc/win32/libisc.def.in | 1 - 6 files changed, 50 insertions(+), 114 deletions(-) diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 804e00ad02..54d1cfffd1 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -28,9 +28,6 @@ ISC_LANG_BEGINDECLS #define ISC_MEM_HIWATER 1 typedef void (*isc_mem_water_t)(void *, int); -typedef void * (*isc_memalloc_t)(void *, size_t); -typedef void (*isc_memfree_t)(void *, void *); - /*% * Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory * allocation and freeing by file and line number. @@ -123,14 +120,14 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; #endif /* - * Flags for isc_mem_createx() calls. + * Flags for isc_mem_create() calls. */ #define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */ #define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */ #define ISC_MEMFLAG_FILL 0x00000004 /* fill with pattern after alloc and frees */ #if !ISC_MEM_USE_INTERNAL_MALLOC -#define ISC_MEMFLAG_DEFAULT 0 +#define ISC_MEMFLAG_DEFAULT 0 #else #define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL|ISC_MEMFLAG_FILL #endif @@ -255,25 +252,9 @@ struct isc_mempool { void isc_mem_create(isc_mem_t **mctxp); -void -isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, - void *arg, isc_mem_t **mctxp, unsigned int flags); - /*!< * \brief Create a memory context. * - * A memory context created using isc_mem_createx() will obtain - * memory from the system by calling 'memalloc' and 'memfree', - * passing them the argument 'arg'. A memory context created - * using isc_mem_create() will use the standard library malloc() - * and free(). - * - * If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context - * will be accessed without locking. The user who creates the context must - * ensure there be no race. Since this can be a source of bug, it is generally - * inadvisable to use this flag unless the user is very sure about the race - * condition and the access to the object is highly performance sensitive. - * * Requires: * mctxp != NULL && *mctxp == NULL */ /*@}*/ diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 494578f075..a2709f240d 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -126,15 +126,17 @@ static isc_mutex_t contextslock; */ static uint64_t totallost; +typedef void * (*isc__memalloc_t)(size_t); +typedef void (*isc__memfree_t)(void *); + struct isc__mem { isc_mem_t common; unsigned int flags; isc_mutex_t lock; - isc_memalloc_t memalloc; - isc_memfree_t memfree; - void * arg; + isc__memalloc_t memalloc; + isc__memfree_t memfree; size_t max_size; - bool checkfree; + bool checkfree; struct stats * stats; isc_refcount_t references; char name[16]; @@ -146,8 +148,8 @@ struct isc__mem { size_t maxmalloced; size_t hi_water; size_t lo_water; - bool hi_called; - bool is_overmem; + bool hi_called; + bool is_overmem; isc_mem_water_t water; void * water_arg; ISC_LIST(isc__mempool_t) pools; @@ -360,8 +362,7 @@ more_basic_blocks(isc__mem_t *ctx) { INSIST(ctx->basic_table_count <= ctx->basic_table_size); if (ctx->basic_table_count == ctx->basic_table_size) { table_size = ctx->basic_table_size + TABLE_INCREMENT; - table = (ctx->memalloc)(ctx->arg, - table_size * sizeof(unsigned char *)); + table = (ctx->memalloc)(table_size * sizeof(unsigned char *)); RUNTIME_CHECK(table != NULL); ctx->malloced += table_size * sizeof(unsigned char *); if (ctx->malloced > ctx->maxmalloced) @@ -370,7 +371,7 @@ more_basic_blocks(isc__mem_t *ctx) { memmove(table, ctx->basic_table, ctx->basic_table_size * sizeof(unsigned char *)); - (ctx->memfree)(ctx->arg, ctx->basic_table); + (ctx->memfree)(ctx->basic_table); ctx->malloced -= ctx->basic_table_size * sizeof(unsigned char *); } @@ -378,7 +379,7 @@ more_basic_blocks(isc__mem_t *ctx) { ctx->basic_table_size = table_size; } - tmp = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target); + tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target); RUNTIME_CHECK(tmp != NULL); ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target;; ctx->basic_table[ctx->basic_table_count] = tmp; @@ -471,7 +472,7 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) { /* * memget() was called on something beyond our upper limit. */ - ret = (ctx->memalloc)(ctx->arg, size); + ret = (ctx->memalloc)(size); RUNTIME_CHECK(ret != NULL); ctx->total += size; ctx->inuse += size; @@ -550,7 +551,7 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) { if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) memset(mem, 0xde, size); /* Mnemonic for "dead". */ - (ctx->memfree)(ctx->arg, mem); + (ctx->memfree)(mem); INSIST(ctx->stats[ctx->max_size].gets != 0U); ctx->stats[ctx->max_size].gets--; INSIST(size <= ctx->inuse); @@ -594,7 +595,7 @@ mem_get(isc__mem_t *ctx, size_t size) { #if ISC_MEM_CHECKOVERRUN size += 1; #endif - ret = (ctx->memalloc)(ctx->arg, size); + ret = (ctx->memalloc)(size); RUNTIME_CHECK(ret != NULL); if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { @@ -623,7 +624,7 @@ mem_put(isc__mem_t *ctx, void *mem, size_t size) { #endif if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) memset(mem, 0xde, size); /* Mnemonic for "dead". */ - (ctx->memfree)(ctx->arg, mem); + (ctx->memfree)(mem); } /*! @@ -678,9 +679,8 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) { */ static void * -default_memalloc(void *arg, size_t size) { +default_memalloc(size_t size) { void *ptr; - UNUSED(arg); ptr = malloc(size); @@ -709,8 +709,7 @@ default_memalloc(void *arg, size_t size) { } static void -default_memfree(void *arg, void *ptr) { - UNUSED(arg); +default_memfree(void *ptr) { free(ptr); } @@ -721,27 +720,19 @@ initialize_action(void) { totallost = 0; } -/* - * Public. - */ - -void -isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, - isc_mem_t **ctxp, unsigned int flags) +static void +mem_create(isc_mem_t **ctxp, unsigned int flags) { isc__mem_t *ctx; REQUIRE(ctxp != NULL && *ctxp == NULL); - REQUIRE(memalloc != NULL); - REQUIRE(memfree != NULL); STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0, "wrong alignment size"); RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS); - ctx = (memalloc)(arg, sizeof(*ctx)); - RUNTIME_CHECK(ctx != NULL); + ctx = (default_memalloc)(sizeof(*ctx)); if ((flags & ISC_MEMFLAG_NOLOCK) == 0) { isc_mutex_init(&ctx->lock); @@ -766,9 +757,8 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, ctx->common.impmagic = MEM_MAGIC; ctx->common.magic = ISCAPI_MCTX_MAGIC; ctx->common.methods = (isc_memmethods_t *)&memmethods; - ctx->memalloc = memalloc; - ctx->memfree = memfree; - ctx->arg = arg; + ctx->memalloc = default_memalloc; + ctx->memfree = default_memfree; ctx->stats = NULL; ctx->checkfree = true; #if ISC_MEM_TRACKLINES @@ -785,8 +775,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, ctx->lowest = NULL; ctx->highest = NULL; - ctx->stats = (memalloc)(arg, - (ctx->max_size+1) * sizeof(struct stats)); + ctx->stats = (ctx->memalloc)((ctx->max_size+1) * sizeof(struct stats)); RUNTIME_CHECK(ctx->stats != NULL); memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats)); @@ -795,7 +784,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, if ((flags & ISC_MEMFLAG_INTERNAL) != 0) { ctx->mem_target = DEF_MEM_TARGET; - ctx->freelists = (memalloc)(arg, ctx->max_size * + ctx->freelists = (ctx->memalloc)(ctx->max_size * sizeof(element *)); RUNTIME_CHECK(ctx->freelists != NULL); memset(ctx->freelists, 0, @@ -808,7 +797,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0)) { unsigned int i; - ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT * + ctx->debuglist = (ctx->memalloc)((DEBUG_TABLE_COUNT * sizeof(debuglist_t))); RUNTIME_CHECK(ctx->debuglist != NULL); for (i = 0; i < DEBUG_TABLE_COUNT; i++) @@ -825,6 +814,10 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, *ctxp = (isc_mem_t *)ctx; } +/* + * Public. + */ + static void destroy(isc__mem_t *ctx) { unsigned int i; @@ -856,7 +849,7 @@ destroy(isc__mem_t *ctx) { ctx->malloced -= sizeof(*dl); } - (ctx->memfree)(ctx->arg, ctx->debuglist); + (ctx->memfree)(ctx->debuglist); ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t); } #endif @@ -877,18 +870,18 @@ destroy(isc__mem_t *ctx) { } } - (ctx->memfree)(ctx->arg, ctx->stats); + (ctx->memfree)(ctx->stats); ctx->malloced -= (ctx->max_size+1) * sizeof(struct stats); if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { for (i = 0; i < ctx->basic_table_count; i++) { - (ctx->memfree)(ctx->arg, ctx->basic_table[i]); + (ctx->memfree)(ctx->basic_table[i]); ctx->malloced -= NUM_BASIC_BLOCKS * ctx->mem_target; } - (ctx->memfree)(ctx->arg, ctx->freelists); + (ctx->memfree)(ctx->freelists); ctx->malloced -= ctx->max_size * sizeof(element *); if (ctx->basic_table != NULL) { - (ctx->memfree)(ctx->arg, ctx->basic_table); + (ctx->memfree)(ctx->basic_table); ctx->malloced -= ctx->basic_table_size * sizeof(unsigned char *); } @@ -899,7 +892,7 @@ destroy(isc__mem_t *ctx) { ctx->malloced -= sizeof(*ctx); if (ctx->checkfree) INSIST(ctx->malloced == 0); - (ctx->memfree)(ctx->arg, ctx); + (ctx->memfree)(ctx); } void @@ -2364,8 +2357,7 @@ isc_mem_renderjson(void *memobj0) { void isc_mem_create(isc_mem_t **mctxp) { - isc_mem_createx(default_memalloc, default_memfree, - NULL, mctxp, isc_mem_defaultflags); + mem_create(mctxp, isc_mem_defaultflags); } void * diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 1f5e6b2f10..abeca57a62 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -16,7 +16,10 @@ VERSION=@BIND9_VERSION@ @BIND9_MAKE_INCLUDES@ CINCLUDES = -I. -Iinclude ${ISC_INCLUDES} \ - ${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@ + ${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@ \ + ${JSON_C_CFLAGS} \ + ${LIBXML2_CFLAGS} \ + ${ZLIB_CFLAGS} CDEFINES = -DTESTS="\"${top_builddir}/lib/isc/tests/\"" ISCLIBS = ../libisc.@A@ ${OPENSSL_LIBS} ${JSON_C_LIBS} ${LIBXML2_LIBS} diff --git a/lib/isc/tests/ht_test.c b/lib/isc/tests/ht_test.c index 9129365912..40bfccbc75 100644 --- a/lib/isc/tests/ht_test.c +++ b/lib/isc/tests/ht_test.c @@ -31,21 +31,6 @@ #include #include -static void * -default_memalloc(void *arg, size_t size) { - UNUSED(arg); - if (size == 0U) { - size = 1; - } - return (malloc(size)); -} - -static void -default_memfree(void *arg, void *ptr) { - UNUSED(arg); - free(ptr); -} - static void test_ht_full(int bits, uintptr_t count) { isc_ht_t *ht = NULL; @@ -53,8 +38,7 @@ test_ht_full(int bits, uintptr_t count) { isc_mem_t *mctx = NULL; uintptr_t i; - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx, 0); + isc_mem_create(&mctx); result = isc_ht_init(&ht, mctx, bits); assert_int_equal(result, ISC_R_SUCCESS); @@ -206,8 +190,7 @@ test_ht_iterator() { unsigned char key[16]; size_t tksize; - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx, 0); + isc_mem_create(&mctx); result = isc_ht_init(&ht, mctx, 16); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index 74c0fdf1fb..bdf8c2a53c 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -50,21 +50,6 @@ _setup(void **state) { return (0); } -static void * -default_memalloc(void *arg, size_t size) { - UNUSED(arg); - if (size == 0U) { - size = 1; - } - return (malloc(size)); -} - -static void -default_memfree(void *arg, void *ptr) { - UNUSED(arg); - free(ptr); -} - static int _teardown(void **state) { UNUSED(state); @@ -168,9 +153,7 @@ isc_mem_test(void **state) { isc_mem_destroy(&localmctx); - isc_mem_createx(default_memalloc, default_memfree, - NULL, &localmctx, - ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL); + isc_mem_create(&localmctx); result = isc_mempool_create(localmctx, 2, &mp1); assert_int_equal(result, ISC_R_SUCCESS); @@ -198,8 +181,7 @@ isc_mem_total_test(void **state) { /* Local alloc, free */ mctx2 = NULL; - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_create(&mctx2); before = isc_mem_total(mctx2); @@ -247,8 +229,7 @@ isc_mem_inuse_test(void **state) { UNUSED(state); mctx2 = NULL; - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_create(&mctx2); before = isc_mem_inuse(mctx2); ptr = isc_mem_allocate(mctx2, 1024000); @@ -278,8 +259,7 @@ isc_mem_noflags_test(void **state) { UNUSED(state); - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_create(&mctx2); isc_mem_debugging = 0; ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); @@ -324,8 +304,7 @@ isc_mem_recordflag_test(void **state) { UNUSED(state); - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_create(&mctx2); ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); isc__mem_printactive(mctx2, f); @@ -368,8 +347,7 @@ isc_mem_traceflag_test(void **state) { UNUSED(state); - isc_mem_createx(default_memalloc, default_memfree, - NULL, &mctx2, 0); + isc_mem_create(&mctx2); isc_mem_debugging = ISC_MEM_DEBUGTRACE; ptr = isc_mem_get(mctx2, 2048); assert_non_null(ptr); diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 77e021d486..96097ff1bc 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -348,7 +348,6 @@ isc_md isc_mem_attach isc_mem_checkdestroyed isc_mem_create -isc_mem_createx isc_mem_destroy isc_mem_detach isc_mem_getname From aeea5ece97c5e850359d3b60939c1dc3cad168cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 6 Sep 2019 12:46:57 +0200 Subject: [PATCH 5/5] Remove now useless ISC_MEMFLAG_NOLOCK memflag Previously the libisc allocator had ability to run unlocked when threading was disabled. As the threading is now always on, remove the ISC_MEMFLAG_NOLOCK memory flag as it serves no purpose. --- lib/isc/include/isc/mem.h | 2 +- lib/isc/mem.c | 98 +++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 54d1cfffd1..7d7aecef78 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -122,7 +122,7 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; /* * Flags for isc_mem_create() calls. */ -#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */ +#define ISC_MEMFLAG_RESERVED 0x00000001 /* reserved, obsoleted, don't use */ #define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */ #define ISC_MEMFLAG_FILL 0x00000004 /* fill with pattern after alloc and frees */ diff --git a/lib/isc/mem.c b/lib/isc/mem.c index a2709f240d..fc7a68e31a 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -42,8 +42,8 @@ #include "mem_p.h" -#define MCTXLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l) -#define MCTXUNLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l) +#define MCTXLOCK(m) LOCK(&m->lock) +#define MCTXUNLOCK(m) UNLOCK(&m->lock) #ifndef ISC_MEM_DEBUGGING #define ISC_MEM_DEBUGGING 0 @@ -734,9 +734,7 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) ctx = (default_memalloc)(sizeof(*ctx)); - if ((flags & ISC_MEMFLAG_NOLOCK) == 0) { - isc_mutex_init(&ctx->lock); - } + isc_mutex_init(&ctx->lock); ctx->max_size = DEF_MAX_SIZE; ctx->flags = flags; @@ -887,8 +885,8 @@ destroy(isc__mem_t *ctx) { } } - if ((ctx->flags & ISC_MEMFLAG_NOLOCK) == 0) - isc_mutex_destroy(&ctx->lock); + isc_mutex_destroy(&ctx->lock); + ctx->malloced -= sizeof(*ctx); if (ctx->checkfree) INSIST(ctx->malloced == 0); @@ -951,7 +949,7 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) { goto destroy; } - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); DELETE_TRACE(ctx, ptr, size, file, line); @@ -961,7 +959,7 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) { mem_putstats(ctx, ptr, size); mem_put(ctx, ptr, size); } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); destroy: if (isc_refcount_decrement(&ctx->references) == 1) { @@ -1009,11 +1007,11 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { return (isc__mem_allocate(ctx0, size FLARG_PASS)); if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); ptr = mem_getunlocked(ctx, size); } else { ptr = mem_get(ctx, size); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); if (ptr != NULL) mem_getstats(ctx, size); } @@ -1032,7 +1030,7 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { fprintf(stderr, "maxinuse = %lu\n", (unsigned long)ctx->inuse); } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); if (call_water && (ctx->water != NULL)) (ctx->water)(ctx->water_arg, ISC_MEM_HIWATER); @@ -1064,7 +1062,7 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { return; } - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); DELETE_TRACE(ctx, ptr, size, file, line); @@ -1086,7 +1084,7 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { call_water = true; } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); if (call_water && (ctx->water != NULL)) (ctx->water)(ctx->water_arg, ISC_MEM_LOWATER); @@ -1098,12 +1096,12 @@ isc_mem_waterack(isc_mem_t *ctx0, int flag) { REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); if (flag == ISC_MEM_LOWATER) ctx->hi_called = false; else if (flag == ISC_MEM_HIWATER) ctx->hi_called = true; - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); } #if ISC_MEM_TRACKLINES @@ -1152,7 +1150,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) { const isc__mempool_t *pool; REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); for (i = 0; i <= ctx->max_size; i++) { s = &ctx->stats[i]; @@ -1201,7 +1199,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) { print_active(ctx, out); #endif - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); } /* @@ -1240,7 +1238,7 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); si = mem_allocateunlocked((isc_mem_t *)ctx, size); if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0)) { mem_getstats(ctx, si[-1].u.size); @@ -1265,7 +1263,7 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { fprintf(stderr, "maxinuse = %lu\n", (unsigned long)ctx->inuse); } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); if (call_water) { (ctx->water)(ctx->water_arg, ISC_MEM_HIWATER); @@ -1334,7 +1332,7 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) { size = si->u.size; } - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); DELETE_TRACE(ctx, ptr, size, file, line); @@ -1362,7 +1360,7 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) { if (ctx->water != NULL) call_water = true; } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); if (call_water) (ctx->water)(ctx->water_arg, ISC_MEM_LOWATER); @@ -1397,11 +1395,11 @@ isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) { isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); ctx->checkfree = flag; - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); } size_t @@ -1410,11 +1408,11 @@ isc_mem_inuse(isc_mem_t *ctx0) { size_t inuse; REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); inuse = ctx->inuse; - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); return (inuse); } @@ -1425,11 +1423,11 @@ isc_mem_maxinuse(isc_mem_t *ctx0) { size_t maxinuse; REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); maxinuse = ctx->maxinuse; - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); return (maxinuse); } @@ -1440,11 +1438,11 @@ isc_mem_total(isc_mem_t *ctx0) { size_t total; REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); total = ctx->total; - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); return (total); } @@ -1461,7 +1459,7 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, REQUIRE(VALID_CONTEXT(ctx)); REQUIRE(hiwater >= lowater); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); oldwater = ctx->water; oldwater_arg = ctx->water_arg; if (water == NULL) { @@ -1480,7 +1478,7 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, ctx->hi_water = hiwater; ctx->lo_water = lowater; } - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); if (callwater && oldwater != NULL) (oldwater)(oldwater_arg, ISC_MEM_LOWATER); @@ -1577,10 +1575,10 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) { *mpctxp = (isc_mempool_t *)mpctx; - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); ISC_LIST_INITANDAPPEND(mctx->pools, mpctx, link); mctx->poolcnt++; - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); return (ISC_R_SUCCESS); } @@ -1635,7 +1633,7 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) { /* * Return any items on the free list */ - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); while (mpctx->items != NULL) { INSIST(mpctx->freecount > 0); mpctx->freecount--; @@ -1649,15 +1647,15 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) { mem_put(mctx, item, mpctx->size); } } - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); /* * Remove our linked list entry from the memory context. */ - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); ISC_LIST_UNLINK(mctx->pools, mpctx, link); mctx->poolcnt--; - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); mpctx->common.impmagic = 0; mpctx->common.magic = 0; @@ -1708,7 +1706,7 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) { * We need to dip into the well. Lock the memory context * here and fill up our free list. */ - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); for (i = 0; i < mpctx->fillcount; i++) { if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { item = mem_getunlocked(mctx, mpctx->size); @@ -1723,7 +1721,7 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) { mpctx->items = item; mpctx->freecount++; } - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); } /* @@ -1747,9 +1745,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) { if (ISC_UNLIKELY(((isc_mem_debugging & TRACE_OR_RECORD) != 0) && item != NULL)) { - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); ADD_TRACE(mctx, item, mpctx->size, file, line); - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); } #endif /* ISC_MEM_TRACKLINES */ @@ -1776,9 +1774,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) { #if ISC_MEM_TRACKLINES if (ISC_UNLIKELY((isc_mem_debugging & TRACE_OR_RECORD) != 0)) { - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); DELETE_TRACE(mctx, mem, mpctx->size, file, line); - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); } #endif /* ISC_MEM_TRACKLINES */ @@ -1786,14 +1784,14 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) { * If our free list is full, return this to the mctx directly. */ if (mpctx->freecount >= mpctx->freemax) { - MCTXLOCK(mctx, &mctx->lock); + MCTXLOCK(mctx); if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { mem_putunlocked(mctx, mem, mpctx->size); } else { mem_putstats(mctx, mem, mpctx->size); mem_put(mctx, mem, mpctx->size); } - MCTXUNLOCK(mctx, &mctx->lock); + MCTXUNLOCK(mctx); if (mpctx->lock != NULL) UNLOCK(mpctx->lock); return; @@ -2019,7 +2017,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, REQUIRE(VALID_CONTEXT(ctx)); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context")); @@ -2116,7 +2114,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, TRY0(xmlTextWriterEndElement(writer)); /* context */ error: - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); return (xmlrc); } @@ -2207,7 +2205,7 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) { REQUIRE(summary != NULL); REQUIRE(array != NULL); - MCTXLOCK(ctx, &ctx->lock); + MCTXLOCK(ctx); summary->contextsize += sizeof(*ctx) + (ctx->max_size + 1) * sizeof(struct stats) + @@ -2288,7 +2286,7 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) { CHECKMEM(obj); json_object_object_add(ctxobj, "lowater", obj); - MCTXUNLOCK(ctx, &ctx->lock); + MCTXUNLOCK(ctx); json_object_array_add(array, ctxobj); return (ISC_R_SUCCESS); }