2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Merge branch 'ondrej/refactor-and-cleanup-isc_mem_create' into 'master'

Refactor and cleanup isc_mem_create()

See merge request isc-projects/bind9!2315
This commit is contained in:
Ondřej Surý 2019-09-12 03:50:22 -04:00
commit 30b6e93a70
93 changed files with 308 additions and 435 deletions

View File

@ -127,9 +127,7 @@ add(char *key, int value) {
isc_symvalue_t symvalue;
if (sym_mctx == NULL) {
result = isc_mem_create(0, 0, &sym_mctx);
if (result != ISC_R_SUCCESS)
return;
isc_mem_create(&sym_mctx);
}
if (symtab == NULL) {

View File

@ -585,7 +585,7 @@ main(int argc, char **argv) {
}
isc_commandline_reset = true;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
switch (c) {

View File

@ -517,7 +517,7 @@ main(int argc, char **argv) {
InitSockets();
#endif
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
if (!quiet)
RUNTIME_CHECK(setup_logging(mctx, errout, &lctx)
== ISC_R_SUCCESS);

View File

@ -207,7 +207,7 @@ main(int argc, char **argv) {
/* Use canonical algorithm name */
algname = alg_totext(alg);
DO("create memory context", isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
if (keyname == NULL) {
const char *suffix = NULL;

View File

@ -209,7 +209,7 @@ main(int argc, char **argv) {
keysize = alg_bits(alg);
algname = alg_totext(alg);
DO("create memory context", isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
generate_key(mctx, alg, keysize, &key_txtbuffer);

View File

@ -1642,9 +1642,7 @@ main(int argc, char *argv[]) {
if (result != ISC_R_SUCCESS)
fatal("dns_lib_init failed: %d", result);
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("failed to create mctx");
isc_mem_create(&mctx);
CHECK(isc_appctx_create(mctx, &actx));
CHECK(isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr));

View File

@ -1365,8 +1365,7 @@ setup_libs(void) {
if (!have_ipv6 && !have_ipv4)
fatal("can't find either v4 or v6 networking");
result = isc_mem_create(0, 0, &mctx);
check_result(result, "isc_mem_create");
isc_mem_create(&mctx);
isc_mem_setname(mctx, "dig", NULL);
result = isc_log_create(mctx, &lctx, &logconfig);

View File

@ -1074,10 +1074,7 @@ main(int argc, char *argv[]) {
int ch;
char *endp;
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
fatal("out of memory");
}
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -350,10 +350,7 @@ main(int argc, char **argv) {
usage();
}
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
fatal("out of memory");
}
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -300,9 +300,7 @@ main(int argc, char **argv) {
if (argc == 1)
usage();
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("out of memory");
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -163,7 +163,7 @@ main(int argc, char **argv) {
if (argc == 1)
usage();
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -259,7 +259,7 @@ main(int argc, char **argv) {
}
isc_commandline_reset = true;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
isc_stdtime_get(&now);

View File

@ -88,9 +88,7 @@ main(int argc, char **argv) {
if (argc == 1)
usage();
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("Out of memory");
isc_mem_create(&mctx);
#if HAVE_PKCS11
pk11_result_register();

View File

@ -167,9 +167,7 @@ main(int argc, char **argv) {
if (argc == 1)
usage();
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("Out of memory");
isc_mem_create(&mctx);
setup_logging(mctx, &log);

View File

@ -3230,9 +3230,7 @@ main(int argc, char *argv[]) {
check_result(isc_app_start(), "isc_app_start");
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("out of memory");
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -209,9 +209,7 @@ main(int argc, char *argv[]) {
isc_commandline_reset = true;
check_result(isc_app_start(), "isc_app_start");
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("out of memory");
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();

View File

@ -1462,10 +1462,7 @@ main(int argc, char *argv[]) {
named_g_chrootdir);
}
result = isc_mem_create(0, 0, &named_g_mctx);
if (result != ISC_R_SUCCESS)
named_main_earlyfatal("isc_mem_create() failed: %s",
isc_result_totext(result));
isc_mem_create(&named_g_mctx);
isc_mem_setname(named_g_mctx, "main", NULL);
setup();

View File

@ -4349,9 +4349,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
* cache, for the main cache memory and the heap
* memory.
*/
CHECK(isc_mem_create(0, 0, &cmctx));
isc_mem_create(&cmctx);
isc_mem_setname(cmctx, "cache", NULL);
CHECK(isc_mem_create(0, 0, &hmctx));
isc_mem_create(&hmctx);
isc_mem_setname(hmctx, "cache_heap", NULL);
CHECK(dns_cache_create(cmctx, hmctx, named_g_taskmgr,
named_g_timermgr, view->rdclass,

View File

@ -225,9 +225,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_FAILURE);
}
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
return (result);
isc_mem_create(&mctx);
cd = isc_mem_get(mctx, sizeof(*cd));
memset(cd, 0, sizeof(*cd));

View File

@ -224,7 +224,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_FAILURE);
}
isc_mem_create(0, 0, &mctx);
isc_mem_create(&mctx);
cd = isc_mem_get(mctx, sizeof(*cd));
memset(cd, 0, sizeof(*cd));

View File

@ -3269,8 +3269,7 @@ main(int argc, char **argv) {
pre_parse_args(argc, argv);
result = isc_mem_create(0, 0, &gmctx);
check_result(result, "isc_mem_create");
isc_mem_create(&gmctx);
parse_args(argc, argv);

View File

@ -65,10 +65,7 @@ main(int argc, char *argv[]) {
exit(1);
}
if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) {
fprintf(stderr, "isc_mem_create() failed\n");
exit(1);
}
isc_mem_create(&mctx);
pk11_result_register();

View File

@ -930,7 +930,7 @@ main(int argc, char **argv) {
serial = isc_random32();
DO("create memory context", isc_mem_create(0, 0, &rndc_mctx));
isc_mem_create(&rndc_mctx);
DO("create socket manager", isc_socketmgr_create(rndc_mctx, &socketmgr));
DO("create task manager", isc_taskmgr_create(rndc_mctx, 1, 0, &taskmgr));
DO("create task", isc_task_create(taskmgr, 0, &task));

View File

@ -70,7 +70,7 @@ main(int argc, char **argv) {
unsigned int zonetype = 0;
unsigned int pflags = 0;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");

View File

@ -96,7 +96,7 @@ main(int argc, char **argv) {
journal = argv[4];
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
CHECK(dst_lib_init(mctx, NULL));
dst_active = true;

View File

@ -295,7 +295,7 @@ main(int argc, char **argv) {
/*
* EVERYTHING needs a memory context.
*/
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
cmp = NULL;
RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)

View File

@ -87,7 +87,7 @@ main(int argc, char *argv[]) {
dns_result_register();
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
while ((ch = isc_commandline_parse(argc, argv, "nvw:")) != -1) {
switch (ch) {

View File

@ -201,7 +201,7 @@ main(int argc, char *argv[]) {
dns_result_register();
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) {
switch (ch) {

View File

@ -362,7 +362,7 @@ main(int argc, char *argv[]) {
dns_result_register();
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(dns_dbtable_create(mctx, dns_rdataclass_in, &dbtable) ==
ISC_R_SUCCESS);

View File

@ -445,7 +445,7 @@ main(int argc, char *argv[]) {
dns_result_register();
mctx = NULL;
RUNCHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
RUNCHECK(isc_log_create(mctx, &lctx, &lcfg));
isc_log_setcontext(lctx);

View File

@ -30,7 +30,7 @@ main(int argc, char **argv) {
UNUSED(argc);
UNUSED(argv);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_interfaceiter_create(mctx, &iter);
if (result != ISC_R_SUCCESS)
goto cleanup;

View File

@ -90,7 +90,7 @@ main(int argc, char *argv[]) {
}
}
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_lex_create(mctx, 256, &lex) == ISC_R_SUCCESS);
if (masterfile) {

View File

@ -106,7 +106,7 @@ main(int argc, char **argv) {
lctx = NULL;
lcfg = NULL;
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
CHECK(isc_log_create(mctx, &lctx, &lcfg));
CHECK(isc_log_settag(lcfg, progname));

View File

@ -57,7 +57,7 @@ main(int argc, char *argv[]) {
UNUSED(argc);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
if (argv[1]) {
isc_buffer_init(&source, argv[1], strlen(argv[1]));

View File

@ -31,7 +31,7 @@ main(int argc, char *argv[]) {
isc_mutex_init(&lock);
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
mp1 = NULL;
RUNTIME_CHECK(isc_mempool_create(mctx, 24, &mp1) == ISC_R_SUCCESS);

View File

@ -186,12 +186,10 @@ nsecify(char *filename) {
int
main(int argc, char *argv[]) {
int i;
isc_result_t result;
dns_result_register();
result = isc_mem_create(0, 0, &mctx);
check_result(result, "isc_mem_create()");
isc_mem_create(&mctx);
argc--;
argv++;

View File

@ -101,7 +101,7 @@ main(int argc, char *argv[]) {
isc_app_start();
isc_interval_set(&linterval, 1, 0);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_taskmgr_create(mctx, 3, 0, &taskmgr) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) ==

View File

@ -277,12 +277,7 @@ main(int argc, char **argv) {
*/
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
printf("isc_mem_create: %s: exiting\n",
dns_result_totext(result));
exit(1);
}
isc_mem_create(&mctx);
result = dns_rbt_create(mctx, delete_name, NULL, &rbt);
if (result != ISC_R_SUCCESS) {

View File

@ -178,9 +178,9 @@ main(int argc, char *argv[]) {
printf("%u workers\n", workers);
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
mctx2 = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx2) == ISC_R_SUCCESS);
isc_mem_create(&mctx2);
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &task_manager) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_timermgr_create(mctx, &timer_manager) ==

View File

@ -207,7 +207,7 @@ main(int argc, char *argv[]) {
isc_mutex_init(&lock);
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
while ((ch = isc_commandline_parse(argc, argv, "vp:")) != -1) {
switch (ch) {

View File

@ -286,7 +286,7 @@ main(int argc, char *argv[]) {
* EVERYTHING needs a memory context.
*/
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
/*
* The task manager is independent (other than memory context)

View File

@ -59,7 +59,7 @@ main(int argc, char *argv[]) {
}
}
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_symtab_create(mctx, 691, undefine_action, NULL,
case_sensitive, &st) == ISC_R_SUCCESS);

View File

@ -77,7 +77,7 @@ main(int argc, char *argv[]) {
workers = 2;
printf("%u workers\n", workers);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) ==
ISC_R_SUCCESS);

View File

@ -107,7 +107,7 @@ main(int argc, char *argv[]) {
workers = 2;
printf("%u workers\n", workers);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx1) == ISC_R_SUCCESS);
isc_mem_create(&mctx1);
RUNTIME_CHECK(isc_taskmgr_create(mctx1, workers, 0, &manager) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_timermgr_create(mctx1, &timgr) == ISC_R_SUCCESS);

View File

@ -280,7 +280,7 @@ main(int argc, char **argv) {
usage();
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_taskmgr_create(mctx, 2, 0, &taskmgr) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS);

View File

@ -268,7 +268,7 @@ main(int argc, char *argv[]) {
isc_sockaddr_fromin(&dstaddr, &inaddr, port);
mctx = NULL;
RUNCHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
lctx = NULL;
lcfg = NULL;

View File

@ -101,7 +101,7 @@ main(int argc, char **argv) {
dns_result_register();
CHECK(isc_mem_create(0, 0, &mctx), "isc_mem_create()");
isc_mem_create(&mctx);
CHECK(dst_lib_init(mctx, NULL), "dst_lib_init()");
CHECK(isc_log_create(mctx, &log_, &logconfig), "isc_log_create()");
isc_log_setcontext(log_);

View File

@ -227,7 +227,7 @@ main(int argc, char *argv[]) {
mctx = NULL;
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
RUNCHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
log = NULL;
logconfig = NULL;

View File

@ -166,7 +166,7 @@ main(int argc, char **argv) {
dns_result_register();
mctx = NULL;
RUNCHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
log = NULL;
logconfig = NULL;

View File

@ -132,7 +132,7 @@ main(int argc, char *argv[]) {
}
isc_commandline_reset = true;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {

View File

@ -342,7 +342,7 @@ main(int argc, char *argv[]) {
if (argc < 1)
fatal("no file specified");
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
dns_result_register();

View File

@ -2015,7 +2015,7 @@ main(int argc, char *argv[]) {
preparse_args(argc, argv);
mctx = NULL;
RUNCHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
lctx = NULL;
lcfg = NULL;

View File

@ -67,7 +67,7 @@ main(int argc, char **argv) {
file = argv[1];
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS);
result = dns_journal_print(mctx, file, stdout);

View File

@ -146,7 +146,7 @@ main(int argc, char *argv[]) {
if (doexit)
exit(0);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(isc_lex_create(mctx, 256, &lex) == ISC_R_SUCCESS);
/*

View File

@ -0,0 +1,95 @@
@@
statement S;
expression E;
@@
- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S;
+ isc_mem_create(E);
@@
statement S;
expression V, E;
@@
- V = isc_mem_create(0, 0, E);
- if (V == ISC_R_SUCCESS) S
+ isc_mem_create(E);
+ S
@@
statement S;
expression V, E;
@@
- V = isc_mem_create(0, 0, E);
- if (V != ISC_R_SUCCESS) S
+ isc_mem_create(E);
@@
expression V, E;
@@
- V = isc_mem_create(0, 0, E);
- check_result(V, ...);
+ isc_mem_create(E);
@@
statement S;
expression V, E, C;
@@
- if (C) { V = isc_mem_create(0, 0, E); }
- if (V != ISC_R_SUCCESS) S
+ if (C) { isc_mem_create(E); }
@@
expression E;
@@
- RUNTIME_CHECK(isc_mem_create(0, 0, E) == ISC_R_SUCCESS);
+ isc_mem_create(E);
@@
expression E;
@@
- RUNCHECK(isc_mem_create(0, 0, E));
+ isc_mem_create(E);
@@
expression E;
@@
- CHECK(isc_mem_create(0, 0, E), ...);
+ isc_mem_create(E);
@@
expression E;
@@
- CHECK(isc_mem_create(0, 0, E));
+ isc_mem_create(E);
@@
expression V, E;
@@
- V = isc_mem_create(0, 0, E);
- assert_int_equal(V, ISC_R_SUCCESS);
+ isc_mem_create(E);
@@
expression E;
statement S;
@@
- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S
+ isc_mem_create(E);
@@
expression E;
@@
- DO(..., isc_mem_create(0, 0, E));
+ isc_mem_create(E);

View File

@ -60,8 +60,7 @@ int ctx_init(void) {
goto done;
}
if (isc_mem_create(0, 0, &ctx.mem) != ISC_R_SUCCESS)
goto done;
isc_mem_create(&ctx.mem);
if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS)
goto done;
@ -337,6 +336,3 @@ struct DNSConf {
%readonly
dns_c_ctx_t *confctx;
};

View File

@ -668,11 +668,7 @@ open_lexer(void) {
return ISC_R_SUCCESS;
/* allocate memory for lexer, and verify it was allocated */
result = isc_mem_create(0, 0, &lex_mctx);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "unexpected error creating lexer\n");
return result;
}
isc_mem_create(&lex_mctx);
/* create lexer */
result = isc_lex_create(lex_mctx, 1500, &lexer);

View File

@ -282,8 +282,8 @@ rudimentary initialization of both.
isc_log_t *lctx;
isc_logconfig_t *lcfg;
if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
isc_mem_create(&mctx);
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
oops_it_didnt_work();
3) Initalize any additional libraries. The convention for the name of

View File

@ -504,7 +504,7 @@ memory has not been freed when BIND shuts down.
To create a basic memory context, use:
isc_mem_t *mctx = NULL;
result = isc_mem_create(0, 0, &mctx);
isc_mem_create(&mctx);
(The zeroes are tuning parameters, `max_size` and `target_size`: Any
allocations smaller than `max_size` will be satisfied by getting
@ -1069,9 +1069,10 @@ the following steps need to be taken to initialize it.
isc_log_t *lctx;
isc_logconfig_t *lcfg;
if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
isc_mem_create(&mctx);
if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) {
oops_it_didnt_work();
}
1. Initalize any additional libraries. The convention for the name of
the initialization function is `{library}_log_init()`, with a pointer to

View File

@ -98,7 +98,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
rdtype = typelist[(*data++) % types]; size--;
rdclass = classlist[(*data++) % classes]; size--;
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
CHECK(isc_lex_create(mctx, 64, &lex));
memset(specials, 0, sizeof(specials));

View File

@ -28,7 +28,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
static isc_mem_t *mctx = NULL;
static void __attribute__((constructor)) init(void) {
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_mem_create(&mctx);
RUNTIME_CHECK(dst_lib_init(mctx, NULL) == ISC_R_SUCCESS);
}

View File

@ -413,9 +413,7 @@ dns_client_create(dns_client_t **clientp, unsigned int options) {
unsigned int logdebuglevel = 0;
#endif
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
return (result);
isc_mem_create(&mctx);
result = isc_appctx_create(mctx, &actx);
if (result != ISC_R_SUCCESS)
goto cleanup;

View File

@ -164,10 +164,9 @@ dt_init(void) {
if (!dt_initialized) {
int ret;
if (dt_mctx == NULL)
result = isc_mem_create(0, 0, &dt_mctx);
if (result != ISC_R_SUCCESS)
goto unlock;
if (dt_mctx == NULL) {
isc_mem_create(&dt_mctx);
}
isc_mem_setname(dt_mctx, "dt", NULL);
isc_mem_setdestroycheck(dt_mctx, false);
@ -177,7 +176,6 @@ dt_init(void) {
else
result = ISC_R_FAILURE;
}
unlock:
UNLOCK(&dt_mutex);
return (result);

View File

@ -108,10 +108,7 @@ state_key_init(void) {
int ret;
if (state_mctx == NULL) {
result = isc_mem_create(0, 0, &state_mctx);
}
if (result != ISC_R_SUCCESS) {
goto unlock;
isc_mem_create(&state_mctx);
}
isc_mem_setname(state_mctx, "geoip_state", NULL);
isc_mem_setdestroycheck(state_mctx, false);
@ -123,7 +120,6 @@ state_key_init(void) {
result = ISC_R_FAILURE;
}
}
unlock:
UNLOCK(&key_mutex);
}

View File

@ -54,9 +54,7 @@ initialize(void) {
isc_refcount_init(&references, 0);
result = isc_mem_create(0, 0, &dns_g_mctx);
if (result != ISC_R_SUCCESS)
return;
isc_mem_create(&dns_g_mctx);
dns_result_register();
result = dns_ecdb_register(dns_g_mctx, &dbimp);
if (result != ISC_R_SUCCESS)

View File

@ -1299,10 +1299,9 @@ totext_filter_proc_key_init(void) {
if (!thread_key_initialized) {
LOCK(&thread_key_mutex);
if (thread_key_mctx == NULL)
result = isc_mem_create(0, 0, &thread_key_mctx);
if (result != ISC_R_SUCCESS)
goto unlock;
if (thread_key_mctx == NULL) {
isc_mem_create(&thread_key_mctx);
}
isc_mem_setname(thread_key_mctx, "threadkey", NULL);
isc_mem_setdestroycheck(thread_key_mctx, false);
@ -1311,9 +1310,9 @@ totext_filter_proc_key_init(void) {
free_specific) != 0) {
result = ISC_R_FAILURE;
isc_mem_detach(&thread_key_mctx);
} else
} else {
thread_key_initialized = 1;
unlock:
}
UNLOCK(&thread_key_mutex);
}
return (result);

View File

@ -9977,12 +9977,7 @@ dns_resolver_create(dns_view_t *view,
* contention among multiple threads. Do this only when
* enabling threads because it will be require more memory.
*/
result = isc_mem_create(0, 0, &res->buckets[i].mctx);
if (result != ISC_R_SUCCESS) {
isc_task_detach(&res->buckets[i].task);
isc_mutex_destroy(&res->buckets[i].lock);
goto cleanup_buckets;
}
isc_mem_create(&res->buckets[i].mctx);
isc_mem_setname(res->buckets[i].mctx, name, NULL);
isc_task_setname(res->buckets[i].task, name, res);
ISC_LIST_INIT(res->buckets[i].fctxs);

View File

@ -69,8 +69,7 @@ getoriginnode_test(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
@ -98,8 +97,7 @@ getsetservestalettl_test(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
@ -142,8 +140,7 @@ dns_dbfind_staleok_test(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);

View File

@ -142,7 +142,7 @@ dns_test_begin(FILE *logfile, bool start_managers) {
}
INSIST(dt_mctx == NULL);
CHECK(isc_mem_create(0, 0, &dt_mctx));
isc_mem_create(&dt_mctx);
/* Don't check the memory leaks as they hide the assertions */
isc_mem_setdestroycheck(dt_mctx, false);

View File

@ -778,11 +778,7 @@ dns_view_createresolver(dns_view_t *view,
view->attributes &= ~DNS_VIEWATTR_RESSHUTDOWN;
isc_refcount_increment(&view->weakrefs);
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
dns_resolver_shutdown(view->resolver);
return (result);
}
isc_mem_create(&mctx);
result = dns_adb_create(mctx, view, timermgr, taskmgr, &view->adb);
isc_mem_setname(mctx, "ADB", NULL);

View File

@ -16775,16 +16775,13 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr) {
static isc_result_t
mctxinit(void **target, void *arg) {
isc_result_t result;
isc_mem_t *mctx = NULL;
UNUSED(arg);
REQUIRE(target != NULL && *target == NULL);
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
return (result);
isc_mem_create(&mctx);
isc_mem_setname(mctx, "zonemgr-pool", NULL);
*target = mctx;

View File

@ -93,9 +93,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
{
isc_result_t result;
result = isc_mem_create(0, 0, mctxp);
if (result != ISC_R_SUCCESS)
goto fail;
isc_mem_create(mctxp);
result = isc_appctx_create(*mctxp, actxp);
if (result != ISC_R_SUCCESS)

View File

@ -34,10 +34,7 @@ static isc_mem_t *mctx = NULL;
static void
setup_test() {
isc_result_t result;
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
/*
* the caller might run from another directory, but tests

View File

@ -28,9 +28,6 @@ ISC_LANG_BEGINDECLS
#define ISC_MEM_HIWATER 1
typedef void (*isc_mem_water_t)(void *, int);
typedef void * (*isc_memalloc_t)(void *, size_t);
typedef void (*isc_memfree_t)(void *, void *);
/*%
* Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
* allocation and freeing by file and line number.
@ -123,14 +120,14 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
#endif
/*
* Flags for isc_mem_createx() calls.
* Flags for isc_mem_create() calls.
*/
#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */
#define ISC_MEMFLAG_RESERVED 0x00000001 /* reserved, obsoleted, don't use */
#define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */
#define ISC_MEMFLAG_FILL 0x00000004 /* fill with pattern after alloc and frees */
#if !ISC_MEM_USE_INTERNAL_MALLOC
#define ISC_MEMFLAG_DEFAULT 0
#define ISC_MEMFLAG_DEFAULT 0
#else
#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL|ISC_MEMFLAG_FILL
#endif
@ -252,42 +249,12 @@ struct isc_mempool {
} while (0)
/*@{*/
isc_result_t
isc_mem_create(size_t max_size, size_t target_size,
isc_mem_t **mctxp);
isc_result_t
isc_mem_createx(size_t max_size, size_t target_size,
isc_memalloc_t memalloc, isc_memfree_t memfree,
void *arg, isc_mem_t **mctxp, unsigned int flags);
void
isc_mem_create(isc_mem_t **mctxp);
/*!<
* \brief Create a memory context.
*
* 'max_size' and 'target_size' are tuning parameters. When
* ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
* will be satisfied by getting blocks of size 'target_size' from the
* system allocator and breaking them up into pieces; larger allocations
* will use the system allocator directly. If 'max_size' and/or
* 'target_size' are zero, default values will be * used. When
* ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
*
* 'max_size' is also used to size the statistics arrays and the array
* used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting
* 'max_size' too low can have detrimental effects on performance.
*
* A memory context created using isc_mem_createx() will obtain
* memory from the system by calling 'memalloc' and 'memfree',
* passing them the argument 'arg'. A memory context created
* using isc_mem_create() will use the standard library malloc()
* and free().
*
* If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
* will be accessed without locking. The user who creates the context must
* ensure there be no race. Since this can be a source of bug, it is generally
* inadvisable to use this flag unless the user is very sure about the race
* condition and the access to the object is highly performance sensitive.
*
* Requires:
* mctxp != NULL && *mctxp == NULL */
/*@}*/

View File

@ -42,8 +42,8 @@
#include "mem_p.h"
#define MCTXLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)
#define MCTXUNLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)
#define MCTXLOCK(m) LOCK(&m->lock)
#define MCTXUNLOCK(m) UNLOCK(&m->lock)
#ifndef ISC_MEM_DEBUGGING
#define ISC_MEM_DEBUGGING 0
@ -126,15 +126,17 @@ static isc_mutex_t contextslock;
*/
static uint64_t totallost;
typedef void * (*isc__memalloc_t)(size_t);
typedef void (*isc__memfree_t)(void *);
struct isc__mem {
isc_mem_t common;
unsigned int flags;
isc_mutex_t lock;
isc_memalloc_t memalloc;
isc_memfree_t memfree;
void * arg;
isc__memalloc_t memalloc;
isc__memfree_t memfree;
size_t max_size;
bool checkfree;
bool checkfree;
struct stats * stats;
isc_refcount_t references;
char name[16];
@ -146,8 +148,8 @@ struct isc__mem {
size_t maxmalloced;
size_t hi_water;
size_t lo_water;
bool hi_called;
bool is_overmem;
bool hi_called;
bool is_overmem;
isc_mem_water_t water;
void * water_arg;
ISC_LIST(isc__mempool_t) pools;
@ -360,8 +362,7 @@ more_basic_blocks(isc__mem_t *ctx) {
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
if (ctx->basic_table_count == ctx->basic_table_size) {
table_size = ctx->basic_table_size + TABLE_INCREMENT;
table = (ctx->memalloc)(ctx->arg,
table_size * sizeof(unsigned char *));
table = (ctx->memalloc)(table_size * sizeof(unsigned char *));
RUNTIME_CHECK(table != NULL);
ctx->malloced += table_size * sizeof(unsigned char *);
if (ctx->malloced > ctx->maxmalloced)
@ -370,7 +371,7 @@ more_basic_blocks(isc__mem_t *ctx) {
memmove(table, ctx->basic_table,
ctx->basic_table_size *
sizeof(unsigned char *));
(ctx->memfree)(ctx->arg, ctx->basic_table);
(ctx->memfree)(ctx->basic_table);
ctx->malloced -= ctx->basic_table_size *
sizeof(unsigned char *);
}
@ -378,7 +379,7 @@ more_basic_blocks(isc__mem_t *ctx) {
ctx->basic_table_size = table_size;
}
tmp = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target);
RUNTIME_CHECK(tmp != NULL);
ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target;;
ctx->basic_table[ctx->basic_table_count] = tmp;
@ -471,7 +472,7 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) {
/*
* memget() was called on something beyond our upper limit.
*/
ret = (ctx->memalloc)(ctx->arg, size);
ret = (ctx->memalloc)(size);
RUNTIME_CHECK(ret != NULL);
ctx->total += size;
ctx->inuse += size;
@ -550,7 +551,7 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) {
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
memset(mem, 0xde, size); /* Mnemonic for "dead". */
(ctx->memfree)(ctx->arg, mem);
(ctx->memfree)(mem);
INSIST(ctx->stats[ctx->max_size].gets != 0U);
ctx->stats[ctx->max_size].gets--;
INSIST(size <= ctx->inuse);
@ -594,7 +595,7 @@ mem_get(isc__mem_t *ctx, size_t size) {
#if ISC_MEM_CHECKOVERRUN
size += 1;
#endif
ret = (ctx->memalloc)(ctx->arg, size);
ret = (ctx->memalloc)(size);
RUNTIME_CHECK(ret != NULL);
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
@ -623,7 +624,7 @@ mem_put(isc__mem_t *ctx, void *mem, size_t size) {
#endif
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
memset(mem, 0xde, size); /* Mnemonic for "dead". */
(ctx->memfree)(ctx->arg, mem);
(ctx->memfree)(mem);
}
/*!
@ -678,9 +679,8 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
*/
static void *
default_memalloc(void *arg, size_t size) {
default_memalloc(size_t size) {
void *ptr;
UNUSED(arg);
ptr = malloc(size);
@ -709,8 +709,7 @@ default_memalloc(void *arg, size_t size) {
}
static void
default_memfree(void *arg, void *ptr) {
UNUSED(arg);
default_memfree(void *ptr) {
free(ptr);
}
@ -721,37 +720,23 @@ initialize_action(void) {
totallost = 0;
}
/*
* Public.
*/
isc_result_t
isc_mem_createx(size_t init_max_size, size_t target_size,
isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
isc_mem_t **ctxp, unsigned int flags)
static void
mem_create(isc_mem_t **ctxp, unsigned int flags)
{
isc__mem_t *ctx;
REQUIRE(ctxp != NULL && *ctxp == NULL);
REQUIRE(memalloc != NULL);
REQUIRE(memfree != NULL);
STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0,
"wrong alignment size");
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
ctx = (memalloc)(arg, sizeof(*ctx));
RUNTIME_CHECK(ctx != NULL);
ctx = (default_memalloc)(sizeof(*ctx));
if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
isc_mutex_init(&ctx->lock);
}
isc_mutex_init(&ctx->lock);
if (init_max_size == 0U)
ctx->max_size = DEF_MAX_SIZE;
else
ctx->max_size = init_max_size;
ctx->max_size = DEF_MAX_SIZE;
ctx->flags = flags;
isc_refcount_init(&ctx->references, 1);
memset(ctx->name, 0, sizeof(ctx->name));
@ -770,9 +755,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->common.impmagic = MEM_MAGIC;
ctx->common.magic = ISCAPI_MCTX_MAGIC;
ctx->common.methods = (isc_memmethods_t *)&memmethods;
ctx->memalloc = memalloc;
ctx->memfree = memfree;
ctx->arg = arg;
ctx->memalloc = default_memalloc;
ctx->memfree = default_memfree;
ctx->stats = NULL;
ctx->checkfree = true;
#if ISC_MEM_TRACKLINES
@ -789,8 +773,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->lowest = NULL;
ctx->highest = NULL;
ctx->stats = (memalloc)(arg,
(ctx->max_size+1) * sizeof(struct stats));
ctx->stats = (ctx->memalloc)((ctx->max_size+1) * sizeof(struct stats));
RUNTIME_CHECK(ctx->stats != NULL);
memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats));
@ -798,11 +781,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats);
if ((flags & ISC_MEMFLAG_INTERNAL) != 0) {
if (target_size == 0U)
ctx->mem_target = DEF_MEM_TARGET;
else
ctx->mem_target = target_size;
ctx->freelists = (memalloc)(arg, ctx->max_size *
ctx->mem_target = DEF_MEM_TARGET;
ctx->freelists = (ctx->memalloc)(ctx->max_size *
sizeof(element *));
RUNTIME_CHECK(ctx->freelists != NULL);
memset(ctx->freelists, 0,
@ -815,7 +795,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0)) {
unsigned int i;
ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT *
ctx->debuglist = (ctx->memalloc)((DEBUG_TABLE_COUNT *
sizeof(debuglist_t)));
RUNTIME_CHECK(ctx->debuglist != NULL);
for (i = 0; i < DEBUG_TABLE_COUNT; i++)
@ -830,10 +810,12 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
UNLOCK(&contextslock);
*ctxp = (isc_mem_t *)ctx;
return (ISC_R_SUCCESS);
}
/*
* Public.
*/
static void
destroy(isc__mem_t *ctx) {
unsigned int i;
@ -865,7 +847,7 @@ destroy(isc__mem_t *ctx) {
ctx->malloced -= sizeof(*dl);
}
(ctx->memfree)(ctx->arg, ctx->debuglist);
(ctx->memfree)(ctx->debuglist);
ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t);
}
#endif
@ -886,29 +868,29 @@ destroy(isc__mem_t *ctx) {
}
}
(ctx->memfree)(ctx->arg, ctx->stats);
(ctx->memfree)(ctx->stats);
ctx->malloced -= (ctx->max_size+1) * sizeof(struct stats);
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
for (i = 0; i < ctx->basic_table_count; i++) {
(ctx->memfree)(ctx->arg, ctx->basic_table[i]);
(ctx->memfree)(ctx->basic_table[i]);
ctx->malloced -= NUM_BASIC_BLOCKS * ctx->mem_target;
}
(ctx->memfree)(ctx->arg, ctx->freelists);
(ctx->memfree)(ctx->freelists);
ctx->malloced -= ctx->max_size * sizeof(element *);
if (ctx->basic_table != NULL) {
(ctx->memfree)(ctx->arg, ctx->basic_table);
(ctx->memfree)(ctx->basic_table);
ctx->malloced -= ctx->basic_table_size *
sizeof(unsigned char *);
}
}
if ((ctx->flags & ISC_MEMFLAG_NOLOCK) == 0)
isc_mutex_destroy(&ctx->lock);
isc_mutex_destroy(&ctx->lock);
ctx->malloced -= sizeof(*ctx);
if (ctx->checkfree)
INSIST(ctx->malloced == 0);
(ctx->memfree)(ctx->arg, ctx);
(ctx->memfree)(ctx);
}
void
@ -967,7 +949,7 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
goto destroy;
}
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
@ -977,7 +959,7 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
mem_putstats(ctx, ptr, size);
mem_put(ctx, ptr, size);
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
destroy:
if (isc_refcount_decrement(&ctx->references) == 1) {
@ -1025,11 +1007,11 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
return (isc__mem_allocate(ctx0, size FLARG_PASS));
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
ptr = mem_getunlocked(ctx, size);
} else {
ptr = mem_get(ctx, size);
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
if (ptr != NULL)
mem_getstats(ctx, size);
}
@ -1048,7 +1030,7 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
fprintf(stderr, "maxinuse = %lu\n",
(unsigned long)ctx->inuse);
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
if (call_water && (ctx->water != NULL))
(ctx->water)(ctx->water_arg, ISC_MEM_HIWATER);
@ -1080,7 +1062,7 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
return;
}
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
@ -1102,7 +1084,7 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
call_water = true;
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
if (call_water && (ctx->water != NULL))
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
@ -1114,12 +1096,12 @@ isc_mem_waterack(isc_mem_t *ctx0, int flag) {
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
if (flag == ISC_MEM_LOWATER)
ctx->hi_called = false;
else if (flag == ISC_MEM_HIWATER)
ctx->hi_called = true;
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
}
#if ISC_MEM_TRACKLINES
@ -1168,7 +1150,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) {
const isc__mempool_t *pool;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
for (i = 0; i <= ctx->max_size; i++) {
s = &ctx->stats[i];
@ -1217,7 +1199,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) {
print_active(ctx, out);
#endif
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
}
/*
@ -1256,7 +1238,7 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) {
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
si = mem_allocateunlocked((isc_mem_t *)ctx, size);
if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0)) {
mem_getstats(ctx, si[-1].u.size);
@ -1281,7 +1263,7 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) {
fprintf(stderr, "maxinuse = %lu\n",
(unsigned long)ctx->inuse);
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
if (call_water) {
(ctx->water)(ctx->water_arg, ISC_MEM_HIWATER);
@ -1350,7 +1332,7 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) {
size = si->u.size;
}
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
DELETE_TRACE(ctx, ptr, size, file, line);
@ -1378,7 +1360,7 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) {
if (ctx->water != NULL)
call_water = true;
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
if (call_water)
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
@ -1413,11 +1395,11 @@ isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
ctx->checkfree = flag;
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
}
size_t
@ -1426,11 +1408,11 @@ isc_mem_inuse(isc_mem_t *ctx0) {
size_t inuse;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
inuse = ctx->inuse;
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
return (inuse);
}
@ -1441,11 +1423,11 @@ isc_mem_maxinuse(isc_mem_t *ctx0) {
size_t maxinuse;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
maxinuse = ctx->maxinuse;
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
return (maxinuse);
}
@ -1456,11 +1438,11 @@ isc_mem_total(isc_mem_t *ctx0) {
size_t total;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
total = ctx->total;
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
return (total);
}
@ -1477,7 +1459,7 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(hiwater >= lowater);
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
oldwater = ctx->water;
oldwater_arg = ctx->water_arg;
if (water == NULL) {
@ -1496,7 +1478,7 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
ctx->hi_water = hiwater;
ctx->lo_water = lowater;
}
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
if (callwater && oldwater != NULL)
(oldwater)(oldwater_arg, ISC_MEM_LOWATER);
@ -1593,10 +1575,10 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
*mpctxp = (isc_mempool_t *)mpctx;
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
ISC_LIST_INITANDAPPEND(mctx->pools, mpctx, link);
mctx->poolcnt++;
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
return (ISC_R_SUCCESS);
}
@ -1651,7 +1633,7 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) {
/*
* Return any items on the free list
*/
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
while (mpctx->items != NULL) {
INSIST(mpctx->freecount > 0);
mpctx->freecount--;
@ -1665,15 +1647,15 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) {
mem_put(mctx, item, mpctx->size);
}
}
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
/*
* Remove our linked list entry from the memory context.
*/
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
ISC_LIST_UNLINK(mctx->pools, mpctx, link);
mctx->poolcnt--;
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
mpctx->common.impmagic = 0;
mpctx->common.magic = 0;
@ -1724,7 +1706,7 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
* We need to dip into the well. Lock the memory context
* here and fill up our free list.
*/
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
for (i = 0; i < mpctx->fillcount; i++) {
if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
item = mem_getunlocked(mctx, mpctx->size);
@ -1739,7 +1721,7 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
mpctx->items = item;
mpctx->freecount++;
}
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
}
/*
@ -1763,9 +1745,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
if (ISC_UNLIKELY(((isc_mem_debugging & TRACE_OR_RECORD) != 0) &&
item != NULL))
{
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
ADD_TRACE(mctx, item, mpctx->size, file, line);
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
}
#endif /* ISC_MEM_TRACKLINES */
@ -1792,9 +1774,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) {
#if ISC_MEM_TRACKLINES
if (ISC_UNLIKELY((isc_mem_debugging & TRACE_OR_RECORD) != 0)) {
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
DELETE_TRACE(mctx, mem, mpctx->size, file, line);
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
}
#endif /* ISC_MEM_TRACKLINES */
@ -1802,14 +1784,14 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) {
* If our free list is full, return this to the mctx directly.
*/
if (mpctx->freecount >= mpctx->freemax) {
MCTXLOCK(mctx, &mctx->lock);
MCTXLOCK(mctx);
if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
mem_putunlocked(mctx, mem, mpctx->size);
} else {
mem_putstats(mctx, mem, mpctx->size);
mem_put(mctx, mem, mpctx->size);
}
MCTXUNLOCK(mctx, &mctx->lock);
MCTXUNLOCK(mctx);
if (mpctx->lock != NULL)
UNLOCK(mpctx->lock);
return;
@ -2035,7 +2017,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary,
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context"));
@ -2132,7 +2114,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary,
TRY0(xmlTextWriterEndElement(writer)); /* context */
error:
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
return (xmlrc);
}
@ -2223,7 +2205,7 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
REQUIRE(summary != NULL);
REQUIRE(array != NULL);
MCTXLOCK(ctx, &ctx->lock);
MCTXLOCK(ctx);
summary->contextsize += sizeof(*ctx) +
(ctx->max_size + 1) * sizeof(struct stats) +
@ -2304,7 +2286,7 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
CHECKMEM(obj);
json_object_object_add(ctxobj, "lowater", obj);
MCTXUNLOCK(ctx, &ctx->lock);
MCTXUNLOCK(ctx);
json_object_array_add(array, ctxobj);
return (ISC_R_SUCCESS);
}
@ -2371,11 +2353,9 @@ isc_mem_renderjson(void *memobj0) {
}
#endif /* HAVE_JSON_C */
isc_result_t
isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
return (isc_mem_createx(init_max_size, target_size,
default_memalloc, default_memfree,
NULL, mctxp, isc_mem_defaultflags));
void
isc_mem_create(isc_mem_t **mctxp) {
mem_create(mctxp, isc_mem_defaultflags);
}
void *

View File

@ -16,7 +16,10 @@ VERSION=@BIND9_VERSION@
@BIND9_MAKE_INCLUDES@
CINCLUDES = -I. -Iinclude ${ISC_INCLUDES} \
${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@
${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@ \
${JSON_C_CFLAGS} \
${LIBXML2_CFLAGS} \
${ZLIB_CFLAGS}
CDEFINES = -DTESTS="\"${top_builddir}/lib/isc/tests/\""
ISCLIBS = ../libisc.@A@ ${OPENSSL_LIBS} ${JSON_C_LIBS} ${LIBXML2_LIBS}

View File

@ -58,8 +58,7 @@ isc_heap_delete_test(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_heap_create(mctx, compare, idx, 0, &heap);
assert_int_equal(result, ISC_R_SUCCESS);

View File

@ -31,21 +31,6 @@
#include <isc/string.h>
#include <isc/util.h>
static void *
default_memalloc(void *arg, size_t size) {
UNUSED(arg);
if (size == 0U) {
size = 1;
}
return (malloc(size));
}
static void
default_memfree(void *arg, void *ptr) {
UNUSED(arg);
free(ptr);
}
static void
test_ht_full(int bits, uintptr_t count) {
isc_ht_t *ht = NULL;
@ -53,9 +38,7 @@ test_ht_full(int bits, uintptr_t count) {
isc_mem_t *mctx = NULL;
uintptr_t i;
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx, 0);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_ht_init(&ht, mctx, bits);
assert_int_equal(result, ISC_R_SUCCESS);
@ -207,9 +190,7 @@ test_ht_iterator() {
unsigned char key[16];
size_t tksize;
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx, 0);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_ht_init(&ht, mctx, 16);
assert_int_equal(result, ISC_R_SUCCESS);

View File

@ -109,7 +109,7 @@ isc_test_begin(FILE *logfile, bool start_managers,
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
INSIST(mctx == NULL);
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
if (logfile != NULL) {
isc_logdestination_t destination;

View File

@ -41,8 +41,7 @@ lex_0xff(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);
@ -75,8 +74,7 @@ lex_setline(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_lex_create(mctx, 1024, &lex);
assert_int_equal(result, ISC_R_SUCCESS);

View File

@ -50,21 +50,6 @@ _setup(void **state) {
return (0);
}
static void *
default_memalloc(void *arg, size_t size) {
UNUSED(arg);
if (size == 0U) {
size = 1;
}
return (malloc(size));
}
static void
default_memfree(void *arg, void *ptr) {
UNUSED(arg);
free(ptr);
}
static int
_teardown(void **state) {
UNUSED(state);
@ -95,8 +80,7 @@ isc_mem_test(void **state) {
UNUSED(state);
result = isc_mem_create(0, 0, &localmctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&localmctx);
result = isc_mempool_create(localmctx, 24, &mp1);
assert_int_equal(result, ISC_R_SUCCESS);
@ -169,10 +153,7 @@ isc_mem_test(void **state) {
isc_mem_destroy(&localmctx);
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &localmctx,
ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&localmctx);
result = isc_mempool_create(localmctx, 2, &mp1);
assert_int_equal(result, ISC_R_SUCCESS);
@ -191,7 +172,6 @@ isc_mem_test(void **state) {
/* test TotalUse calculation */
static void
isc_mem_total_test(void **state) {
isc_result_t result;
isc_mem_t *mctx2 = NULL;
size_t before, after;
ssize_t diff;
@ -201,11 +181,7 @@ isc_mem_total_test(void **state) {
/* Local alloc, free */
mctx2 = NULL;
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx2, 0);
if (result != ISC_R_SUCCESS) {
goto out;
}
isc_mem_create(&mctx2);
before = isc_mem_total(mctx2);
@ -239,17 +215,12 @@ isc_mem_total_test(void **state) {
/* 2048 +8 bytes extra for size_info */
assert_int_equal(diff, (2048 + 8) * 100000);
out:
if (mctx2 != NULL) {
isc_mem_destroy(&mctx2);
}
isc_mem_destroy(&mctx2);
}
/* test InUse calculation */
static void
isc_mem_inuse_test(void **state) {
isc_result_t result;
isc_mem_t *mctx2 = NULL;
size_t before, after;
ssize_t diff;
@ -258,11 +229,7 @@ isc_mem_inuse_test(void **state) {
UNUSED(state);
mctx2 = NULL;
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx2, 0);
if (result != ISC_R_SUCCESS) {
goto out;
}
isc_mem_create(&mctx2);
before = isc_mem_inuse(mctx2);
ptr = isc_mem_allocate(mctx2, 1024000);
@ -273,11 +240,7 @@ isc_mem_inuse_test(void **state) {
assert_int_equal(diff, 0);
out:
if (mctx2 != NULL) {
isc_mem_destroy(&mctx2);
}
isc_mem_destroy(&mctx2);
}
#if ISC_MEM_TRACKLINES
@ -296,9 +259,7 @@ isc_mem_noflags_test(void **state) {
UNUSED(state);
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx2, 0);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx2);
isc_mem_debugging = 0;
ptr = isc_mem_get(mctx2, 2048);
assert_non_null(ptr);
@ -343,9 +304,7 @@ isc_mem_recordflag_test(void **state) {
UNUSED(state);
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx2, 0);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx2);
ptr = isc_mem_get(mctx2, 2048);
assert_non_null(ptr);
isc__mem_printactive(mctx2, f);
@ -388,10 +347,8 @@ isc_mem_traceflag_test(void **state) {
UNUSED(state);
result = isc_mem_createx(0, 0, default_memalloc, default_memfree,
NULL, &mctx2, 0);
isc_mem_create(&mctx2);
isc_mem_debugging = ISC_MEM_DEBUGTRACE;
assert_int_equal(result, ISC_R_SUCCESS);
ptr = isc_mem_get(mctx2, 2048);
assert_non_null(ptr);
isc__mem_printactive(mctx2, f);

View File

@ -273,7 +273,6 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
static void
random_test(pvalue_func_t *func, isc_random_func test_func) {
isc_mem_t *mctx = NULL;
isc_result_t result;
uint32_t m;
uint32_t j;
uint32_t histogram[11] = { 0 };
@ -287,8 +286,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
tables_init();
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
m = 1000;
passed = 0;

View File

@ -708,8 +708,7 @@ manytasks(void **state) {
isc_condition_init(&cv);
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
result = isc_mem_create(0, 0, &mctx);
assert_int_equal(result, ISC_R_SUCCESS);
isc_mem_create(&mctx);
result = isc_taskmgr_create(mctx, 4, 0, &taskmgr);
assert_int_equal(result, ISC_R_SUCCESS);

View File

@ -348,7 +348,6 @@ isc_md
isc_mem_attach
isc_mem_checkdestroyed
isc_mem_create
isc_mem_createx
isc_mem_destroy
isc_mem_detach
isc_mem_getname

View File

@ -71,7 +71,7 @@ setup() {
isc_result_t result;
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;

View File

@ -3043,7 +3043,6 @@ client_timeout(isc_task_t *task, isc_event_t *event) {
static isc_result_t
get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) {
isc_mem_t *clientmctx;
isc_result_t result;
#if NMCTXS > 0
unsigned int nextmctx;
#endif
@ -3054,10 +3053,9 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) {
* Caller must be holding the manager lock.
*/
if ((manager->sctx->options & NS_SERVER_CLIENTTEST) != 0) {
result = isc_mem_create(0, 0, mctxp);
if (result == ISC_R_SUCCESS)
isc_mem_setname(*mctxp, "client", NULL);
return (result);
isc_mem_create(mctxp);
isc_mem_setname(*mctxp, "client", NULL);
return (ISC_R_SUCCESS);
}
#if NMCTXS > 0
nextmctx = manager->nextmctx++;
@ -3068,9 +3066,7 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) {
clientmctx = manager->mctxpool[nextmctx];
if (clientmctx == NULL) {
result = isc_mem_create(0, 0, &clientmctx);
if (result != ISC_R_SUCCESS)
return (result);
isc_mem_create(&clientmctx);
isc_mem_setname(clientmctx, "client", NULL);
manager->mctxpool[nextmctx] = clientmctx;

View File

@ -43,13 +43,9 @@ static isc_refcount_t references;
static void
initialize(void) {
isc_result_t result;
REQUIRE(initialize_done == false);
result = isc_mem_create(0, 0, &ns_g_mctx);
if (result != ISC_R_SUCCESS)
return;
isc_mem_create(&ns_g_mctx);
isc_refcount_init(&references, 0);
initialize_done = true;

View File

@ -237,7 +237,7 @@ ns_test_begin(FILE *logfile, bool start_managers) {
}
INSIST(mctx == NULL);
CHECK(isc_mem_create(0, 0, &mctx));
isc_mem_create(&mctx);
if (!dst_active) {
CHECK(dst_lib_init(mctx, NULL));

View File

@ -215,9 +215,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
{
isc_result_t result;
result = isc_mem_create(0, 0, mctxp);
if (result != ISC_R_SUCCESS)
goto fail;
isc_mem_create(mctxp);
result = isc_appctx_create(*mctxp, actxp);
if (result != ISC_R_SUCCESS)

View File

@ -113,11 +113,7 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr,
isc_region_t r;
dns_secalg_t alg;
result = isc_mem_create(0, 0, mctxp);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "failed to create mctx\n");
exit(1);
}
isc_mem_create(mctxp);
if (algname != NULL) {
tr.base = algname;
@ -367,11 +363,7 @@ main(int argc, char *argv[]) {
exit(1);
}
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "failed to crate mctx\n");
exit(1);
}
isc_mem_create(&mctx);
result = isc_appctx_create(mctx, &actx);
if (result != ISC_R_SUCCESS)

View File

@ -97,9 +97,7 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
{
isc_result_t result;
result = isc_mem_create(0, 0, mctxp);
if (result != ISC_R_SUCCESS)
goto fail;
isc_mem_create(mctxp);
result = isc_appctx_create(*mctxp, actxp);
if (result != ISC_R_SUCCESS)

View File

@ -188,11 +188,7 @@ main(int argc, char *argv[]) {
qmessage = NULL;
rmessage = NULL;
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "failed to create a memory context\n");
exit(1);
}
isc_mem_create(&mctx);
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage);
if (result == ISC_R_SUCCESS) {
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE,

View File

@ -240,11 +240,7 @@ main(int argc, char *argv[]) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
exit(1);
}
result = isc_mem_create(0, 0, &umctx);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "failed to crate mctx\n");
exit(1);
}
isc_mem_create(&umctx);
result = dns_client_create(&client, 0);
if (result != ISC_R_SUCCESS) {