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.
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);
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:
}
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':
}
FALLTHROUGH;
case 'h':
- isc_mem_detach(&isc_g_mctx);
usage();
default:
}
if (isc_commandline_index + 1 < argc) {
- isc_mem_detach(&isc_g_mctx);
usage();
}
if (argv[isc_commandline_index] != NULL) {
cfg_parser_destroy(&parser);
}
- if (isc_g_mctx != NULL) {
- isc_mem_detach(&isc_g_mctx);
- }
-
return result == ISC_R_SUCCESS ? 0 : 1;
}
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);
usage();
}
- isc_mem_create("default", &isc_g_mctx);
if (!quiet) {
RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS);
}
fprintf(errout, "OK\n");
}
destroy();
- isc_mem_detach(&isc_g_mctx);
return (result == ISC_R_SUCCESS) ? 0 : 1;
}
keyname = isc_commandline_argument;
break;
case 'M':
- isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+ isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break;
case 'm':
}
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);
isc_mem_stats(isc_g_mctx, stderr);
}
- isc_mem_detach(&isc_g_mctx);
-
return 0;
}
}
break;
case 'M':
- isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+ isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break;
case 'm':
show_final_mem = true;
/* Use canonical algorithm name */
algname = dst_hmac_algorithm_totext(alg);
- isc_mem_create("default", &isc_g_mctx);
-
if (keyname == NULL) {
const char *suffix = NULL;
isc_mem_stats(isc_g_mctx, stderr);
}
- isc_mem_detach(&isc_g_mctx);
-
return 0;
}
}
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) {
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':
/*
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;
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);
}
}
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"
}
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;
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"
if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout);
}
- isc_mem_detach(&isc_g_mctx);
fflush(stdout);
if (ferror(stdout)) {
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"
if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout);
}
- isc_mem_detach(&isc_g_mctx);
fflush(stdout);
if (ferror(stdout)) {
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"
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);
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:
}
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':
if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout);
}
- isc_mem_detach(&isc_g_mctx);
if (freeit != NULL) {
free(freeit);
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"
usage();
}
- isc_mem_create("default", &isc_g_mctx);
-
isc_commandline_errprint = false;
while ((ch = isc_commandline_parse(argc, argv, "E:fK:rRhv:V")) != -1) {
if (dir != NULL) {
isc_mem_free(isc_g_mctx, dir);
}
- isc_mem_detach(&isc_g_mctx);
return 0;
}
usage();
}
- isc_mem_create("default", &isc_g_mctx);
-
setup_logging();
isc_commandline_errprint = false;
isc_mem_stats(isc_g_mctx, stdout);
}
isc_mem_free(isc_g_mctx, directory);
- isc_mem_detach(&isc_g_mctx);
return 0;
}
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:
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:
}
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) {
if (verbose > 10) {
isc_mem_stats(isc_g_mctx, stdout);
}
- isc_mem_detach(&isc_g_mctx);
return result == ISC_R_SUCCESS ? 0 : 1;
}
return tmp;
}
+static unsigned int mem_debugging = 0;
+
static struct flag_def {
const char *name;
unsigned int value;
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':
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;
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':
break;
case 'M':
- isc_mem_debugging = ISC_MEM_DEBUGTRACE;
+ isc_mem_debugon(ISC_MEM_DEBUGTRACE);
break;
case 'm':
exit(EXIT_FAILURE);
}
- isc_mem_create(argv[0], &isc_g_mctx);
-
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, "bigkey");
printf("%s\n", filename);
dst_key_free(&key);
- isc_mem_detach(&isc_g_mctx);
return 0;
}
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:
}
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':
if (printmemstats) {
isc_mem_stats(isc_g_mctx, stdout);
}
- isc_mem_detach(&isc_g_mctx);
return 0;
}
#include "dnstap.pb-c.h"
-bool memrecord = false;
bool printmessage = false;
bool hexmessage = false;
bool yaml = false;
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;
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");
if (message != NULL) {
dns_message_detach(&message);
}
- isc_mem_detach(&isc_g_mctx);
exit(rv);
}
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) {
}
file = argv[0];
- isc_mem_create("default", &isc_g_mctx);
setup_logging(stderr);
if (upgrade) {
fprintf(stderr, "%s\n", isc_result_totext(result));
}
}
- isc_mem_detach(&isc_g_mctx);
+
return result != ISC_R_SUCCESS ? 1 : 0;
}
usage(0);
break;
case 'm':
- isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
+ isc_mem_debugon(ISC_MEM_DEBUGRECORD);
break;
default:
usage(1);
journal = (const char *)jbuf;
}
- isc_mem_create("default", &isc_g_mctx);
-
logconfig = isc_logconfig_get();
isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
dns_db_detach(&olddb);
}
- if (isc_g_mctx != NULL) {
- isc_mem_detach(&isc_g_mctx);
- }
-
return (result != ISC_R_SUCCESS) ? 1 : 0;
}
isc_lex_close(lex);
isc_lex_destroy(&lex);
}
- if (isc_g_mctx != NULL) {
- isc_mem_detach(&isc_g_mctx);
- }
}
ISC_NORETURN static void
exit(EXIT_SUCCESS);
}
- isc_mem_create("default", &isc_g_mctx);
isc_lex_create(isc_g_mctx, 256, &lex);
/*
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
#define ISC_MEM_TRACKLINES 0
#endif /* ifndef ISC_MEM_TRACKLINES */
-extern unsigned int isc_mem_debugging;
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.
* \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).
*/
/*@}*/
#endif
void
isc__mem_create(const char *name, isc_mem_t **_ISC_MEM_FLARG);
-
/*!<
* \brief Create a memory context.
*
* 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__)
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){
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);
*/
isc_netmgr_destroy();
isc_loopmgr_destroy();
- isc_mem_detach(&isc_g_mctx);
}
#include <isc/types.h>
#include <isc/urcu.h>
#include <isc/util.h>
+#include <isc/uv.h>
#ifdef HAVE_LIBXML2
#include <libxml/xmlwriter.h>
#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;
* 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) {
/*
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
rcu_barrier();
+ isc_mem_detach(&isc_g_mctx);
+
isc__mem_checkdestroyed();
LOCK(&contextslock);
}
}
+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) {
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);
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);
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 */
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);
}
/*
* 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().
*/
#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,
#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,
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;
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");
printf("names %u\n", count);
- isc_mem_detach(&mctx);
-
return 0;
}
isc_rwlock_init(&rwl);
- isc_mem_create("test", &isc_g_mctx);
-
if (argc != 2) {
fprintf(stderr,
"usage: load-names <filename.csv> <nthreads>\n");
"---------- | ---------- | ---------- |\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){
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",
exit(EXIT_SUCCESS);
}
- isc_mem_create("test", &isc_g_mctx);
-
filename = argv[0];
result = isc_file_getsize(filename, &fileoff);
if (result != ISC_R_SUCCESS) {
usage();
}
- isc_mem_create("test", &isc_g_mctx);
-
dns_qp_create(isc_g_mctx, &methods, NULL, &qp);
start = isc_time_monotonic();
int
main(void) {
- isc_mem_t *mctx = NULL;
-
setlinebuf(stdout);
uint32_t nloops;
}
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;
}
ssize_t diff;
void *ptr;
- mctx = NULL;
isc_mem_create("test", &mctx);
before = isc_mem_inuse(mctx);
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));
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;
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));
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;
}