2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

Change the 'isc_g_mctx' to be always available

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.
This commit is contained in:
Ondřej Surý 2025-07-24 08:06:04 +02:00
parent 74726b3313
commit f7e5c1db38
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
44 changed files with 180 additions and 169 deletions

View File

@ -106,10 +106,6 @@ add(char *key, int value) {
isc_result_t result; isc_result_t result;
isc_symvalue_t symvalue; isc_symvalue_t symvalue;
if (isc_g_mctx == NULL) {
isc_mem_create("check-tool", &isc_g_mctx);
}
if (symtab == NULL) { if (symtab == NULL) {
isc_symtab_create(isc_g_mctx, freekey, isc_g_mctx, false, isc_symtab_create(isc_g_mctx, freekey, isc_g_mctx, false,
&symtab); &symtab);

View File

@ -599,15 +599,15 @@ main(int argc, char **argv) {
case 'm': case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0) 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) 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) if (strcasecmp(isc_commandline_argument, "usage") == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;
default: default:
@ -616,8 +616,6 @@ main(int argc, char **argv) {
} }
isc_commandline_reset = true; isc_commandline_reset = true;
isc_mem_create("default", &isc_g_mctx);
while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) { while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
switch (c) { switch (c) {
case 'a': case 'a':
@ -688,7 +686,6 @@ main(int argc, char **argv) {
} }
FALLTHROUGH; FALLTHROUGH;
case 'h': case 'h':
isc_mem_detach(&isc_g_mctx);
usage(); usage();
default: default:
@ -711,7 +708,6 @@ main(int argc, char **argv) {
} }
if (isc_commandline_index + 1 < argc) { if (isc_commandline_index + 1 < argc) {
isc_mem_detach(&isc_g_mctx);
usage(); usage();
} }
if (argv[isc_commandline_index] != NULL) { if (argv[isc_commandline_index] != NULL) {
@ -752,9 +748,5 @@ cleanup:
cfg_parser_destroy(&parser); cfg_parser_destroy(&parser);
} }
if (isc_g_mctx != NULL) {
isc_mem_detach(&isc_g_mctx);
}
return result == ISC_R_SUCCESS ? 0 : 1; return result == ISC_R_SUCCESS ? 0 : 1;
} }

View File

@ -109,11 +109,6 @@ main(int argc, char **argv) {
FILE *errout = stdout; FILE *errout = stdout;
char *endp; char *endp;
/*
* Uncomment the following line if memory debugging is needed:
* isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
*/
outputstyle = &dns_master_style_full; outputstyle = &dns_master_style_full;
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
@ -518,7 +513,6 @@ main(int argc, char **argv) {
usage(); usage();
} }
isc_mem_create("default", &isc_g_mctx);
if (!quiet) { if (!quiet) {
RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS); RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS);
} }
@ -560,7 +554,6 @@ main(int argc, char **argv) {
fprintf(errout, "OK\n"); fprintf(errout, "OK\n");
} }
destroy(); destroy();
isc_mem_detach(&isc_g_mctx);
return (result == ISC_R_SUCCESS) ? 0 : 1; return (result == ISC_R_SUCCESS) ? 0 : 1;
} }

View File

@ -145,7 +145,7 @@ main(int argc, char **argv) {
keyname = isc_commandline_argument; keyname = isc_commandline_argument;
break; break;
case 'M': case 'M':
isc_mem_debugging = ISC_MEM_DEBUGTRACE; isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break; break;
case 'm': case 'm':
@ -218,7 +218,6 @@ main(int argc, char **argv) {
} }
algname = dst_hmac_algorithm_totext(alg); algname = dst_hmac_algorithm_totext(alg);
isc_mem_create("default", &isc_g_mctx);
isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret)); isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
generate_key(isc_g_mctx, alg, keysize, &key_txtbuffer); generate_key(isc_g_mctx, alg, keysize, &key_txtbuffer);
@ -282,7 +281,5 @@ options {\n\
isc_mem_stats(isc_g_mctx, stderr); isc_mem_stats(isc_g_mctx, stderr);
} }
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -130,7 +130,7 @@ main(int argc, char **argv) {
} }
break; break;
case 'M': case 'M':
isc_mem_debugging = ISC_MEM_DEBUGTRACE; isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break; break;
case 'm': case 'm':
show_final_mem = true; show_final_mem = true;
@ -194,8 +194,6 @@ main(int argc, char **argv) {
/* Use canonical algorithm name */ /* Use canonical algorithm name */
algname = dst_hmac_algorithm_totext(alg); algname = dst_hmac_algorithm_totext(alg);
isc_mem_create("default", &isc_g_mctx);
if (keyname == NULL) { if (keyname == NULL) {
const char *suffix = NULL; const char *suffix = NULL;
@ -278,7 +276,5 @@ nsupdate -k <keyfile>\n");
isc_mem_stats(isc_g_mctx, stderr); isc_mem_stats(isc_g_mctx, stderr);
} }
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -1599,8 +1599,8 @@ preparse_args(int argc, char **argv) {
} }
break; break;
case 'm': case 'm':
isc_mem_debugging = ISC_MEM_DEBUGTRACE | isc_mem_debugon(ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD; ISC_MEM_DEBUGRECORD);
break; break;
case '4': case '4':
if (ipv6only) { if (ipv6only) {

View File

@ -2960,8 +2960,8 @@ preparse_args(int argc, char **argv) {
break; break;
case 'm': case 'm':
memdebugging = true; memdebugging = true;
isc_mem_debugging = ISC_MEM_DEBUGTRACE | isc_mem_debugon(ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD; ISC_MEM_DEBUGRECORD);
break; break;
case 'r': case 'r':
/* /*

View File

@ -577,15 +577,15 @@ pre_parse_args(int argc, char **argv) {
memdebugging = true; memdebugging = true;
if (strcasecmp("trace", isc_commandline_argument) == 0) if (strcasecmp("trace", isc_commandline_argument) == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGTRACE; isc_mem_debugon(ISC_MEM_DEBUGTRACE);
} else if (strcasecmp("record", } else if (strcasecmp("record",
isc_commandline_argument) == 0) isc_commandline_argument) == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; isc_mem_debugon(ISC_MEM_DEBUGRECORD);
} else if (strcasecmp("usage", } else if (strcasecmp("usage",
isc_commandline_argument) == 0) isc_commandline_argument) == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;

View File

@ -1052,11 +1052,8 @@ cleanup(void) {
free_keytable(&new_key_tbl); free_keytable(&new_key_tbl);
} }
free_all_sets(); free_all_sets();
if (isc_g_mctx != NULL) { if (print_mem_stats && verbose > 10) {
if (print_mem_stats && verbose > 10) { isc_mem_stats(isc_g_mctx, stdout);
isc_mem_stats(isc_g_mctx, stdout);
}
isc_mem_detach(&isc_g_mctx);
} }
} }
@ -1075,8 +1072,6 @@ main(int argc, char *argv[]) {
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
#define OPTIONS "a:c:Dd:f:i:ms:T:uv:V" #define OPTIONS "a:c:Dd:f:i:ms:T:uv:V"
@ -1112,8 +1107,8 @@ main(int argc, char *argv[]) {
} }
break; break;
case 'm': case 'm':
isc_mem_debugging = ISC_MEM_DEBUGTRACE | isc_mem_debugon(ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD; ISC_MEM_DEBUGRECORD);
break; break;
case 's': case 's':
startstr = isc_commandline_argument; startstr = isc_commandline_argument;

View File

@ -383,8 +383,6 @@ main(int argc, char **argv) {
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
#define OPTIONS "12Aa:Cc:d:Ff:K:sT:v:whV" #define OPTIONS "12Aa:Cc:d:Ff:K:sT:v:whV"
@ -547,7 +545,6 @@ main(int argc, char **argv) {
if (verbose > 10) { if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_detach(&isc_g_mctx);
fflush(stdout); fflush(stdout);
if (ferror(stdout)) { if (ferror(stdout)) {

View File

@ -309,8 +309,6 @@ main(int argc, char **argv) {
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
#define CMDLINE_FLAGS "D:f:hK:L:P:v:V" #define CMDLINE_FLAGS "D:f:hK:L:P:v:V"
@ -454,7 +452,6 @@ main(int argc, char **argv) {
if (verbose > 10) { if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_detach(&isc_g_mctx);
fflush(stdout); fflush(stdout);
if (ferror(stdout)) { if (ferror(stdout)) {

View File

@ -149,8 +149,6 @@ main(int argc, char **argv) {
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; 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" #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_stats(isc_g_mctx, stdout);
} }
isc_mem_free(isc_g_mctx, label); isc_mem_free(isc_g_mctx, label);
isc_mem_detach(&isc_g_mctx);
if (freeit != NULL) { if (freeit != NULL) {
free(freeit); free(freeit);

View File

@ -820,15 +820,15 @@ main(int argc, char **argv) {
case 'm': case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0) 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) 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) if (strcasecmp(isc_commandline_argument, "usage") == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;
default: default:
@ -837,8 +837,6 @@ main(int argc, char **argv) {
} }
isc_commandline_reset = true; isc_commandline_reset = true;
isc_mem_create("default", &isc_g_mctx);
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) { switch (ch) {
case '3': case '3':
@ -1209,7 +1207,6 @@ main(int argc, char **argv) {
if (verbose > 10) { if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_detach(&isc_g_mctx);
if (freeit != NULL) { if (freeit != NULL) {
free(freeit); free(freeit);

View File

@ -1330,8 +1330,6 @@ main(int argc, char *argv[]) {
isc_commandline_init(argc, argv); isc_commandline_init(argc, argv);
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
#define OPTIONS "E:e:Ff:hi:K:k:l:ov:V" #define OPTIONS "E:e:Ff:hi:K:k:l:ov:V"

View File

@ -81,8 +81,6 @@ main(int argc, char **argv) {
usage(); usage();
} }
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
while ((ch = isc_commandline_parse(argc, argv, "E:fK:rRhv:V")) != -1) { while ((ch = isc_commandline_parse(argc, argv, "E:fK:rRhv:V")) != -1) {
@ -251,7 +249,6 @@ cleanup:
if (dir != NULL) { if (dir != NULL) {
isc_mem_free(isc_g_mctx, dir); isc_mem_free(isc_g_mctx, dir);
} }
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -243,8 +243,6 @@ main(int argc, char **argv) {
usage(); usage();
} }
isc_mem_create("default", &isc_g_mctx);
setup_logging(); setup_logging();
isc_commandline_errprint = false; isc_commandline_errprint = false;
@ -951,7 +949,6 @@ main(int argc, char **argv) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_free(isc_g_mctx, directory); isc_mem_free(isc_g_mctx, directory);
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -3297,15 +3297,15 @@ main(int argc, char *argv[]) {
case 'm': case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0) 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) 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) if (strcasecmp(isc_commandline_argument, "usage") == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;
default: default:

View File

@ -184,15 +184,15 @@ main(int argc, char *argv[]) {
case 'm': case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0) 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) 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) if (strcasecmp(isc_commandline_argument, "usage") == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;
default: default:
@ -201,8 +201,6 @@ main(int argc, char *argv[]) {
} }
isc_commandline_reset = true; isc_commandline_reset = true;
isc_mem_create("default", &isc_g_mctx);
isc_commandline_errprint = false; isc_commandline_errprint = false;
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
@ -332,7 +330,6 @@ main(int argc, char *argv[]) {
if (verbose > 10) { if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_detach(&isc_g_mctx);
return result == ISC_R_SUCCESS ? 0 : 1; return result == ISC_R_SUCCESS ? 0 : 1;
} }

View File

@ -361,6 +361,8 @@ parse_int(char *arg, const char *desc) {
return tmp; return tmp;
} }
static unsigned int mem_debugging = 0;
static struct flag_def { static struct flag_def {
const char *name; const char *name;
unsigned int value; unsigned int value;
@ -860,7 +862,8 @@ parse_command_line(int argc, char *argv[]) {
break; break;
case 'm': case 'm':
set_flags(isc_commandline_argument, mem_debug_flags, set_flags(isc_commandline_argument, mem_debug_flags,
&isc_mem_debugging); &mem_debugging);
isc_mem_debugon(mem_debugging);
break; break;
case 'N': /* Deprecated. */ case 'N': /* Deprecated. */
case 'n': case 'n':

View File

@ -8918,7 +8918,7 @@ apply_configuration(cfg_parser_t *configparser, cfg_obj_t *config,
named_g_memstatistics = cfg_obj_asboolean(obj); named_g_memstatistics = cfg_obj_asboolean(obj);
} else { } else {
named_g_memstatistics = named_g_memstatistics =
((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0); ((isc_mem_debugon(0) & ISC_MEM_DEBUGRECORD) != 0);
} }
obj = NULL; obj = NULL;

View File

@ -1002,8 +1002,8 @@ pre_parse_args(int argc, char **argv) {
debugging = true; debugging = true;
ddebugging = true; ddebugging = true;
memdebugging = true; memdebugging = true;
isc_mem_debugging = ISC_MEM_DEBUGTRACE | isc_mem_debugon(ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD; ISC_MEM_DEBUGRECORD);
break; break;
case '4': case '4':

View File

@ -869,7 +869,7 @@ main(int argc, char **argv) {
break; break;
case 'M': case 'M':
isc_mem_debugging = ISC_MEM_DEBUGTRACE; isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break; break;
case 'm': case 'm':

View File

@ -104,8 +104,6 @@ main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
isc_mem_create(argv[0], &isc_g_mctx);
logconfig = isc_logconfig_get(); logconfig = isc_logconfig_get();
isc_log_settag(logconfig, "bigkey"); isc_log_settag(logconfig, "bigkey");
@ -137,7 +135,6 @@ main(int argc, char **argv) {
printf("%s\n", filename); printf("%s\n", filename);
dst_key_free(&key); dst_key_free(&key);
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -120,15 +120,15 @@ main(int argc, char *argv[]) {
case 'm': case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0) 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) 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) if (strcasecmp(isc_commandline_argument, "usage") == 0)
{ {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE; isc_mem_debugon(ISC_MEM_DEBUGUSAGE);
} }
break; break;
default: default:
@ -137,8 +137,6 @@ main(int argc, char *argv[]) {
} }
isc_commandline_reset = true; isc_commandline_reset = true;
isc_mem_create(argv[0], &isc_g_mctx);
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) { switch (ch) {
case 'b': case 'b':
@ -258,7 +256,6 @@ main(int argc, char *argv[]) {
if (printmemstats) { if (printmemstats) {
isc_mem_stats(isc_g_mctx, stdout); isc_mem_stats(isc_g_mctx, stdout);
} }
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }

View File

@ -55,7 +55,6 @@
#include "dnstap.pb-c.h" #include "dnstap.pb-c.h"
bool memrecord = false;
bool printmessage = false; bool printmessage = false;
bool hexmessage = false; bool hexmessage = false;
bool yaml = false; bool yaml = false;
@ -347,8 +346,7 @@ main(int argc, char *argv[]) {
while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) { while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) {
switch (ch) { switch (ch) {
case 'm': case 'm':
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; isc_mem_debugon(ISC_MEM_DEBUGRECORD);
memrecord = true;
break; break;
case 'p': case 'p':
printmessage = true; printmessage = true;
@ -375,8 +373,6 @@ main(int argc, char *argv[]) {
fatal("no file specified"); fatal("no file specified");
} }
isc_mem_create("default", &isc_g_mctx);
CHECKM(dns_dt_open(argv[0], dns_dtmode_file, isc_g_mctx, &handle), CHECKM(dns_dt_open(argv[0], dns_dtmode_file, isc_g_mctx, &handle),
"dns_dt_openfile"); "dns_dt_openfile");
@ -425,7 +421,6 @@ cleanup:
if (message != NULL) { if (message != NULL) {
dns_message_detach(&message); dns_message_detach(&message);
} }
isc_mem_detach(&isc_g_mctx);
exit(rv); exit(rv);
} }

View File

@ -1818,8 +1818,8 @@ preparse_args(int argc, char **argv) {
while (strpbrk(option, single_dash_opts) == &option[0]) { while (strpbrk(option, single_dash_opts) == &option[0]) {
switch (option[0]) { switch (option[0]) {
case 'm': case 'm':
isc_mem_debugging = ISC_MEM_DEBUGTRACE | isc_mem_debugon(ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD; ISC_MEM_DEBUGRECORD);
break; break;
case '4': case '4':
if (ipv6only) { if (ipv6only) {

View File

@ -91,7 +91,6 @@ main(int argc, char **argv) {
} }
file = argv[0]; file = argv[0];
isc_mem_create("default", &isc_g_mctx);
setup_logging(stderr); setup_logging(stderr);
if (upgrade) { if (upgrade) {
@ -110,6 +109,6 @@ main(int argc, char **argv) {
fprintf(stderr, "%s\n", isc_result_totext(result)); fprintf(stderr, "%s\n", isc_result_totext(result));
} }
} }
isc_mem_detach(&isc_g_mctx);
return result != ISC_R_SUCCESS ? 1 : 0; return result != ISC_R_SUCCESS ? 1 : 0;
} }

View File

@ -128,7 +128,7 @@ main(int argc, char **argv) {
usage(0); usage(0);
break; break;
case 'm': case 'm':
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; isc_mem_debugon(ISC_MEM_DEBUGRECORD);
break; break;
default: default:
usage(1); usage(1);
@ -151,8 +151,6 @@ main(int argc, char **argv) {
journal = (const char *)jbuf; journal = (const char *)jbuf;
} }
isc_mem_create("default", &isc_g_mctx);
logconfig = isc_logconfig_get(); logconfig = isc_logconfig_get();
isc_log_createandusechannel( isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC, logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
@ -218,9 +216,5 @@ cleanup:
dns_db_detach(&olddb); dns_db_detach(&olddb);
} }
if (isc_g_mctx != NULL) {
isc_mem_detach(&isc_g_mctx);
}
return (result != ISC_R_SUCCESS) ? 1 : 0; return (result != ISC_R_SUCCESS) ? 1 : 0;
} }

View File

@ -59,9 +59,6 @@ cleanup(void) {
isc_lex_close(lex); isc_lex_close(lex);
isc_lex_destroy(&lex); isc_lex_destroy(&lex);
} }
if (isc_g_mctx != NULL) {
isc_mem_detach(&isc_g_mctx);
}
} }
ISC_NORETURN static void ISC_NORETURN static void
@ -169,7 +166,6 @@ main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
isc_mem_create("default", &isc_g_mctx);
isc_lex_create(isc_g_mctx, 256, &lex); isc_lex_create(isc_g_mctx, 256, &lex);
/* /*

View File

@ -253,6 +253,7 @@ isc__crypto_initialize(void) {
uint64_t opts = OPENSSL_INIT_LOAD_CONFIG; uint64_t opts = OPENSSL_INIT_LOAD_CONFIG;
isc_mem_create("OpenSSL", &isc__crypto_mctx); isc_mem_create("OpenSSL", &isc__crypto_mctx);
isc_mem_setdebugging(isc__crypto_mctx, 0);
isc_mem_setdestroycheck(isc__crypto_mctx, false); isc_mem_setdestroycheck(isc__crypto_mctx, false);
#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L

View File

@ -35,7 +35,6 @@
#define ISC_MEM_TRACKLINES 0 #define ISC_MEM_TRACKLINES 0
#endif /* ifndef ISC_MEM_TRACKLINES */ #endif /* ifndef ISC_MEM_TRACKLINES */
extern unsigned int isc_mem_debugging;
extern unsigned int isc_mem_defaultflags; extern unsigned int isc_mem_defaultflags;
/*@{*/ /*@{*/
@ -45,14 +44,10 @@ extern unsigned int isc_mem_defaultflags;
#define ISC_MEM_DEBUGALL \ #define ISC_MEM_DEBUGALL \
(ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGUSAGE) (ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD | ISC_MEM_DEBUGUSAGE)
/*!< /*!<
* The variable isc_mem_debugging holds a set of flags for * The following memory debugging options can be specified:
* 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:
* *
* \li #ISC_MEM_DEBUGTRACE * \li #ISC_MEM_DEBUGTRACE
* Log each allocation and free to isc_lctx. * Log each allocation and free.
* *
* \li #ISC_MEM_DEBUGRECORD * \li #ISC_MEM_DEBUGRECORD
* Remember each allocation, and match them up on free. * Remember each allocation, and match them up on free.
@ -61,6 +56,15 @@ extern unsigned int isc_mem_defaultflags;
* \li #ISC_MEM_DEBUGUSAGE * \li #ISC_MEM_DEBUGUSAGE
* Every time the memory usage is greater (lower) than hi_water * Every time the memory usage is greater (lower) than hi_water
* (lo_water) mark, print the current inuse memory. * (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 #endif
void void
isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG); isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG);
/*!< /*!<
* \brief Create a memory context. * \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 */ * 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 #if ISC_MEM_TRACE
#define isc_mem_ref(ptr) isc_mem__ref(ptr, __func__, __FILE__, __LINE__) #define isc_mem_ref(ptr) isc_mem__ref(ptr, __func__, __FILE__, __LINE__)
#define isc_mem_unref(ptr) isc_mem__unref(ptr, __func__, __FILE__, __LINE__) #define isc_mem_unref(ptr) isc_mem__unref(ptr, __func__, __FILE__, __LINE__)

View File

@ -1552,6 +1552,7 @@ isc__log_initialize(void) {
isc_mem_t *mctx = NULL; isc_mem_t *mctx = NULL;
isc_mem_create("log", &mctx); isc_mem_create("log", &mctx);
isc_mem_setdebugging(mctx, 0);
isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx)); isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx));
*isc__lctx = (isc_log_t){ *isc__lctx = (isc_log_t){

View File

@ -19,7 +19,6 @@
void void
isc_managers_create(uint32_t workers) { isc_managers_create(uint32_t workers) {
isc_mem_create("default", &isc_g_mctx);
isc_loopmgr_create(isc_g_mctx, workers); isc_loopmgr_create(isc_g_mctx, workers);
isc_netmgr_create(isc_g_mctx); isc_netmgr_create(isc_g_mctx);
isc_rwlock_setworkers(workers); isc_rwlock_setworkers(workers);
@ -32,5 +31,4 @@ isc_managers_destroy(void) {
*/ */
isc_netmgr_destroy(); isc_netmgr_destroy();
isc_loopmgr_destroy(); isc_loopmgr_destroy();
isc_mem_detach(&isc_g_mctx);
} }

View File

@ -35,6 +35,7 @@
#include <isc/types.h> #include <isc/types.h>
#include <isc/urcu.h> #include <isc/urcu.h>
#include <isc/util.h> #include <isc/util.h>
#include <isc/uv.h>
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
#include <libxml/xmlwriter.h> #include <libxml/xmlwriter.h>
@ -64,7 +65,8 @@
#ifndef ISC_MEM_DEBUGGING #ifndef ISC_MEM_DEBUGGING
#define ISC_MEM_DEBUGGING 0 #define ISC_MEM_DEBUGGING 0
#endif /* ifndef ISC_MEM_DEBUGGING */ #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; unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT;
volatile void *isc__mem_malloc = mallocx; volatile void *isc__mem_malloc = mallocx;
@ -384,6 +386,23 @@ mem_putstats(isc_mem_t *ctx, size_t size) {
* Private. * 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 void
isc__mem_initialize(void) { isc__mem_initialize(void) {
/* /*
@ -395,6 +414,20 @@ isc__mem_initialize(void) {
isc_mutex_init(&contextslock); isc_mutex_init(&contextslock);
ISC_LIST_INIT(contexts); 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 void
@ -403,6 +436,8 @@ isc__mem_shutdown(void) {
rcu_barrier(); rcu_barrier();
isc_mem_detach(&isc_g_mctx);
isc__mem_checkdestroyed(); isc__mem_checkdestroyed();
LOCK(&contextslock); 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 static void
mem_create(const char *name, isc_mem_t **ctxp, unsigned int debugging, mem_create(const char *name, isc_mem_t **ctxp, unsigned int debugging,
unsigned int flags, unsigned int jemalloc_flags) { unsigned int flags, unsigned int jemalloc_flags) {
@ -845,7 +914,7 @@ isc_mem_isovermem(isc_mem_t *ctx) {
return false; return false;
} }
if ((isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) { if ((ctx->debugging & ISC_MEM_DEBUGUSAGE) != 0) {
fprintf(stderr, fprintf(stderr,
"overmem %s mctx %p inuse %zu hi_water %zu\n", "overmem %s mctx %p inuse %zu hi_water %zu\n",
ctx->name, ctx, inuse, hiwater); ctx->name, ctx, inuse, hiwater);
@ -865,7 +934,7 @@ isc_mem_isovermem(isc_mem_t *ctx) {
return true; return true;
} }
if ((isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) { if ((ctx->debugging & ISC_MEM_DEBUGUSAGE) != 0) {
fprintf(stderr, fprintf(stderr,
"overmem %s mctx %p inuse %zu lo_water %zu\n", "overmem %s mctx %p inuse %zu lo_water %zu\n",
ctx->name, ctx, inuse, lowater); ctx->name, ctx, inuse, lowater);
@ -1158,7 +1227,7 @@ isc__mem_checkdestroyed(void) {
LOCK(&contextslock); LOCK(&contextslock);
if (!ISC_LIST_EMPTY(contexts)) { if (!ISC_LIST_EMPTY(contexts)) {
#if ISC_MEM_TRACKLINES #if ISC_MEM_TRACKLINES
if ((isc_mem_debugging & TRACE_OR_RECORD) != 0) { if ((mem_debugging & TRACE_OR_RECORD) != 0) {
print_contexts(file); print_contexts(file);
} }
#endif /* if ISC_MEM_TRACKLINES */ #endif /* if ISC_MEM_TRACKLINES */
@ -1378,9 +1447,9 @@ error:
void void
isc__mem_create(const char *name, isc_mem_t **mctxp FLARG) { 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_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", fprintf(stderr, "create mctx %p func %s file %s line %u\n",
*mctxp, func, file, line); *mctxp, func, file, line);
} }

View 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 * 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(). * used for isc_mem_get() and isc_mem_put().
*/ */

View File

@ -133,6 +133,7 @@ isc__uv_initialize(void) {
#if UV_VERSION_HEX >= UV_VERSION(1, 38, 0) #if UV_VERSION_HEX >= UV_VERSION(1, 38, 0)
int r; int r;
isc_mem_create("uv", &isc__uv_mctx); isc_mem_create("uv", &isc__uv_mctx);
isc_mem_setdebugging(isc__uv_mctx, 0);
isc_mem_setdestroycheck(isc__uv_mctx, false); isc_mem_setdestroycheck(isc__uv_mctx, false);
r = uv_replace_allocator(isc__uv_malloc, isc__uv_realloc, r = uv_replace_allocator(isc__uv_malloc, isc__uv_realloc,

View File

@ -53,6 +53,7 @@ isc__xml_initialize(void) {
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
#ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS
isc_mem_create("libxml2", &isc__xml_mctx); isc_mem_create("libxml2", &isc__xml_mctx);
isc_mem_setdebugging(isc__xml_mctx, 0);
isc_mem_setdestroycheck(isc__xml_mctx, false); isc_mem_setdestroycheck(isc__xml_mctx, false);
RUNTIME_CHECK(xmlMemSetup(isc__xml_free, isc__xml_malloc, RUNTIME_CHECK(xmlMemSetup(isc__xml_free, isc__xml_malloc,

View File

@ -42,9 +42,6 @@ main(void) {
isc_result_t result; isc_result_t result;
isc_buffer_t buf; isc_buffer_t buf;
isc_mem_t *mctx = NULL;
isc_mem_create("test", &mctx);
static dns_fixedname_t fixedname[65536]; static dns_fixedname_t fixedname[65536];
unsigned int count = 0; unsigned int count = 0;
@ -76,14 +73,14 @@ main(void) {
dns_compress_t cctx; dns_compress_t cctx;
isc_buffer_init(&buf, wire, sizeof(wire)); 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++) { for (unsigned int i = 0; i < count; i++) {
dns_name_t *name = dns_fixedname_name(&fixedname[i]); dns_name_t *name = dns_fixedname_name(&fixedname[i]);
result = dns_name_towire(name, &cctx, &buf); result = dns_name_towire(name, &cctx, &buf);
if (result == ISC_R_NOSPACE) { if (result == ISC_R_NOSPACE) {
dns_compress_invalidate(&cctx); 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)); isc_buffer_init(&buf, wire, sizeof(wire));
} else { } else {
CHECKRESULT(result, "dns_name_towire"); CHECKRESULT(result, "dns_name_towire");
@ -100,7 +97,5 @@ main(void) {
printf("names %u\n", count); printf("names %u\n", count);
isc_mem_detach(&mctx);
return 0; return 0;
} }

View File

@ -422,8 +422,6 @@ main(int argc, char *argv[]) {
isc_rwlock_init(&rwl); isc_rwlock_init(&rwl);
isc_mem_create("test", &isc_g_mctx);
if (argc != 2) { if (argc != 2) {
fprintf(stderr, fprintf(stderr,
"usage: load-names <filename.csv> <nthreads>\n"); "usage: load-names <filename.csv> <nthreads>\n");
@ -493,18 +491,16 @@ main(int argc, char *argv[]) {
"---------- | ---------- | ---------- |\n"); "---------- | ---------- | ---------- |\n");
for (struct fun *fun = fun_list; fun->name != NULL; fun++) { for (struct fun *fun = fun_list; fun->name != NULL; fun++) {
isc_mem_t *mem = NULL;
void *map = NULL; void *map = NULL;
isc_mem_create("test", &mem); map = fun->new(isc_g_mctx);
map = fun->new(mem);
size_t nitems = lines / (nthreads + 1); size_t nitems = lines / (nthreads + 1);
isc_barrier_init(&barrier, nthreads); isc_barrier_init(&barrier, nthreads);
isc_time_t t0 = isc_time_now_hires(); 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++) { for (size_t i = 0; i < nthreads; i++) {
threads[i] = (struct thread_s){ threads[i] = (struct thread_s){
@ -526,13 +522,13 @@ main(int argc, char *argv[]) {
d1 += threads[i].d1; d1 += threads[i].d1;
} }
size_t m1 = isc_mem_inuse(mem); size_t m1 = isc_mem_inuse(isc_g_mctx);
rcu_barrier(); rcu_barrier();
isc_time_t t1 = isc_time_now_hires(); isc_time_t t1 = isc_time_now_hires();
uint64_t d3 = isc_time_microdiff(&t1, &t0); 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 | " printf("%10s | %10zu | %10.4f | %10.4f | %10.4f | "
"%10.4f | %10.4f |\n", "%10.4f | %10.4f |\n",

View File

@ -162,8 +162,6 @@ main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
isc_mem_create("test", &isc_g_mctx);
filename = argv[0]; filename = argv[0];
result = isc_file_getsize(filename, &fileoff); result = isc_file_getsize(filename, &fileoff);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {

View File

@ -197,8 +197,6 @@ main(int argc, char **argv) {
usage(); usage();
} }
isc_mem_create("test", &isc_g_mctx);
dns_qp_create(isc_g_mctx, &methods, NULL, &qp); dns_qp_create(isc_g_mctx, &methods, NULL, &qp);
start = isc_time_monotonic(); start = isc_time_monotonic();

View File

@ -854,8 +854,6 @@ setup_tickers(isc_mem_t *mctx) {
int int
main(void) { main(void) {
isc_mem_t *mctx = NULL;
setlinebuf(stdout); setlinebuf(stdout);
uint32_t nloops; uint32_t nloops;
@ -868,20 +866,18 @@ main(void) {
} }
INSIST(nloops > 1); INSIST(nloops > 1);
isc_mem_create("test", &mctx); isc_mem_setdestroycheck(isc_g_mctx, true);
isc_mem_setdestroycheck(mctx, true);
init_logging(); init_logging();
init_items(mctx); init_items(isc_g_mctx);
isc_loopmgr_create(mctx, nloops); isc_loopmgr_create(isc_g_mctx, nloops);
setup_tickers(mctx); setup_tickers(isc_g_mctx);
isc_loop_setup(isc_loop_main(), startup, NULL); isc_loop_setup(isc_loop_main(), startup, NULL);
isc_loopmgr_run(); isc_loopmgr_run();
isc_loopmgr_destroy(); isc_loopmgr_destroy();
isc_mem_free(mctx, item); isc_mem_free(isc_g_mctx, item);
isc_mem_checkdestroyed(stdout); isc_mem_checkdestroyed(stdout);
isc_mem_detach(&mctx);
return 0; return 0;
} }

View File

@ -182,7 +182,6 @@ ISC_RUN_TEST_IMPL(isc_mem_inuse) {
ssize_t diff; ssize_t diff;
void *ptr; void *ptr;
mctx = NULL;
isc_mem_create("test", &mctx); isc_mem_create("test", &mctx);
before = isc_mem_inuse(mctx); before = isc_mem_inuse(mctx);
@ -334,18 +333,19 @@ ISC_RUN_TEST_IMPL(isc_mem_noflags) {
char buf[4096], *p; char buf[4096], *p;
FILE *f; FILE *f;
void *ptr; void *ptr;
unsigned int debugging;
result = isc_stdio_open("mem.output", "w", &f); result = isc_stdio_open("mem.output", "w", &f);
assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_debugging = 0; debugging = isc_mem_debugoff(ISC_MEM_DEBUGALL);
isc_mem_create("test", &mctx); isc_mem_create("test", &mctx);
ptr = isc_mem_get(mctx, 2048); ptr = isc_mem_get(mctx, 2048);
assert_non_null(ptr); assert_non_null(ptr);
isc__mem_printactive(mctx, f); isc__mem_printactive(mctx, f);
isc_mem_put(mctx, ptr, 2048); isc_mem_put(mctx, ptr, 2048);
isc_mem_detach(&mctx); isc_mem_detach(&mctx);
isc_mem_debugging = ISC_MEM_DEBUGRECORD; isc_mem_debugon(debugging);
isc_stdio_close(f); isc_stdio_close(f);
memset(buf, 0, sizeof(buf)); 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); result = isc_stdio_read(buf, sizeof(buf), 1, f, NULL);
assert_int_equal(result, ISC_R_EOF); assert_int_equal(result, ISC_R_EOF);
isc_stdio_close(f); isc_stdio_close(f);
isc_file_remove("mem.output"); // isc_file_remove("mem.output");
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
@ -433,19 +433,22 @@ ISC_RUN_TEST_IMPL(isc_mem_traceflag) {
char buf[4096], *p; char buf[4096], *p;
FILE *f; FILE *f;
void *ptr; void *ptr;
unsigned int debugging;
/* redirect stderr so we can check trace output */ /* redirect stderr so we can check trace output */
f = freopen("mem.output", "w", stderr); f = freopen("mem.output", "w", stderr);
assert_non_null(f); 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); isc_mem_create("test", &mctx);
ptr = isc_mem_get(mctx, 2048); ptr = isc_mem_get(mctx, 2048);
assert_non_null(ptr); assert_non_null(ptr);
isc__mem_printactive(mctx, f); isc__mem_printactive(mctx, f);
isc_mem_put(mctx, ptr, 2048); isc_mem_put(mctx, ptr, 2048);
isc_mem_detach(&mctx); isc_mem_detach(&mctx);
isc_mem_debugging = ISC_MEM_DEBUGRECORD; isc_mem_debugoff(ISC_MEM_DEBUGALL);
isc_mem_debugon(debugging);
isc_stdio_close(f); isc_stdio_close(f);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));

View File

@ -67,16 +67,13 @@ setup_workers(void **state ISC_ATTR_UNUSED) {
int int
setup_mctx(void **state ISC_ATTR_UNUSED) { setup_mctx(void **state ISC_ATTR_UNUSED) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD; isc_mem_debugon(ISC_MEM_DEBUGRECORD);
isc_mem_create("test", &isc_g_mctx);
return 0; return 0;
} }
int int
teardown_mctx(void **state ISC_ATTR_UNUSED) { teardown_mctx(void **state ISC_ATTR_UNUSED) {
isc_mem_detach(&isc_g_mctx);
return 0; return 0;
} }