]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change the 'isc_g_mctx' to be always available
authorOndřej Surý <ondrej@isc.org>
Thu, 24 Jul 2025 06:06:04 +0000 (08:06 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 4 Aug 2025 09:29:50 +0000 (11:29 +0200)
This required couple of internal changes to the isc_mem_debugging.

The isc_mem_debugging is now internal to isc_mem unit and there are
three new functions:

1. isc_mem_setdebugging() can change the debugging setting for an
   individual memory context.  This is need for the memory contexts used
   for OpenSSL, libxml and libuv accounting as recording and tracing
   memory is broken there.

2. isc_mem_debugon() / isc_mem_debugoff() can be used to change default
   memory debugging flags as well as debugging flags for isc_g_mctx.

Additionally, the memory debugging is inconsistent across the code-base.
For now, we are keeping the existing flags, but three new environment
variables have been added 'ISC_MEM_DEBUGRECORD', 'ISC_MEM_DEBUGTRACE'
and 'ISC_MEM_DEBUGUSAGE' to set the global debugging flags at any
program using the memory contexts.

44 files changed:
bin/check/check-tool.c
bin/check/named-checkconf.c
bin/check/named-checkzone.c
bin/confgen/rndc-confgen.c
bin/confgen/tsig-keygen.c
bin/delv/delv.c
bin/dig/dig.c
bin/dig/host.c
bin/dnssec/dnssec-cds.c
bin/dnssec/dnssec-dsfromkey.c
bin/dnssec/dnssec-importkey.c
bin/dnssec/dnssec-keyfromlabel.c
bin/dnssec/dnssec-keygen.c
bin/dnssec/dnssec-ksr.c
bin/dnssec/dnssec-revoke.c
bin/dnssec/dnssec-settime.c
bin/dnssec/dnssec-signzone.c
bin/dnssec/dnssec-verify.c
bin/named/main.c
bin/named/server.c
bin/nsupdate/nsupdate.c
bin/rndc/rndc.c
bin/tests/system/rsabigexponent/bigkey.c
bin/tests/system/wire-test.c
bin/tools/dnstap-read.c
bin/tools/mdig.c
bin/tools/named-journalprint.c
bin/tools/named-makejournal.c
bin/tools/named-rrchecker.c
lib/isc/crypto.c
lib/isc/include/isc/mem.h
lib/isc/log.c
lib/isc/managers.c
lib/isc/mem.c
lib/isc/thread.c
lib/isc/uv.c
lib/isc/xml.c
tests/bench/compress.c
tests/bench/load-names.c
tests/bench/qp-dump.c
tests/bench/qplookups.c
tests/bench/qpmulti.c
tests/isc/mem_test.c
tests/libtest/isc.c

index 8a1b3ac3482ba58705bc080663ddb8110cccab93..dd833f6c4d88b01d00e79eaddb1682984eec1ea5 100644 (file)
@@ -106,10 +106,6 @@ add(char *key, int value) {
        isc_result_t result;
        isc_symvalue_t symvalue;
 
-       if (isc_g_mctx == NULL) {
-               isc_mem_create("check-tool", &isc_g_mctx);
-       }
-
        if (symtab == NULL) {
                isc_symtab_create(isc_g_mctx, freekey, isc_g_mctx, false,
                                  &symtab);
index 0a49aec2996e8bb559f377fc7f7421632f98e4b1..5485837fc9861a793004f5493dec9d9b36d83730 100644 (file)
@@ -599,15 +599,15 @@ main(int argc, char **argv) {
                case 'm':
                        if (strcasecmp(isc_commandline_argument, "record") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        }
                        if (strcasecmp(isc_commandline_argument, "trace") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        }
                        if (strcasecmp(isc_commandline_argument, "usage") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
                default:
@@ -616,8 +616,6 @@ main(int argc, char **argv) {
        }
        isc_commandline_reset = true;
 
-       isc_mem_create("default", &isc_g_mctx);
-
        while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
                switch (c) {
                case 'a':
@@ -688,7 +686,6 @@ main(int argc, char **argv) {
                        }
                        FALLTHROUGH;
                case 'h':
-                       isc_mem_detach(&isc_g_mctx);
                        usage();
 
                default:
@@ -711,7 +708,6 @@ main(int argc, char **argv) {
        }
 
        if (isc_commandline_index + 1 < argc) {
-               isc_mem_detach(&isc_g_mctx);
                usage();
        }
        if (argv[isc_commandline_index] != NULL) {
@@ -752,9 +748,5 @@ cleanup:
                cfg_parser_destroy(&parser);
        }
 
-       if (isc_g_mctx != NULL) {
-               isc_mem_detach(&isc_g_mctx);
-       }
-
        return result == ISC_R_SUCCESS ? 0 : 1;
 }
index 7f90883c81c2249da97cab004c9e973b1e662da8..98a18ad78be7cfea2c9b31abd1522ed8521202db 100644 (file)
@@ -109,11 +109,6 @@ main(int argc, char **argv) {
        FILE *errout = stdout;
        char *endp;
 
-       /*
-        * Uncomment the following line if memory debugging is needed:
-        * isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
-        */
-
        outputstyle = &dns_master_style_full;
 
        isc_commandline_init(argc, argv);
@@ -518,7 +513,6 @@ main(int argc, char **argv) {
                usage();
        }
 
-       isc_mem_create("default", &isc_g_mctx);
        if (!quiet) {
                RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS);
        }
@@ -560,7 +554,6 @@ main(int argc, char **argv) {
                fprintf(errout, "OK\n");
        }
        destroy();
-       isc_mem_detach(&isc_g_mctx);
 
        return (result == ISC_R_SUCCESS) ? 0 : 1;
 }
index 2b75446f9ba8acfd3ea0b14a79c6f4d4e0ca0fce..89ff68f398c845da9df7cdc6180459a1f793b616 100644 (file)
@@ -145,7 +145,7 @@ main(int argc, char **argv) {
                        keyname = isc_commandline_argument;
                        break;
                case 'M':
-                       isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+                       isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        break;
 
                case 'm':
@@ -218,7 +218,6 @@ main(int argc, char **argv) {
        }
        algname = dst_hmac_algorithm_totext(alg);
 
-       isc_mem_create("default", &isc_g_mctx);
        isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
 
        generate_key(isc_g_mctx, alg, keysize, &key_txtbuffer);
@@ -282,7 +281,5 @@ options {\n\
                isc_mem_stats(isc_g_mctx, stderr);
        }
 
-       isc_mem_detach(&isc_g_mctx);
-
        return 0;
 }
index ed01c35c0392d1ab6a50daa3ef37074414491a7c..553a45eaf2d4b91dd7b2de1e7e536247f20f2ba4 100644 (file)
@@ -130,7 +130,7 @@ main(int argc, char **argv) {
                        }
                        break;
                case 'M':
-                       isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+                       isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        break;
                case 'm':
                        show_final_mem = true;
@@ -194,8 +194,6 @@ main(int argc, char **argv) {
        /* Use canonical algorithm name */
        algname = dst_hmac_algorithm_totext(alg);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        if (keyname == NULL) {
                const char *suffix = NULL;
 
@@ -278,7 +276,5 @@ nsupdate -k <keyfile>\n");
                isc_mem_stats(isc_g_mctx, stderr);
        }
 
-       isc_mem_detach(&isc_g_mctx);
-
        return 0;
 }
index 22882e289e4054c66f08de83708f9c773002b5c9..021aeb6deeb1657e6d590cf2721de0009399350c 100644 (file)
@@ -1599,8 +1599,8 @@ preparse_args(int argc, char **argv) {
                                }
                                break;
                        case 'm':
-                               isc_mem_debugging = ISC_MEM_DEBUGTRACE |
-                                                   ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE |
+                                               ISC_MEM_DEBUGRECORD);
                                break;
                        case '4':
                                if (ipv6only) {
index 41d7a3bd284143119d8fb635ddfe3344def82eb0..d4dec3f116b3c44c893358764f4dc8a28a26e485 100644 (file)
@@ -2960,8 +2960,8 @@ preparse_args(int argc, char **argv) {
                                break;
                        case 'm':
                                memdebugging = true;
-                               isc_mem_debugging = ISC_MEM_DEBUGTRACE |
-                                                   ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE |
+                                               ISC_MEM_DEBUGRECORD);
                                break;
                        case 'r':
                                /*
index 6df09b890ce0706f390d7601799542df7946afaa..2afcf7638df72332f6937e41456cb5a88b093f72 100644 (file)
@@ -577,15 +577,15 @@ pre_parse_args(int argc, char **argv) {
                        memdebugging = true;
                        if (strcasecmp("trace", isc_commandline_argument) == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        } else if (strcasecmp("record",
                                              isc_commandline_argument) == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        } else if (strcasecmp("usage",
                                              isc_commandline_argument) == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
 
index 5b92267bd41ef722497449a3557a41ddb92bf876..22d1852f622304726149985edabe52ce92371e30 100644 (file)
@@ -1052,11 +1052,8 @@ cleanup(void) {
                free_keytable(&new_key_tbl);
        }
        free_all_sets();
-       if (isc_g_mctx != NULL) {
-               if (print_mem_stats && verbose > 10) {
-                       isc_mem_stats(isc_g_mctx, stdout);
-               }
-               isc_mem_detach(&isc_g_mctx);
+       if (print_mem_stats && verbose > 10) {
+               isc_mem_stats(isc_g_mctx, stdout);
        }
 }
 
@@ -1075,8 +1072,6 @@ main(int argc, char *argv[]) {
 
        isc_commandline_init(argc, argv);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
 #define OPTIONS "a:c:Dd:f:i:ms:T:uv:V"
@@ -1112,8 +1107,8 @@ main(int argc, char *argv[]) {
                        }
                        break;
                case 'm':
-                       isc_mem_debugging = ISC_MEM_DEBUGTRACE |
-                                           ISC_MEM_DEBUGRECORD;
+                       isc_mem_debugon(ISC_MEM_DEBUGTRACE |
+                                       ISC_MEM_DEBUGRECORD);
                        break;
                case 's':
                        startstr = isc_commandline_argument;
index cb4976cb5d644a8429643977693d5181ab23f5b0..0eaf67d50533e491bbb4162829ce6b5fd51ed256 100644 (file)
@@ -383,8 +383,6 @@ main(int argc, char **argv) {
 
        isc_commandline_init(argc, argv);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
 #define OPTIONS "12Aa:Cc:d:Ff:K:sT:v:whV"
@@ -547,7 +545,6 @@ main(int argc, char **argv) {
        if (verbose > 10) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        fflush(stdout);
        if (ferror(stdout)) {
index 6a1b3768dcf30a2e8aa74ee61213c5fde1fc721a..31f51c01ed693d10ac08ece6b6523d24a817a49a 100644 (file)
@@ -309,8 +309,6 @@ main(int argc, char **argv) {
 
        isc_commandline_init(argc, argv);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
 #define CMDLINE_FLAGS "D:f:hK:L:P:v:V"
@@ -454,7 +452,6 @@ main(int argc, char **argv) {
        if (verbose > 10) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        fflush(stdout);
        if (ferror(stdout)) {
index e4b3db66878ce42797f67ec03da5f2d7bd73c5ab..31a61b5bab3fd05ecf3640b57324a6893ee0b3d9 100644 (file)
@@ -149,8 +149,6 @@ main(int argc, char **argv) {
 
        isc_commandline_init(argc, argv);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
 #define CMDLINE_FLAGS "3A:a:Cc:D:E:Ff:GhI:i:kK:L:l:M:n:P:p:R:S:t:v:Vy"
@@ -699,7 +697,6 @@ main(int argc, char **argv) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
        isc_mem_free(isc_g_mctx, label);
-       isc_mem_detach(&isc_g_mctx);
 
        if (freeit != NULL) {
                free(freeit);
index 910e3c27239c596a13b52b780bf7fd5085a2ba45..d52df7ec646812e151599c780ea941341028eabe 100644 (file)
@@ -820,15 +820,15 @@ main(int argc, char **argv) {
                case 'm':
                        if (strcasecmp(isc_commandline_argument, "record") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        }
                        if (strcasecmp(isc_commandline_argument, "trace") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        }
                        if (strcasecmp(isc_commandline_argument, "usage") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
                default:
@@ -837,8 +837,6 @@ main(int argc, char **argv) {
        }
        isc_commandline_reset = true;
 
-       isc_mem_create("default", &isc_g_mctx);
-
        while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
                switch (ch) {
                case '3':
@@ -1209,7 +1207,6 @@ main(int argc, char **argv) {
        if (verbose > 10) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        if (freeit != NULL) {
                free(freeit);
index 55e8ca9e2590d4aa36ba9b9cc2d72e0510c67233..8c1b059232fa95fd8414fcea09ae9026c8029f55 100644 (file)
@@ -1330,8 +1330,6 @@ main(int argc, char *argv[]) {
 
        isc_commandline_init(argc, argv);
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
 #define OPTIONS "E:e:Ff:hi:K:k:l:ov:V"
index 7708b7b75964878860ab49b0f5e87575fba512d3..a105f88684254fdcfff69120d010e9be277ffc03 100644 (file)
@@ -81,8 +81,6 @@ main(int argc, char **argv) {
                usage();
        }
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
        while ((ch = isc_commandline_parse(argc, argv, "E:fK:rRhv:V")) != -1) {
@@ -251,7 +249,6 @@ cleanup:
        if (dir != NULL) {
                isc_mem_free(isc_g_mctx, dir);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        return 0;
 }
index 4a747fb0ad7bd92d88cf6a11ff4f53cf71528f75..312706e3142eeb722ea912705a3cde66ab3b483c 100644 (file)
@@ -243,8 +243,6 @@ main(int argc, char **argv) {
                usage();
        }
 
-       isc_mem_create("default", &isc_g_mctx);
-
        setup_logging();
 
        isc_commandline_errprint = false;
@@ -951,7 +949,6 @@ main(int argc, char **argv) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
        isc_mem_free(isc_g_mctx, directory);
-       isc_mem_detach(&isc_g_mctx);
 
        return 0;
 }
index b3325f9affd2e2c9236bd591b9ebaec543504815..ff0fd055cf0ad685608b841fdbdb09929214712c 100644 (file)
@@ -3297,15 +3297,15 @@ main(int argc, char *argv[]) {
                case 'm':
                        if (strcasecmp(isc_commandline_argument, "record") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        }
                        if (strcasecmp(isc_commandline_argument, "trace") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        }
                        if (strcasecmp(isc_commandline_argument, "usage") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
                default:
index 795226e5ea75a90b662175efbc1a41c538e9be2e..f0586f710e4dc203882c535043c0d0008fa0ec8f 100644 (file)
@@ -184,15 +184,15 @@ main(int argc, char *argv[]) {
                case 'm':
                        if (strcasecmp(isc_commandline_argument, "record") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        }
                        if (strcasecmp(isc_commandline_argument, "trace") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        }
                        if (strcasecmp(isc_commandline_argument, "usage") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
                default:
@@ -201,8 +201,6 @@ main(int argc, char *argv[]) {
        }
        isc_commandline_reset = true;
 
-       isc_mem_create("default", &isc_g_mctx);
-
        isc_commandline_errprint = false;
 
        while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
@@ -332,7 +330,6 @@ main(int argc, char *argv[]) {
        if (verbose > 10) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        return result == ISC_R_SUCCESS ? 0 : 1;
 }
index a12257f3b9f0363d3810ba0b532e40fc7e16445b..7a8482842953d7ac42ae4e0d6c685eb2179d72f0 100644 (file)
@@ -361,6 +361,8 @@ parse_int(char *arg, const char *desc) {
        return tmp;
 }
 
+static unsigned int mem_debugging = 0;
+
 static struct flag_def {
        const char *name;
        unsigned int value;
@@ -860,7 +862,8 @@ parse_command_line(int argc, char *argv[]) {
                        break;
                case 'm':
                        set_flags(isc_commandline_argument, mem_debug_flags,
-                                 &isc_mem_debugging);
+                                 &mem_debugging);
+                       isc_mem_debugon(mem_debugging);
                        break;
                case 'N': /* Deprecated. */
                case 'n':
index 8a6f00011e9a99a3f1056edfba2a699848548d07..771ec91cbe9d597e9b5ff42033a85366caf68144 100644 (file)
@@ -8918,7 +8918,7 @@ apply_configuration(cfg_parser_t *configparser, cfg_obj_t *config,
                named_g_memstatistics = cfg_obj_asboolean(obj);
        } else {
                named_g_memstatistics =
-                       ((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0);
+                       ((isc_mem_debugon(0) & ISC_MEM_DEBUGRECORD) != 0);
        }
 
        obj = NULL;
index 8d8d9a993fda1b2cb6268b913909d6203554d1b3..24990effda492db68c518f5fc7503122a6acc31e 100644 (file)
@@ -1002,8 +1002,8 @@ pre_parse_args(int argc, char **argv) {
                        debugging = true;
                        ddebugging = true;
                        memdebugging = true;
-                       isc_mem_debugging = ISC_MEM_DEBUGTRACE |
-                                           ISC_MEM_DEBUGRECORD;
+                       isc_mem_debugon(ISC_MEM_DEBUGTRACE |
+                                       ISC_MEM_DEBUGRECORD);
                        break;
 
                case '4':
index 74526f2663adf9e4ed3c4b10898531bdc47b256a..e60f96ce377539275104e7a4ce7bda4383d75a8b 100644 (file)
@@ -869,7 +869,7 @@ main(int argc, char **argv) {
                        break;
 
                case 'M':
-                       isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+                       isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        break;
 
                case 'm':
index a81efbbfb810cdbbde2b7ca48626f799976db140..af09f42b77074c2596c09cccb6206f50bf841c45 100644 (file)
@@ -104,8 +104,6 @@ main(int argc, char **argv) {
                exit(EXIT_FAILURE);
        }
 
-       isc_mem_create(argv[0], &isc_g_mctx);
-
        logconfig = isc_logconfig_get();
        isc_log_settag(logconfig, "bigkey");
 
@@ -137,7 +135,6 @@ main(int argc, char **argv) {
        printf("%s\n", filename);
        dst_key_free(&key);
 
-       isc_mem_detach(&isc_g_mctx);
        return 0;
 }
 
index 9225d23a5f86dd1f21794d43641fea0b8a475338..5e0f475cb4b7fe8f4eaf082ded2e73242be66eef 100644 (file)
@@ -120,15 +120,15 @@ main(int argc, char *argv[]) {
                case 'm':
                        if (strcasecmp(isc_commandline_argument, "record") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        }
                        if (strcasecmp(isc_commandline_argument, "trace") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE);
                        }
                        if (strcasecmp(isc_commandline_argument, "usage") == 0)
                        {
-                               isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
+                               isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
                        }
                        break;
                default:
@@ -137,8 +137,6 @@ main(int argc, char *argv[]) {
        }
        isc_commandline_reset = true;
 
-       isc_mem_create(argv[0], &isc_g_mctx);
-
        while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
                switch (ch) {
                case 'b':
@@ -258,7 +256,6 @@ main(int argc, char *argv[]) {
        if (printmemstats) {
                isc_mem_stats(isc_g_mctx, stdout);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        return 0;
 }
index 4d63fce4262f1ca10b35e195e41429fac3f23281..e226efa45b04b555a2cd6894d6e627e7c86e6007 100644 (file)
@@ -55,7 +55,6 @@
 
 #include "dnstap.pb-c.h"
 
-bool memrecord = false;
 bool printmessage = false;
 bool hexmessage = false;
 bool yaml = false;
@@ -347,8 +346,7 @@ main(int argc, char *argv[]) {
        while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) {
                switch (ch) {
                case 'm':
-                       isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
-                       memrecord = true;
+                       isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        break;
                case 'p':
                        printmessage = true;
@@ -375,8 +373,6 @@ main(int argc, char *argv[]) {
                fatal("no file specified");
        }
 
-       isc_mem_create("default", &isc_g_mctx);
-
        CHECKM(dns_dt_open(argv[0], dns_dtmode_file, isc_g_mctx, &handle),
               "dns_dt_openfile");
 
@@ -425,7 +421,6 @@ cleanup:
        if (message != NULL) {
                dns_message_detach(&message);
        }
-       isc_mem_detach(&isc_g_mctx);
 
        exit(rv);
 }
index 2f25279ba4f33731a11adff335513bd116661e8a..68a6beefeefa2dcc477f745d19f045ab5697bfc5 100644 (file)
@@ -1818,8 +1818,8 @@ preparse_args(int argc, char **argv) {
                while (strpbrk(option, single_dash_opts) == &option[0]) {
                        switch (option[0]) {
                        case 'm':
-                               isc_mem_debugging = ISC_MEM_DEBUGTRACE |
-                                                   ISC_MEM_DEBUGRECORD;
+                               isc_mem_debugon(ISC_MEM_DEBUGTRACE |
+                                               ISC_MEM_DEBUGRECORD);
                                break;
                        case '4':
                                if (ipv6only) {
index 56f2e2afff152af1a3b080e53e9a568058220a8b..0678b03f106802b3b1017f157067b2f540d86c77 100644 (file)
@@ -91,7 +91,6 @@ main(int argc, char **argv) {
        }
        file = argv[0];
 
-       isc_mem_create("default", &isc_g_mctx);
        setup_logging(stderr);
 
        if (upgrade) {
@@ -110,6 +109,6 @@ main(int argc, char **argv) {
                        fprintf(stderr, "%s\n", isc_result_totext(result));
                }
        }
-       isc_mem_detach(&isc_g_mctx);
+
        return result != ISC_R_SUCCESS ? 1 : 0;
 }
index 8ac42856d16cdbf9441f72e324500a4ba98a33c7..c18da012e28ad1b184ebbcd43015cdbb4ba5f9f5 100644 (file)
@@ -128,7 +128,7 @@ main(int argc, char **argv) {
                        usage(0);
                        break;
                case 'm':
-                       isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+                       isc_mem_debugon(ISC_MEM_DEBUGRECORD);
                        break;
                default:
                        usage(1);
@@ -151,8 +151,6 @@ main(int argc, char **argv) {
                journal = (const char *)jbuf;
        }
 
-       isc_mem_create("default", &isc_g_mctx);
-
        logconfig = isc_logconfig_get();
        isc_log_createandusechannel(
                logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
@@ -218,9 +216,5 @@ cleanup:
                dns_db_detach(&olddb);
        }
 
-       if (isc_g_mctx != NULL) {
-               isc_mem_detach(&isc_g_mctx);
-       }
-
        return (result != ISC_R_SUCCESS) ? 1 : 0;
 }
index ac12752aafa367e3b81667b17b063137f5a97721..99a0ba4dface5bef3d21453ac559aeec0411b45d 100644 (file)
@@ -59,9 +59,6 @@ cleanup(void) {
                isc_lex_close(lex);
                isc_lex_destroy(&lex);
        }
-       if (isc_g_mctx != NULL) {
-               isc_mem_detach(&isc_g_mctx);
-       }
 }
 
 ISC_NORETURN static void
@@ -169,7 +166,6 @@ main(int argc, char *argv[]) {
                exit(EXIT_SUCCESS);
        }
 
-       isc_mem_create("default", &isc_g_mctx);
        isc_lex_create(isc_g_mctx, 256, &lex);
 
        /*
index 186149d60eb32e52ae80aaf3ec2777dfc39bae83..9e4347794f7478ab3cfa8e6e4e3886e264ac0718 100644 (file)
@@ -253,6 +253,7 @@ isc__crypto_initialize(void) {
        uint64_t opts = OPENSSL_INIT_LOAD_CONFIG;
 
        isc_mem_create("OpenSSL", &isc__crypto_mctx);
+       isc_mem_setdebugging(isc__crypto_mctx, 0);
        isc_mem_setdestroycheck(isc__crypto_mctx, false);
 
 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L
index 8a4415df440f4f95d9e21d0f7d43358d360b3dc5..4792ed3d6bd7d1a09316157b6004615a1936214d 100644 (file)
@@ -35,7 +35,6 @@
 #define ISC_MEM_TRACKLINES 0
 #endif /* ifndef ISC_MEM_TRACKLINES */
 
-extern unsigned int isc_mem_debugging;
 extern unsigned int isc_mem_defaultflags;
 
 /*@{*/
@@ -45,14 +44,10 @@ extern unsigned int isc_mem_defaultflags;
 #define ISC_MEM_DEBUGALL \
        (ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGUSAGE)
 /*!<
- * The variable isc_mem_debugging holds a set of flags for
- * turning certain memory debugging options on or off at
- * runtime.  It is initialized to the value ISC_MEM_DEGBUGGING,
- * which is 0 by default but may be overridden at compile time.
- * The following flags can be specified:
+ * The following memory debugging options can be specified:
  *
  * \li #ISC_MEM_DEBUGTRACE
- *     Log each allocation and free to isc_lctx.
+ *     Log each allocation and free.
  *
  * \li #ISC_MEM_DEBUGRECORD
  *     Remember each allocation, and match them up on free.
@@ -61,6 +56,15 @@ extern unsigned int isc_mem_defaultflags;
  * \li #ISC_MEM_DEBUGUSAGE
  *     Every time the memory usage is greater (lower) than hi_water
  *     (lo_water) mark, print the current inuse memory.
+ *
+ * These flags are set in the static variable mem_debugging.
+ * When a new memory context is created, its debugging flags
+ * are set to the current value of mem_debugging.
+ *
+ * By default, no flags are set. This can be overridden by changing
+ * ISC_MEM_DEBUGGING in mem.c. The flags can be activated at runtime by
+ * setting environment variables (for example, "ISC_MEM_DEBUGRECORD=1")
+ * or by calling isc_mem_debugon() (see below).
  */
 /*@}*/
 
@@ -217,7 +221,6 @@ extern volatile void *isc__mem_malloc;
 #endif
 void
 isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG);
-
 /*!<
  * \brief Create a memory context.
  *
@@ -225,6 +228,33 @@ isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG);
  * mctxp != NULL && *mctxp == NULL */
 /*@}*/
 
+unsigned int
+isc_mem_debugon(unsigned int debugging);
+unsigned int
+isc_mem_debugoff(unsigned int debugging);
+/*!<
+ * Set or clear debugging the flags for the main memory context
+ * (isc_g_mctx), and the default debugging flags for all memory
+ * contexts yet to be created (mem_debugging).
+ *
+ * Note: These are bitwise operations. To clear the existing flags
+ * before setting new ones, use isc_mem_debugoff(ISC_MEM_DEBUGALL).
+ *
+ * Returns:
+ * \li the previous value of the debugging flags
+ */
+
+void
+isc_mem_setdebugging(isc_mem_t *ctx, unsigned int debugging);
+/*!<
+ * Set the debugging flags for a single memory context.
+ *
+ * Note: This is an assignemnt, not a bitwise operation.
+ *
+ * Requires:
+ * \li 'ctx' valid memory context without active allocation.
+ */
+
 #if ISC_MEM_TRACE
 #define isc_mem_ref(ptr)   isc_mem__ref(ptr, __func__, __FILE__, __LINE__)
 #define isc_mem_unref(ptr) isc_mem__unref(ptr, __func__, __FILE__, __LINE__)
index 5aa98f684c40b2e354a86f74a833db3db782f572..d46054f4344932f453ec59b35e24a6bc34c40f07 100644 (file)
@@ -1552,6 +1552,7 @@ isc__log_initialize(void) {
        isc_mem_t *mctx = NULL;
 
        isc_mem_create("log", &mctx);
+       isc_mem_setdebugging(mctx, 0);
 
        isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx));
        *isc__lctx = (isc_log_t){
index 55020fdecf06b2b0afdf635891df2435c8c20616..a01a8bac7dc7a794674648e0122fc47e751b2e75 100644 (file)
@@ -19,7 +19,6 @@
 
 void
 isc_managers_create(uint32_t workers) {
-       isc_mem_create("default", &isc_g_mctx);
        isc_loopmgr_create(isc_g_mctx, workers);
        isc_netmgr_create(isc_g_mctx);
        isc_rwlock_setworkers(workers);
@@ -32,5 +31,4 @@ isc_managers_destroy(void) {
         */
        isc_netmgr_destroy();
        isc_loopmgr_destroy();
-       isc_mem_detach(&isc_g_mctx);
 }
index b424b3faeb3de8641f48a386532d5d76d745df5e..f9e807f12b460aa38f17721d6efbb60380fecb7d 100644 (file)
@@ -35,6 +35,7 @@
 #include <isc/types.h>
 #include <isc/urcu.h>
 #include <isc/util.h>
+#include <isc/uv.h>
 
 #ifdef HAVE_LIBXML2
 #include <libxml/xmlwriter.h>
@@ -64,7 +65,8 @@
 #ifndef ISC_MEM_DEBUGGING
 #define ISC_MEM_DEBUGGING 0
 #endif /* ifndef ISC_MEM_DEBUGGING */
-unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING;
+
+static unsigned int mem_debugging = ISC_MEM_DEBUGGING;
 unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT;
 
 volatile void *isc__mem_malloc = mallocx;
@@ -384,6 +386,23 @@ mem_putstats(isc_mem_t *ctx, size_t size) {
  * Private.
  */
 
+static bool
+debugging_enabled(const char *name) {
+       char env_buf[256];
+       size_t env_size = sizeof(env_buf);
+
+       int r = uv_os_getenv(name, env_buf, &env_size);
+       switch (r) {
+       case 0:
+               return true;
+       case UV_ENOENT:
+               return false;
+       default:
+               UV_RUNTIME_CHECK(uv_os_getenv, r);
+               UNREACHABLE();
+       }
+}
+
 void
 isc__mem_initialize(void) {
 /*
@@ -395,6 +414,20 @@ isc__mem_initialize(void) {
 
        isc_mutex_init(&contextslock);
        ISC_LIST_INIT(contexts);
+
+       if (debugging_enabled("ISC_MEM_DEBUGTRACE")) {
+               mem_debugging |= ISC_MEM_DEBUGTRACE;
+       }
+
+       if (debugging_enabled("ISC_MEM_DEBUGRECORD")) {
+               mem_debugging |= ISC_MEM_DEBUGRECORD;
+       }
+
+       if (debugging_enabled("ISC_MEM_DEBUGUSAGE")) {
+               mem_debugging |= ISC_MEM_DEBUGUSAGE;
+       }
+
+       isc_mem_create("default", &isc_g_mctx);
 }
 
 void
@@ -403,6 +436,8 @@ isc__mem_shutdown(void) {
 
        rcu_barrier();
 
+       isc_mem_detach(&isc_g_mctx);
+
        isc__mem_checkdestroyed();
 
        LOCK(&contextslock);
@@ -414,6 +449,40 @@ isc__mem_shutdown(void) {
        }
 }
 
+void
+isc_mem_setdebugging(isc_mem_t *ctx, unsigned int debugging) {
+       REQUIRE(VALID_CONTEXT(ctx));
+       REQUIRE(isc_mem_inuse(ctx) == 0);
+
+       ctx->debugging = debugging;
+}
+
+unsigned int
+isc_mem_debugon(unsigned int debugging) {
+       unsigned int old_mem_debugging = mem_debugging;
+
+       if (debugging != 0) {
+               mem_debugging |= debugging;
+
+               isc_mem_setdebugging(isc_g_mctx, mem_debugging);
+       }
+
+       return old_mem_debugging;
+}
+
+unsigned int
+isc_mem_debugoff(unsigned int debugging) {
+       unsigned int old_mem_debugging = mem_debugging;
+
+       if (debugging != 0) {
+               mem_debugging &= ~debugging;
+
+               isc_mem_setdebugging(isc_g_mctx, mem_debugging);
+       }
+
+       return old_mem_debugging;
+}
+
 static void
 mem_create(const char *name, isc_mem_t **ctxp, unsigned int debugging,
           unsigned int flags, unsigned int jemalloc_flags) {
@@ -845,7 +914,7 @@ isc_mem_isovermem(isc_mem_t *ctx) {
                        return false;
                }
 
-               if ((isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) {
+               if ((ctx->debugging & ISC_MEM_DEBUGUSAGE) != 0) {
                        fprintf(stderr,
                                "overmem %s mctx %p inuse %zu hi_water %zu\n",
                                ctx->name, ctx, inuse, hiwater);
@@ -865,7 +934,7 @@ isc_mem_isovermem(isc_mem_t *ctx) {
                        return true;
                }
 
-               if ((isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) {
+               if ((ctx->debugging & ISC_MEM_DEBUGUSAGE) != 0) {
                        fprintf(stderr,
                                "overmem %s mctx %p inuse %zu lo_water %zu\n",
                                ctx->name, ctx, inuse, lowater);
@@ -1158,7 +1227,7 @@ isc__mem_checkdestroyed(void) {
        LOCK(&contextslock);
        if (!ISC_LIST_EMPTY(contexts)) {
 #if ISC_MEM_TRACKLINES
-               if ((isc_mem_debugging & TRACE_OR_RECORD) != 0) {
+               if ((mem_debugging & TRACE_OR_RECORD) != 0) {
                        print_contexts(file);
                }
 #endif /* if ISC_MEM_TRACKLINES */
@@ -1378,9 +1447,9 @@ error:
 
 void
 isc__mem_create(const char *name, isc_mem_t **mctxp FLARG) {
-       mem_create(name, mctxp, isc_mem_debugging, isc_mem_defaultflags, 0);
+       mem_create(name, mctxp, mem_debugging, isc_mem_defaultflags, 0);
 #if ISC_MEM_TRACKLINES
-       if ((isc_mem_debugging & ISC_MEM_DEBUGTRACE) != 0) {
+       if ((mem_debugging & ISC_MEM_DEBUGTRACE) != 0) {
                fprintf(stderr, "create mctx %p func %s file %s line %u\n",
                        *mctxp, func, file, line);
        }
index 8bc0e94ad48b9bb911e7a9106d7123454e1f716c..5841a467fea6116f0e2da2a870bcfe954a85c7ba 100644 (file)
@@ -48,7 +48,7 @@ static struct call_rcu_data *isc__thread_call_rcu_data = NULL;
 
 /*
  * We can't use isc_mem API here, because it's called too early and the
- * isc_mem_debugging flags can be changed later causing mismatch between flags
+ * memory debugging flags can be changed later causing mismatch between flags
  * used for isc_mem_get() and isc_mem_put().
  */
 
index 59330e2d407feeb1af326cacc7714df7df86e122..f0dcd51212dbc880f95c750c7e9a55be6a49c3ae 100644 (file)
@@ -133,6 +133,7 @@ isc__uv_initialize(void) {
 #if UV_VERSION_HEX >= UV_VERSION(1, 38, 0)
        int r;
        isc_mem_create("uv", &isc__uv_mctx);
+       isc_mem_setdebugging(isc__uv_mctx, 0);
        isc_mem_setdestroycheck(isc__uv_mctx, false);
 
        r = uv_replace_allocator(isc__uv_malloc, isc__uv_realloc,
index 664a6e8fe8120e7e07a3fd71cd850b6f7f79f8a0..2bfd0e9457528a55c1167bd9100b0171f5b94c81 100644 (file)
@@ -53,6 +53,7 @@ isc__xml_initialize(void) {
 #ifdef HAVE_LIBXML2
 #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS
        isc_mem_create("libxml2", &isc__xml_mctx);
+       isc_mem_setdebugging(isc__xml_mctx, 0);
        isc_mem_setdestroycheck(isc__xml_mctx, false);
 
        RUNTIME_CHECK(xmlMemSetup(isc__xml_free, isc__xml_malloc,
index 59b8759c4d575a869de8f87d266751f1b29ec9f4..14ac709098006c1aa437a324bfd1ff158cdcee0f 100644 (file)
@@ -42,9 +42,6 @@ main(void) {
        isc_result_t result;
        isc_buffer_t buf;
 
-       isc_mem_t *mctx = NULL;
-       isc_mem_create("test", &mctx);
-
        static dns_fixedname_t fixedname[65536];
        unsigned int count = 0;
 
@@ -76,14 +73,14 @@ main(void) {
                dns_compress_t cctx;
 
                isc_buffer_init(&buf, wire, sizeof(wire));
-               dns_compress_init(&cctx, mctx, 0);
+               dns_compress_init(&cctx, isc_g_mctx, 0);
 
                for (unsigned int i = 0; i < count; i++) {
                        dns_name_t *name = dns_fixedname_name(&fixedname[i]);
                        result = dns_name_towire(name, &cctx, &buf);
                        if (result == ISC_R_NOSPACE) {
                                dns_compress_invalidate(&cctx);
-                               dns_compress_init(&cctx, mctx, 0);
+                               dns_compress_init(&cctx, isc_g_mctx, 0);
                                isc_buffer_init(&buf, wire, sizeof(wire));
                        } else {
                                CHECKRESULT(result, "dns_name_towire");
@@ -100,7 +97,5 @@ main(void) {
 
        printf("names %u\n", count);
 
-       isc_mem_detach(&mctx);
-
        return 0;
 }
index fcf9ddf6cf274ed876df41e33cb51a58683d5a53..210f13ec9569a42c4d2714e282fefbe466b1ab2e 100644 (file)
@@ -422,8 +422,6 @@ main(int argc, char *argv[]) {
 
        isc_rwlock_init(&rwl);
 
-       isc_mem_create("test", &isc_g_mctx);
-
        if (argc != 2) {
                fprintf(stderr,
                        "usage: load-names <filename.csv> <nthreads>\n");
@@ -493,18 +491,16 @@ main(int argc, char *argv[]) {
                       "---------- | ---------- | ---------- |\n");
 
                for (struct fun *fun = fun_list; fun->name != NULL; fun++) {
-                       isc_mem_t *mem = NULL;
                        void *map = NULL;
 
-                       isc_mem_create("test", &mem);
-                       map = fun->new(mem);
+                       map = fun->new(isc_g_mctx);
 
                        size_t nitems = lines / (nthreads + 1);
 
                        isc_barrier_init(&barrier, nthreads);
 
                        isc_time_t t0 = isc_time_now_hires();
-                       size_t m0 = isc_mem_inuse(mem);
+                       size_t m0 = isc_mem_inuse(isc_g_mctx);
 
                        for (size_t i = 0; i < nthreads; i++) {
                                threads[i] = (struct thread_s){
@@ -526,13 +522,13 @@ main(int argc, char *argv[]) {
                                d1 += threads[i].d1;
                        }
 
-                       size_t m1 = isc_mem_inuse(mem);
+                       size_t m1 = isc_mem_inuse(isc_g_mctx);
 
                        rcu_barrier();
 
                        isc_time_t t1 = isc_time_now_hires();
                        uint64_t d3 = isc_time_microdiff(&t1, &t0);
-                       size_t m2 = isc_mem_inuse(mem);
+                       size_t m2 = isc_mem_inuse(isc_g_mctx);
 
                        printf("%10s | %10zu | %10.4f | %10.4f | %10.4f | "
                               "%10.4f | %10.4f |\n",
index 1ed80fad1054ce3593ff5ef82356f94f0fd4a173..7d362ec52927a52d7284547741bb0adc5e38a851 100644 (file)
@@ -162,8 +162,6 @@ main(int argc, char *argv[]) {
                exit(EXIT_SUCCESS);
        }
 
-       isc_mem_create("test", &isc_g_mctx);
-
        filename = argv[0];
        result = isc_file_getsize(filename, &fileoff);
        if (result != ISC_R_SUCCESS) {
index 966fabf6295ef0f13cdbca3c06bcd1d4d739092a..1c142c123b35c052a6d792b21808eac36cb61fc9 100644 (file)
@@ -197,8 +197,6 @@ main(int argc, char **argv) {
                usage();
        }
 
-       isc_mem_create("test", &isc_g_mctx);
-
        dns_qp_create(isc_g_mctx, &methods, NULL, &qp);
 
        start = isc_time_monotonic();
index cf7243204b3551674dddd0adc7d9b27e23b38503..fb5f38c96111f07c2db3e6aebddfbd8a7e8544bb 100644 (file)
@@ -854,8 +854,6 @@ setup_tickers(isc_mem_t *mctx) {
 
 int
 main(void) {
-       isc_mem_t *mctx = NULL;
-
        setlinebuf(stdout);
 
        uint32_t nloops;
@@ -868,20 +866,18 @@ main(void) {
        }
        INSIST(nloops > 1);
 
-       isc_mem_create("test", &mctx);
-       isc_mem_setdestroycheck(mctx, true);
+       isc_mem_setdestroycheck(isc_g_mctx, true);
        init_logging();
-       init_items(mctx);
+       init_items(isc_g_mctx);
 
-       isc_loopmgr_create(mctx, nloops);
-       setup_tickers(mctx);
+       isc_loopmgr_create(isc_g_mctx, nloops);
+       setup_tickers(isc_g_mctx);
        isc_loop_setup(isc_loop_main(), startup, NULL);
        isc_loopmgr_run();
        isc_loopmgr_destroy();
 
-       isc_mem_free(mctx, item);
+       isc_mem_free(isc_g_mctx, item);
        isc_mem_checkdestroyed(stdout);
-       isc_mem_detach(&mctx);
 
        return 0;
 }
index 13d73dfc4e96e89b775a96a157ee9ae686b734b5..a19a8ee9649d2f3e5734538eae56abc02190565a 100644 (file)
@@ -182,7 +182,6 @@ ISC_RUN_TEST_IMPL(isc_mem_inuse) {
        ssize_t diff;
        void *ptr;
 
-       mctx = NULL;
        isc_mem_create("test", &mctx);
 
        before = isc_mem_inuse(mctx);
@@ -334,18 +333,19 @@ ISC_RUN_TEST_IMPL(isc_mem_noflags) {
        char buf[4096], *p;
        FILE *f;
        void *ptr;
+       unsigned int debugging;
 
        result = isc_stdio_open("mem.output", "w", &f);
        assert_int_equal(result, ISC_R_SUCCESS);
 
-       isc_mem_debugging = 0;
+       debugging = isc_mem_debugoff(ISC_MEM_DEBUGALL);
        isc_mem_create("test", &mctx);
        ptr = isc_mem_get(mctx, 2048);
        assert_non_null(ptr);
        isc__mem_printactive(mctx, f);
        isc_mem_put(mctx, ptr, 2048);
        isc_mem_detach(&mctx);
-       isc_mem_debugging = ISC_MEM_DEBUGRECORD;
+       isc_mem_debugon(debugging);
        isc_stdio_close(f);
 
        memset(buf, 0, sizeof(buf));
@@ -354,7 +354,7 @@ ISC_RUN_TEST_IMPL(isc_mem_noflags) {
        result = isc_stdio_read(buf, sizeof(buf), 1, f, NULL);
        assert_int_equal(result, ISC_R_EOF);
        isc_stdio_close(f);
-       isc_file_remove("mem.output");
+       // isc_file_remove("mem.output");
 
        buf[sizeof(buf) - 1] = 0;
 
@@ -433,19 +433,22 @@ ISC_RUN_TEST_IMPL(isc_mem_traceflag) {
        char buf[4096], *p;
        FILE *f;
        void *ptr;
+       unsigned int debugging;
 
        /* redirect stderr so we can check trace output */
        f = freopen("mem.output", "w", stderr);
        assert_non_null(f);
 
-       isc_mem_debugging = ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGTRACE;
+       debugging = isc_mem_debugoff(ISC_MEM_DEBUGALL);
+       isc_mem_debugon(ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGTRACE);
        isc_mem_create("test", &mctx);
        ptr = isc_mem_get(mctx, 2048);
        assert_non_null(ptr);
        isc__mem_printactive(mctx, f);
        isc_mem_put(mctx, ptr, 2048);
        isc_mem_detach(&mctx);
-       isc_mem_debugging = ISC_MEM_DEBUGRECORD;
+       isc_mem_debugoff(ISC_MEM_DEBUGALL);
+       isc_mem_debugon(debugging);
        isc_stdio_close(f);
 
        memset(buf, 0, sizeof(buf));
index 5ababa92ac85f23e226b7534ca126049abc6b650..5b6334a64d3192f3bdf63ef22d28cd49ed507f71 100644 (file)
@@ -67,16 +67,13 @@ setup_workers(void **state ISC_ATTR_UNUSED) {
 
 int
 setup_mctx(void **state ISC_ATTR_UNUSED) {
-       isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
-       isc_mem_create("test", &isc_g_mctx);
+       isc_mem_debugon(ISC_MEM_DEBUGRECORD);
 
        return 0;
 }
 
 int
 teardown_mctx(void **state ISC_ATTR_UNUSED) {
-       isc_mem_detach(&isc_g_mctx);
-
        return 0;
 }