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

Merge branch 'ondrej-isc_mem_cget' into 'main'

Checked array allocation arithmetic with isc_mem_get and friends

See merge request isc-projects/bind9!8237
This commit is contained in:
Ondřej Surý 2023-08-31 20:18:26 +00:00
commit 4e1630eeba
68 changed files with 622 additions and 689 deletions

View File

@ -1,3 +1,9 @@
6236. [func] Add isc_mem_cget() and isc_mem_cput() calloc-like
functions that take nmemb and size, do checked
multiplication and zero the memory before returning
it to the user. Replace isc_mem_getx(..., ISC_MEM_ZERO)
with isc_mem_cget(...) usage. [GL !8237]
6235. [doc] Clarify BIND 9 time formats. [GL #4266]
6234. [bug] Restore stale-refresh-time value after flushing the

View File

@ -537,7 +537,7 @@ match_keyset_dsset(dns_rdataset_t *keyset, dns_rdataset_t *dsset,
nkey = dns_rdataset_count(keyset);
keytable = isc_mem_getx(mctx, sizeof(keytable[0]) * nkey, ISC_MEM_ZERO);
keytable = isc_mem_cget(mctx, nkey, sizeof(keytable[0]));
for (result = dns_rdataset_first(keyset), i = 0, ki = keytable;
result == ISC_R_SUCCESS;
@ -593,7 +593,7 @@ free_keytable(keyinfo_t **keytable_p) {
}
}
isc_mem_put(mctx, keytable, sizeof(keytable[0]) * nkey);
isc_mem_cput(mctx, keytable, nkey, sizeof(keytable[0]));
}
/*
@ -614,7 +614,7 @@ matching_sigs(keyinfo_t *keytbl, dns_rdataset_t *rdataset,
REQUIRE(keytbl != NULL);
algo = isc_mem_getx(mctx, nkey * sizeof(algo[0]), ISC_MEM_ZERO);
algo = isc_mem_cget(mctx, nkey, sizeof(algo[0]));
for (result = dns_rdataset_first(sigset); result == ISC_R_SUCCESS;
result = dns_rdataset_next(sigset))
@ -697,7 +697,7 @@ signed_loose(dns_secalg_t *algo) {
ok = true;
}
}
isc_mem_put(mctx, algo, nkey * sizeof(algo[0]));
isc_mem_cput(mctx, algo, nkey, sizeof(algo[0]));
return (ok);
}
@ -739,7 +739,7 @@ signed_strict(dns_rdataset_t *dsset, dns_secalg_t *algo) {
}
}
isc_mem_put(mctx, algo, nkey * sizeof(algo[0]));
isc_mem_cput(mctx, algo, nkey, sizeof(algo[0]));
return (all_ok);
}
@ -894,7 +894,7 @@ consistent_digests(dns_rdataset_t *dsset) {
n = dns_rdataset_count(dsset);
arrdata = isc_mem_get(mctx, n * sizeof(dns_rdata_t));
arrdata = isc_mem_cget(mctx, n, sizeof(dns_rdata_t));
for (result = dns_rdataset_first(dsset), i = 0; result == ISC_R_SUCCESS;
result = dns_rdataset_next(dsset), i++)
@ -908,7 +908,7 @@ consistent_digests(dns_rdataset_t *dsset) {
/*
* Convert sorted arrdata to more accessible format
*/
ds = isc_mem_get(mctx, n * sizeof(dns_rdata_ds_t));
ds = isc_mem_cget(mctx, n, sizeof(dns_rdata_ds_t));
for (i = 0; i < n; i++) {
result = dns_rdata_tostruct(&arrdata[i], &ds[i], NULL);
@ -947,8 +947,8 @@ consistent_digests(dns_rdataset_t *dsset) {
/*
* Done!
*/
isc_mem_put(mctx, ds, n * sizeof(dns_rdata_ds_t));
isc_mem_put(mctx, arrdata, n * sizeof(dns_rdata_t));
isc_mem_cput(mctx, ds, n, sizeof(dns_rdata_ds_t));
isc_mem_cput(mctx, arrdata, n, sizeof(dns_rdata_t));
return (match);
}

View File

@ -528,8 +528,8 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name,
if (!nosigs) {
arraysize += dns_rdataset_count(&sigset);
}
wassignedby = isc_mem_get(mctx, arraysize * sizeof(bool));
nowsignedby = isc_mem_get(mctx, arraysize * sizeof(bool));
wassignedby = isc_mem_cget(mctx, arraysize, sizeof(bool));
nowsignedby = isc_mem_cget(mctx, arraysize, sizeof(bool));
for (i = 0; i < arraysize; i++) {
wassignedby[i] = nowsignedby[i] = false;
@ -781,8 +781,8 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name,
}
}
isc_mem_put(mctx, wassignedby, arraysize * sizeof(bool));
isc_mem_put(mctx, nowsignedby, arraysize * sizeof(bool));
isc_mem_cput(mctx, wassignedby, arraysize, sizeof(bool));
isc_mem_cput(mctx, nowsignedby, arraysize, sizeof(bool));
}
struct hashlist {

View File

@ -576,22 +576,18 @@ named_config_getname(isc_mem_t *mctx, const cfg_obj_t *obj,
return (ISC_R_SUCCESS);
}
#define grow_array(mctx, array, newlen, oldlen) \
if (newlen >= oldlen) { \
size_t newsize = (newlen + 16) * sizeof(array[0]); \
size_t oldsize = oldlen * sizeof(array[0]); \
array = isc_mem_regetx(mctx, array, oldsize, newsize, \
ISC_MEM_ZERO); \
oldlen = newlen + 16; \
#define grow_array(mctx, array, newlen, oldlen) \
if (newlen >= oldlen) { \
array = isc_mem_creget(mctx, array, oldlen, newlen + 16, \
sizeof(array[0])); \
oldlen = newlen + 16; \
}
#define shrink_array(mctx, array, newlen, oldlen) \
if (newlen < oldlen) { \
size_t newsize = newlen * sizeof(array[0]); \
size_t oldsize = oldlen * sizeof(array[0]); \
array = isc_mem_regetx(mctx, array, oldsize, newsize, \
ISC_MEM_ZERO); \
oldlen = newlen; \
#define shrink_array(mctx, array, newlen, oldlen) \
if (newlen < oldlen) { \
array = isc_mem_creget(mctx, array, oldlen, newlen, \
sizeof(array[0])); \
oldlen = newlen; \
}
isc_result_t
@ -808,10 +804,10 @@ resume:
shrink_array(mctx, sources, i, srccount);
if (lists != NULL) {
isc_mem_put(mctx, lists, listcount * sizeof(lists[0]));
isc_mem_cput(mctx, lists, listcount, sizeof(lists[0]));
}
if (stack != NULL) {
isc_mem_put(mctx, stack, stackcount * sizeof(stack[0]));
isc_mem_cput(mctx, stack, stackcount, sizeof(stack[0]));
}
INSIST(keycount == addrcount);
@ -829,7 +825,7 @@ resume:
cleanup:
if (addrs != NULL) {
isc_mem_put(mctx, addrs, addrcount * sizeof(addrs[0]));
isc_mem_cput(mctx, addrs, addrcount, sizeof(addrs[0]));
}
if (keys != NULL) {
for (size_t j = 0; j < i; j++) {
@ -841,7 +837,7 @@ cleanup:
}
isc_mem_put(mctx, keys[j], sizeof(*keys[j]));
}
isc_mem_put(mctx, keys, keycount * sizeof(keys[0]));
isc_mem_cput(mctx, keys, keycount, sizeof(keys[0]));
}
if (tlss != NULL) {
for (size_t j = 0; j < i; j++) {
@ -853,16 +849,16 @@ cleanup:
}
isc_mem_put(mctx, tlss[j], sizeof(*tlss[j]));
}
isc_mem_put(mctx, tlss, tlscount * sizeof(tlss[0]));
isc_mem_cput(mctx, tlss, tlscount, sizeof(tlss[0]));
}
if (sources != NULL) {
isc_mem_put(mctx, sources, srccount * sizeof(sources[0]));
isc_mem_cput(mctx, sources, srccount, sizeof(sources[0]));
}
if (lists != NULL) {
isc_mem_put(mctx, lists, listcount * sizeof(lists[0]));
isc_mem_cput(mctx, lists, listcount, sizeof(lists[0]));
}
if (stack != NULL) {
isc_mem_put(mctx, stack, stackcount * sizeof(stack[0]));
isc_mem_cput(mctx, stack, stackcount, sizeof(stack[0]));
}
return (result);
}

View File

@ -4210,7 +4210,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
dlzargv[0], dlzargc, dlzargv,
&dlzdb);
isc_mem_free(mctx, s);
isc_mem_put(mctx, dlzargv, dlzargc * sizeof(*dlzargv));
isc_mem_cput(mctx, dlzargv, dlzargc, sizeof(*dlzargv));
if (result != ISC_R_SUCCESS) {
goto cleanup;
}

View File

@ -289,7 +289,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
if (n == 0) {
types = NULL;
} else {
types = isc_mem_get(mctx, n * sizeof(*types));
types = isc_mem_cget(mctx, n, sizeof(*types));
}
i = 0;
@ -319,8 +319,8 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
ISC_LOG_ERROR,
"'%s' is not a valid count",
bracket);
isc_mem_put(mctx, types,
n * sizeof(*types));
isc_mem_cput(mctx, types, n,
sizeof(*types));
goto cleanup;
}
} else {
@ -334,7 +334,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
ISC_LOG_ERROR,
"'%.*s' is not a valid type",
(int)r.length, str);
isc_mem_put(mctx, types, n * sizeof(*types));
isc_mem_cput(mctx, types, n, sizeof(*types));
goto cleanup;
}
}
@ -344,7 +344,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
mtype, dns_fixedname_name(&fname), n,
types);
if (types != NULL) {
isc_mem_put(mctx, types, n * sizeof(*types));
isc_mem_cput(mctx, types, n, sizeof(*types));
}
}
@ -705,7 +705,7 @@ strtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp,
if (*s == '\0') {
/* We have reached the end of the string. */
*argcp = n;
*argvp = isc_mem_get(mctx, n * sizeof(char *));
*argvp = isc_mem_cget(mctx, n, sizeof(char *));
} else {
char *p = s;
while (*p != ' ' && *p != '\t' && *p != '\0') {
@ -1000,7 +1000,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
* compiler w/o generating a warning.
*/
dns_zone_setdbtype(zone, dbargc, (const char *const *)dbargv);
isc_mem_put(mctx, dbargv, dbargc * sizeof(*dbargv));
isc_mem_cput(mctx, dbargv, dbargc, sizeof(*dbargv));
if (cpval != default_dbtype && cpval != dlz_dbtype) {
isc_mem_free(mctx, cpval);
}

View File

@ -238,8 +238,8 @@ error(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
static void
primary_from_servers(void) {
if (primary_servers != NULL && primary_servers != servers) {
isc_mem_put(gmctx, primary_servers,
primary_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, primary_servers, primary_alloc,
sizeof(isc_sockaddr_t));
}
primary_servers = servers;
primary_total = ns_total;
@ -684,12 +684,12 @@ doshutdown(void) {
* to NULL.
*/
if (primary_servers != NULL && primary_servers != servers) {
isc_mem_put(gmctx, primary_servers,
primary_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, primary_servers, primary_alloc,
sizeof(isc_sockaddr_t));
}
if (servers != NULL) {
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, servers, ns_alloc, sizeof(isc_sockaddr_t));
}
if (localaddr4 != NULL) {
@ -830,7 +830,7 @@ setup_system(void) {
if (primary_servers == servers) {
primary_servers = NULL;
}
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, servers, ns_alloc, sizeof(isc_sockaddr_t));
}
ns_inuse = 0;
@ -845,7 +845,7 @@ setup_system(void) {
default_servers = !local_only;
ns_total = ns_alloc = (have_ipv4 ? 1 : 0) + (have_ipv6 ? 1 : 0);
servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t));
servers = isc_mem_cget(gmctx, ns_alloc, sizeof(isc_sockaddr_t));
if (have_ipv6) {
memset(&in6, 0, sizeof(in6));
@ -887,7 +887,7 @@ setup_system(void) {
}
ns_alloc = ns_total;
servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t));
servers = isc_mem_cget(gmctx, ns_alloc, sizeof(isc_sockaddr_t));
i = 0;
for (sa = ISC_LIST_HEAD(*nslist); sa != NULL;
@ -1556,15 +1556,14 @@ evaluate_server(char *cmdline) {
if (primary_servers == servers) {
primary_servers = NULL;
}
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, servers, ns_alloc, sizeof(isc_sockaddr_t));
}
default_servers = false;
ns_alloc = MAX_SERVERADDRS;
ns_inuse = 0;
servers = isc_mem_getx(gmctx, ns_alloc * sizeof(isc_sockaddr_t),
ISC_MEM_ZERO);
servers = isc_mem_cget(gmctx, ns_alloc, sizeof(isc_sockaddr_t));
ns_total = get_addresses(server, (in_port_t)port, servers, ns_alloc);
if (ns_total == 0) {
return (STATUS_SYNTAX);
@ -2824,7 +2823,6 @@ lookforsoa:
if (default_servers) {
char serverstr[DNS_NAME_MAXTEXT + 1];
isc_buffer_t buf;
size_t size;
isc_buffer_init(&buf, serverstr, sizeof(serverstr));
result = dns_name_totext(&primary, DNS_NAME_OMITFINALDOT, &buf);
@ -2832,12 +2830,12 @@ lookforsoa:
serverstr[isc_buffer_usedlength(&buf)] = 0;
if (primary_servers != NULL && primary_servers != servers) {
isc_mem_put(gmctx, primary_servers,
primary_alloc * sizeof(isc_sockaddr_t));
isc_mem_cput(gmctx, primary_servers, primary_alloc,
sizeof(isc_sockaddr_t));
}
primary_alloc = MAX_SERVERADDRS;
size = primary_alloc * sizeof(isc_sockaddr_t);
primary_servers = isc_mem_getx(gmctx, size, ISC_MEM_ZERO);
primary_servers = isc_mem_cget(gmctx, primary_alloc,
sizeof(isc_sockaddr_t));
primary_total = get_addresses(serverstr, dnsport,
primary_servers, primary_alloc);
if (primary_total == 0) {

View File

@ -606,18 +606,17 @@ create_db(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
a_addr.s_addr = 0x0100007fU;
sampledb = isc_mem_getx(mctx, sizeof(*sampledb), ISC_MEM_ZERO);
sampledb = isc_mem_get(mctx, sizeof(*sampledb));
*sampledb = (sampledb_t){
.common.magic = DNS_DB_MAGIC,
.common.impmagic = SAMPLEDB_MAGIC,
.common.methods = &sampledb_methods,
.common.rdclass = rdclass,
};
isc_mem_attach(mctx, &sampledb->common.mctx);
dns_name_init(&sampledb->common.origin, NULL);
sampledb->common.magic = DNS_DB_MAGIC;
sampledb->common.impmagic = SAMPLEDB_MAGIC;
sampledb->common.methods = &sampledb_methods;
sampledb->common.attributes = 0;
sampledb->common.rdclass = rdclass;
CHECK(dns_name_dupwithoffsets(origin, mctx, &sampledb->common.origin));
isc_refcount_init(&sampledb->common.references, 1);

View File

@ -135,7 +135,7 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
cleanup:
isc_mem_free(mctx, s);
if (argv != NULL) {
isc_mem_put(mctx, argv, argc * sizeof(*argv));
isc_mem_cput(mctx, argv, argc, sizeof(*argv));
}
return (result);

View File

@ -114,12 +114,12 @@ new_sample_instance(isc_mem_t *mctx, const char *db_name, int argc, char **argv,
REQUIRE(sample_instp != NULL && *sample_instp == NULL);
sample_instance_t *inst = isc_mem_getx(mctx, sizeof(*inst),
ISC_MEM_ZERO);
sample_instance_t *inst = isc_mem_get(mctx, sizeof(*inst));
*inst = (sample_instance_t){ 0 };
isc_mem_attach(mctx, &inst->mctx);
inst->db_name = isc_mem_strdup(mctx, db_name);
inst->zone1_name = dns_fixedname_initname(&inst->zone1_fn);
inst->zone2_name = dns_fixedname_initname(&inst->zone2_fn);

View File

@ -226,7 +226,8 @@ syncptr(sample_instance_t *inst, dns_name_t *name, dns_rdata_t *addr_rdata,
DNS_RDATACOMMON_INIT(&ptr_struct, dns_rdatatype_ptr, dns_rdataclass_in);
dns_name_init(&ptr_struct.ptr, NULL);
syncptr = isc_mem_getx(mctx, sizeof(*syncptr), ISC_MEM_ZERO);
syncptr = isc_mem_get(mctx, sizeof(*syncptr));
*syncptr = (syncptr_t){ 0 };
isc_mem_attach(mctx, &syncptr->mctx);
isc_buffer_init(&syncptr->b, syncptr->buf, sizeof(syncptr->buf));
dns_fixedname_init(&syncptr->ptr_target_name);

161
cocci/isc_mem_cget.spatch Normal file
View File

@ -0,0 +1,161 @@
@@
expression MCTX, COUNT;
type ELEM;
@@
- isc_mem_get(MCTX, COUNT * sizeof(ELEM))
+ isc_mem_cget(MCTX, COUNT, sizeof(ELEM))
@@
expression MCTX, COUNT, ELEM;
@@
- isc_mem_get(MCTX, COUNT * sizeof(ELEM))
+ isc_mem_cget(MCTX, COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, COUNT;
type ELEM;
@@
- isc_mem_put(MCTX, OLD_PTR, COUNT * sizeof(ELEM))
+ isc_mem_cput(MCTX, OLD_PTR, COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, COUNT, ELEM;
@@
- isc_mem_put(MCTX, OLD_PTR, COUNT * sizeof(ELEM))
+ isc_mem_cput(MCTX, OLD_PTR, COUNT, sizeof(ELEM))
@@
expression MCTX, COUNT;
type ELEM;
@@
- isc_mem_get(MCTX, sizeof(ELEM) * COUNT)
+ isc_mem_cget(MCTX, COUNT, sizeof(ELEM))
@@
expression MCTX, COUNT, ELEM;
@@
- isc_mem_get(MCTX, sizeof(ELEM) * COUNT)
+ isc_mem_cget(MCTX, COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, COUNT;
type ELEM;
@@
- isc_mem_put(MCTX, OLD_PTR, sizeof(ELEM) * COUNT)
+ isc_mem_cput(MCTX, OLD_PTR, COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, COUNT, ELEM;
@@
- isc_mem_put(MCTX, OLD_PTR, sizeof(ELEM) * COUNT)
+ isc_mem_cput(MCTX, OLD_PTR, COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_COUNT, NEW_COUNT;
identifier OLD_SIZE, NEW_SIZE;
type ELEM;
@@
- size_t OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- size_t NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_COUNT, NEW_COUNT, ELEM;
identifier OLD_SIZE, NEW_SIZE;
@@
- size_t OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- size_t NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_COUNT, NEW_COUNT;
identifier OLD_SIZE, NEW_SIZE;
type ELEM;
@@
- size_t NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- size_t OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_COUNT, NEW_COUNT, ELEM;
identifier OLD_SIZE, NEW_SIZE;
@@
- size_t NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- size_t OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_SIZE, OLD_COUNT, NEW_SIZE, NEW_COUNT;
type ELEM;
@@
- OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_SIZE, OLD_COUNT, NEW_SIZE, NEW_COUNT, ELEM;
@@
- OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_SIZE, OLD_COUNT, NEW_SIZE, NEW_COUNT;
type ELEM;
@@
- NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, NEW_PTR, OLD_SIZE, OLD_COUNT, NEW_SIZE, NEW_COUNT, ELEM;
@@
- NEW_SIZE = NEW_COUNT * sizeof(ELEM);
- OLD_SIZE = OLD_COUNT * sizeof(ELEM);
- NEW_PTR = isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE);
+ NEW_PTR = isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM));
@@
expression MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT;
type ELEM;
@@
- isc_mem_reget(MCTX, OLD_PTR, OLD_COUNT * sizeof(ELEM), NEW_COUNT * sizeof(ELEM))
+ isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, ELEM;
@@
- isc_mem_reget(MCTX, OLD_PTR, OLD_COUNT * sizeof(ELEM), NEW_COUNT * sizeof(ELEM))
+ isc_mem_creget(MCTX, OLD_PTR, OLD_COUNT, NEW_COUNT, sizeof(ELEM))
@@
expression MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE;
@@
- isc_mem_reget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE)
+ isc_mem_creget(MCTX, OLD_PTR, OLD_SIZE, NEW_SIZE, sizeof(char))

View File

@ -1,17 +0,0 @@
@@
expression ptr, ctx, size;
@@
- ptr = isc_mem_get(ctx, size);
+ ptr = isc_mem_getx(ctx, size, ISC_MEM_ZERO);
...
- memset(ptr, 0, size);
@@
expression ptr, ctx, size;
@@
- ptr = isc_mem_allocate(ctx, size);
+ ptr = isc_mem_allocatex(ctx, size, ISC_MEM_ZERO);
...
- memset(ptr, 0, size);

View File

@ -70,8 +70,7 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) {
*/
acl->magic = DNS_ACL_MAGIC;
acl->elements = isc_mem_getx(mctx, n * sizeof(acl->elements[0]),
ISC_MEM_ZERO);
acl->elements = isc_mem_cget(mctx, n, sizeof(acl->elements[0]));
acl->alloc = n;
ISC_LIST_INIT(acl->ports_and_transports);
acl->port_proto_entries = 0;
@ -316,10 +315,9 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) {
newalloc = 4;
}
dest->elements = isc_mem_regetx(
dest->mctx, dest->elements,
dest->alloc * sizeof(dest->elements[0]),
newalloc * sizeof(dest->elements[0]), ISC_MEM_ZERO);
dest->elements = isc_mem_creget(dest->mctx, dest->elements,
dest->alloc, newalloc,
sizeof(dest->elements[0]));
dest->alloc = newalloc;
}
@ -521,8 +519,8 @@ destroy(dns_acl_t *dacl) {
}
}
if (dacl->elements != NULL) {
isc_mem_put(dacl->mctx, dacl->elements,
dacl->alloc * sizeof(dacl->elements[0]));
isc_mem_cput(dacl->mctx, dacl->elements, dacl->alloc,
sizeof(dacl->elements[0]));
}
if (dacl->name != NULL) {
isc_mem_free(dacl->mctx, dacl->name);

View File

@ -42,9 +42,8 @@ dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx,
if ((flags & DNS_COMPRESS_LARGE) != 0) {
size_t count = (1 << DNS_COMPRESS_LARGEBITS);
size_t size = count * sizeof(*set);
mask = count - 1;
set = isc_mem_allocatex(mctx, size, ISC_MEM_ZERO);
set = isc_mem_callocate(mctx, count, sizeof(*set));
} else {
mask = ARRAY_SIZE(cctx->smallset) - 1;
set = cctx->smallset;

View File

@ -560,7 +560,7 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
if (length == 0) {
return (ISC_R_SUCCESS);
}
v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *));
v = isc_mem_cget(diff->mctx, length, sizeof(dns_difftuple_t *));
for (i = 0; i < length; i++) {
p = ISC_LIST_HEAD(diff->tuples);
v[i] = p;
@ -571,7 +571,7 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
for (i = 0; i < length; i++) {
ISC_LIST_APPEND(diff->tuples, v[i], link);
}
isc_mem_put(diff->mctx, v, length * sizeof(dns_difftuple_t *));
isc_mem_cput(diff->mctx, v, length, sizeof(dns_difftuple_t *));
return (ISC_R_SUCCESS);
}

View File

@ -953,11 +953,11 @@ setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
v4ports = NULL;
if (nv4ports != 0) {
v4ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv4ports);
v4ports = isc_mem_cget(mgr->mctx, nv4ports, sizeof(in_port_t));
}
v6ports = NULL;
if (nv6ports != 0) {
v6ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv6ports);
v6ports = isc_mem_cget(mgr->mctx, nv6ports, sizeof(in_port_t));
}
do {
@ -973,15 +973,15 @@ setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
INSIST(i4 == nv4ports && i6 == nv6ports);
if (mgr->v4ports != NULL) {
isc_mem_put(mgr->mctx, mgr->v4ports,
mgr->nv4ports * sizeof(in_port_t));
isc_mem_cput(mgr->mctx, mgr->v4ports, mgr->nv4ports,
sizeof(in_port_t));
}
mgr->v4ports = v4ports;
mgr->nv4ports = nv4ports;
if (mgr->v6ports != NULL) {
isc_mem_put(mgr->mctx, mgr->v6ports,
mgr->nv6ports * sizeof(in_port_t));
isc_mem_cput(mgr->mctx, mgr->v6ports, mgr->nv6ports,
sizeof(in_port_t));
}
mgr->v6ports = v6ports;
mgr->nv6ports = nv6ports;
@ -1082,12 +1082,12 @@ dispatchmgr_destroy(dns_dispatchmgr_t *mgr) {
}
if (mgr->v4ports != NULL) {
isc_mem_put(mgr->mctx, mgr->v4ports,
mgr->nv4ports * sizeof(in_port_t));
isc_mem_cput(mgr->mctx, mgr->v4ports, mgr->nv4ports,
sizeof(in_port_t));
}
if (mgr->v6ports != NULL) {
isc_mem_put(mgr->mctx, mgr->v6ports,
mgr->nv6ports * sizeof(in_port_t));
isc_mem_cput(mgr->mctx, mgr->v6ports, mgr->nv6ports,
sizeof(in_port_t));
}
isc_nm_detach(&mgr->nm);
@ -1115,8 +1115,8 @@ qid_allocate(dns_dispatchmgr_t *mgr, dns_qid_t **qidp) {
*qid = (dns_qid_t){ .qid_nbuckets = DNS_QID_BUCKETS,
.qid_increment = DNS_QID_INCREMENT };
qid->qid_table = isc_mem_get(mgr->mctx,
DNS_QID_BUCKETS * sizeof(dns_displist_t));
qid->qid_table = isc_mem_cget(mgr->mctx, DNS_QID_BUCKETS,
sizeof(dns_displist_t));
for (i = 0; i < qid->qid_nbuckets; i++) {
ISC_LIST_INIT(qid->qid_table[i]);
}
@ -1137,8 +1137,8 @@ qid_destroy(isc_mem_t *mctx, dns_qid_t **qidp) {
REQUIRE(VALID_QID(qid));
qid->magic = 0;
isc_mem_put(mctx, qid->qid_table,
qid->qid_nbuckets * sizeof(dns_displist_t));
isc_mem_cput(mctx, qid->qid_table, qid->qid_nbuckets,
sizeof(dns_displist_t));
isc_mutex_destroy(&qid->lock);
isc_mem_put(mctx, qid, sizeof(*qid));
}
@ -2290,7 +2290,7 @@ dns_dispatchset_create(isc_mem_t *mctx, dns_dispatch_t *source,
isc_mutex_init(&dset->lock);
dset->dispatches = isc_mem_get(mctx, sizeof(dns_dispatch_t *) * n);
dset->dispatches = isc_mem_cget(mctx, n, sizeof(dns_dispatch_t *));
isc_mem_attach(mctx, &dset->mctx);
@ -2318,7 +2318,7 @@ fail:
for (j = 0; j < i; j++) {
dns_dispatch_detach(&(dset->dispatches[j])); /* DISPATCH004 */
}
isc_mem_put(mctx, dset->dispatches, sizeof(dns_dispatch_t *) * n);
isc_mem_cput(mctx, dset->dispatches, n, sizeof(dns_dispatch_t *));
if (dset->mctx == mctx) {
isc_mem_detach(&dset->mctx);
}
@ -2340,8 +2340,8 @@ dns_dispatchset_destroy(dns_dispatchset_t **dsetp) {
for (i = 0; i < dset->ndisp; i++) {
dns_dispatch_detach(&(dset->dispatches[i])); /* DISPATCH004 */
}
isc_mem_put(dset->mctx, dset->dispatches,
sizeof(dns_dispatch_t *) * dset->ndisp);
isc_mem_cput(dset->mctx, dset->dispatches, dset->ndisp,
sizeof(dns_dispatch_t *));
isc_mutex_destroy(&dset->lock);
isc_mem_putanddetach(&dset->mctx, dset, sizeof(dns_dispatchset_t));
}

View File

@ -101,14 +101,14 @@ rdataset_to_sortedarray(dns_rdataset_t *set, isc_mem_t *mctx,
n = dns_rdataset_count(set);
data = isc_mem_get(mctx, n * sizeof(dns_rdata_t));
data = isc_mem_cget(mctx, n, sizeof(dns_rdata_t));
dns_rdataset_init(&rdataset);
dns_rdataset_clone(set, &rdataset);
ret = dns_rdataset_first(&rdataset);
if (ret != ISC_R_SUCCESS) {
dns_rdataset_disassociate(&rdataset);
isc_mem_put(mctx, data, n * sizeof(dns_rdata_t));
isc_mem_cput(mctx, data, n, sizeof(dns_rdata_t));
return (ret);
}
@ -359,7 +359,7 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key,
sig.common.rdtype, &sig, buffer);
cleanup_array:
isc_mem_put(mctx, rdatas, nrdatas * sizeof(dns_rdata_t));
isc_mem_cput(mctx, rdatas, nrdatas, sizeof(dns_rdata_t));
cleanup_context:
dst_context_destroy(&ctx);
cleanup_databuf:
@ -573,7 +573,7 @@ again:
}
cleanup_array:
isc_mem_put(mctx, rdatas, nrdatas * sizeof(dns_rdata_t));
isc_mem_cput(mctx, rdatas, nrdatas, sizeof(dns_rdata_t));
cleanup_context:
dst_context_destroy(&ctx);
if (ret == DST_R_VERIFYFAILURE && !downcase) {

View File

@ -1033,7 +1033,9 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) {
REQUIRE(src != NULL);
REQUIRE(destp != NULL && *destp == NULL);
d = isc_mem_getx(mctx, sizeof(*d), ISC_MEM_ZERO);
d = isc_mem_get(mctx, sizeof(*d));
*d = (dns_dtdata_t){ 0 };
isc_mem_attach(mctx, &d->mctx);
d->frame = dnstap__dnstap__unpack(NULL, src->length, src->base);

View File

@ -34,8 +34,6 @@ dns_ipkeylist_init(dns_ipkeylist_t *ipkl) {
void
dns_ipkeylist_clear(isc_mem_t *mctx, dns_ipkeylist_t *ipkl) {
uint32_t i;
REQUIRE(ipkl != NULL);
if (ipkl->allocated == 0) {
@ -43,60 +41,55 @@ dns_ipkeylist_clear(isc_mem_t *mctx, dns_ipkeylist_t *ipkl) {
}
if (ipkl->addrs != NULL) {
isc_mem_put(mctx, ipkl->addrs,
ipkl->allocated * sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, ipkl->addrs, ipkl->allocated,
sizeof(ipkl->addrs[0]));
}
if (ipkl->sources != NULL) {
isc_mem_put(mctx, ipkl->sources,
ipkl->allocated * sizeof(isc_sockaddr_t));
}
if (ipkl->addrs != NULL) {
isc_mem_put(mctx, ipkl->addrs,
ipkl->allocated * sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, ipkl->sources, ipkl->allocated,
sizeof(ipkl->sources[0]));
}
if (ipkl->keys != NULL) {
for (i = 0; i < ipkl->allocated; i++) {
if (ipkl->keys[i] == NULL) {
continue;
for (size_t i = 0; i < ipkl->allocated; i++) {
if (ipkl->keys[i] != NULL) {
if (dns_name_dynamic(ipkl->keys[i])) {
dns_name_free(ipkl->keys[i], mctx);
}
isc_mem_put(mctx, ipkl->keys[i],
sizeof(*ipkl->keys[i]));
}
if (dns_name_dynamic(ipkl->keys[i])) {
dns_name_free(ipkl->keys[i], mctx);
}
isc_mem_put(mctx, ipkl->keys[i], sizeof(dns_name_t));
}
isc_mem_put(mctx, ipkl->keys,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_cput(mctx, ipkl->keys, ipkl->allocated,
sizeof(ipkl->keys[0]));
}
if (ipkl->tlss != NULL) {
for (i = 0; i < ipkl->allocated; i++) {
if (ipkl->tlss[i] == NULL) {
continue;
for (size_t i = 0; i < ipkl->allocated; i++) {
if (ipkl->tlss[i] != NULL) {
if (dns_name_dynamic(ipkl->tlss[i])) {
dns_name_free(ipkl->tlss[i], mctx);
}
isc_mem_put(mctx, ipkl->tlss[i],
sizeof(*ipkl->tlss[i]));
}
if (dns_name_dynamic(ipkl->tlss[i])) {
dns_name_free(ipkl->tlss[i], mctx);
}
isc_mem_put(mctx, ipkl->tlss[i], sizeof(dns_name_t));
}
isc_mem_put(mctx, ipkl->tlss,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_cput(mctx, ipkl->tlss, ipkl->allocated,
sizeof(ipkl->tlss[0]));
}
if (ipkl->labels != NULL) {
for (i = 0; i < ipkl->allocated; i++) {
if (ipkl->labels[i] == NULL) {
continue;
for (size_t i = 0; i < ipkl->allocated; i++) {
if (ipkl->labels[i] != NULL) {
if (dns_name_dynamic(ipkl->labels[i])) {
dns_name_free(ipkl->labels[i], mctx);
}
isc_mem_put(mctx, ipkl->labels[i],
sizeof(*ipkl->labels[i]));
}
if (dns_name_dynamic(ipkl->labels[i])) {
dns_name_free(ipkl->labels[i], mctx);
}
isc_mem_put(mctx, ipkl->labels[i], sizeof(dns_name_t));
}
isc_mem_put(mctx, ipkl->labels,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_cput(mctx, ipkl->labels, ipkl->allocated,
sizeof(ipkl->labels[0]));
}
dns_ipkeylist_init(ipkl);
@ -173,12 +166,6 @@ dns_ipkeylist_copy(isc_mem_t *mctx, const dns_ipkeylist_t *src,
isc_result_t
dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) {
isc_sockaddr_t *addrs = NULL;
isc_sockaddr_t *sources = NULL;
dns_name_t **keys = NULL;
dns_name_t **tlss = NULL;
dns_name_t **labels = NULL;
REQUIRE(ipkl != NULL);
REQUIRE(n > ipkl->count);
@ -186,70 +173,17 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) {
return (ISC_R_SUCCESS);
}
addrs = isc_mem_get(mctx, n * sizeof(isc_sockaddr_t));
sources = isc_mem_get(mctx, n * sizeof(isc_sockaddr_t));
keys = isc_mem_get(mctx, n * sizeof(dns_name_t *));
tlss = isc_mem_get(mctx, n * sizeof(dns_name_t *));
labels = isc_mem_get(mctx, n * sizeof(dns_name_t *));
if (ipkl->addrs != NULL) {
memmove(addrs, ipkl->addrs,
ipkl->allocated * sizeof(isc_sockaddr_t));
isc_mem_put(mctx, ipkl->addrs,
ipkl->allocated * sizeof(isc_sockaddr_t));
}
ipkl->addrs = addrs;
memset(&ipkl->addrs[ipkl->allocated], 0,
(n - ipkl->allocated) * sizeof(isc_sockaddr_t));
if (ipkl->sources != NULL) {
memmove(sources, ipkl->sources,
ipkl->allocated * sizeof(isc_sockaddr_t));
isc_mem_put(mctx, ipkl->sources,
ipkl->allocated * sizeof(isc_sockaddr_t));
}
ipkl->sources = sources;
memset(&ipkl->sources[ipkl->allocated], 0,
(n - ipkl->allocated) * sizeof(isc_sockaddr_t));
if (ipkl->keys) {
memmove(keys, ipkl->keys,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_put(mctx, ipkl->keys,
ipkl->allocated * sizeof(dns_name_t *));
}
ipkl->keys = keys;
memset(&ipkl->keys[ipkl->allocated], 0,
(n - ipkl->allocated) * sizeof(dns_name_t *));
if (ipkl->tlss) {
memmove(tlss, ipkl->tlss,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_put(mctx, ipkl->tlss,
ipkl->allocated * sizeof(dns_name_t *));
}
ipkl->tlss = tlss;
memset(&ipkl->tlss[ipkl->allocated], 0,
(n - ipkl->allocated) * sizeof(dns_name_t *));
if (ipkl->labels != NULL) {
memmove(labels, ipkl->labels,
ipkl->allocated * sizeof(dns_name_t *));
isc_mem_put(mctx, ipkl->labels,
ipkl->allocated * sizeof(dns_name_t *));
}
ipkl->labels = labels;
memset(&ipkl->labels[ipkl->allocated], 0,
(n - ipkl->allocated) * sizeof(dns_name_t *));
ipkl->addrs = isc_mem_creget(mctx, ipkl->addrs, ipkl->allocated, n,
sizeof(ipkl->addrs[0]));
ipkl->sources = isc_mem_creget(mctx, ipkl->sources, ipkl->allocated, n,
sizeof(ipkl->sources[0]));
ipkl->keys = isc_mem_creget(mctx, ipkl->keys, ipkl->allocated, n,
sizeof(ipkl->keys[0]));
ipkl->tlss = isc_mem_creget(mctx, ipkl->tlss, ipkl->allocated, n,
sizeof(ipkl->tlss[0]));
ipkl->labels = isc_mem_creget(mctx, ipkl->labels, ipkl->allocated, n,
sizeof(ipkl->labels[0]));
ipkl->allocated = n;
return (ISC_R_SUCCESS);
isc_mem_put(mctx, addrs, n * sizeof(isc_sockaddr_t));
isc_mem_put(mctx, sources, n * sizeof(isc_sockaddr_t));
isc_mem_put(mctx, tlss, n * sizeof(dns_name_t *));
isc_mem_put(mctx, keys, n * sizeof(dns_name_t *));
isc_mem_put(mctx, labels, n * sizeof(dns_name_t *));
return (ISC_R_NOMEMORY);
}

View File

@ -20,6 +20,7 @@
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/mem.h>
#include <isc/overflow.h>
#include <isc/result.h>
#include <isc/serial.h>
#include <isc/stdio.h>
@ -588,9 +589,9 @@ journal_file_create(isc_mem_t *mctx, bool downgrade, const char *filename) {
journal_header_encode(&header, &rawheader);
size = sizeof(journal_rawheader_t) +
index_size * sizeof(journal_rawpos_t);
ISC_CHECKED_MUL(index_size, sizeof(journal_rawpos_t));
mem = isc_mem_getx(mctx, size, ISC_MEM_ZERO);
mem = isc_mem_cget(mctx, 1, size);
memmove(mem, &rawheader, sizeof(rawheader));
result = isc_stdio_write(mem, 1, (size_t)size, fp, NULL);
@ -704,13 +705,14 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create,
unsigned int rawbytes;
unsigned char *p;
rawbytes = j->header.index_size * sizeof(journal_rawpos_t);
rawbytes = ISC_CHECKED_MUL(j->header.index_size,
sizeof(journal_rawpos_t));
j->rawindex = isc_mem_get(mctx, rawbytes);
CHECK(journal_read(j, j->rawindex, rawbytes));
j->index = isc_mem_get(mctx, j->header.index_size *
sizeof(journal_pos_t));
j->index = isc_mem_cget(mctx, j->header.index_size,
sizeof(journal_pos_t));
p = j->rawindex;
for (i = 0; i < j->header.index_size; i++) {
@ -746,12 +748,12 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create,
failure:
j->magic = 0;
if (j->rawindex != NULL) {
isc_mem_put(j->mctx, j->rawindex,
j->header.index_size * sizeof(journal_rawpos_t));
isc_mem_cput(j->mctx, j->rawindex, j->header.index_size,
sizeof(journal_rawpos_t));
}
if (j->index != NULL) {
isc_mem_put(j->mctx, j->index,
j->header.index_size * sizeof(journal_pos_t));
isc_mem_cput(j->mctx, j->index, j->header.index_size,
sizeof(journal_pos_t));
}
isc_mem_free(j->mctx, j->filename);
if (j->fp != NULL) {
@ -1159,7 +1161,8 @@ dns_journal_begin_transaction(dns_journal_t *j) {
*/
if (JOURNAL_EMPTY(&j->header)) {
offset = sizeof(journal_rawheader_t) +
j->header.index_size * sizeof(journal_rawpos_t);
ISC_CHECKED_MUL(j->header.index_size,
sizeof(journal_rawpos_t));
} else {
offset = j->header.end.offset;
}
@ -1443,12 +1446,12 @@ dns_journal_destroy(dns_journal_t **journalp) {
j->it.result = ISC_R_FAILURE;
dns_name_invalidate(&j->it.name);
if (j->rawindex != NULL) {
isc_mem_put(j->mctx, j->rawindex,
j->header.index_size * sizeof(journal_rawpos_t));
isc_mem_cput(j->mctx, j->rawindex, j->header.index_size,
sizeof(journal_rawpos_t));
}
if (j->index != NULL) {
isc_mem_put(j->mctx, j->index,
j->header.index_size * sizeof(journal_pos_t));
isc_mem_cput(j->mctx, j->index, j->header.index_size,
sizeof(journal_pos_t));
}
if (j->it.target.base != NULL) {
isc_mem_put(j->mctx, j->it.target.base, j->it.target.length);
@ -1914,7 +1917,8 @@ dns_journal_iter_init(dns_journal_t *j, uint32_t begin_serial,
* (We don't need to worry about the transaction header
* because that was already excluded from xdr.size.)
*/
*xfrsizep = size - (count * sizeof(journal_rawrrhdr_t));
*xfrsizep = size - (ISC_CHECKED_MUL(
count, sizeof(journal_rawrrhdr_t)));
}
result = ISC_R_SUCCESS;
@ -2531,7 +2535,8 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial,
* Cope with very small target sizes.
*/
indexend = sizeof(journal_rawheader_t) +
j1->header.index_size * sizeof(journal_rawpos_t);
ISC_CHECKED_MUL(j1->header.index_size,
sizeof(journal_rawpos_t));
if (target_size < DNS_JOURNAL_SIZE_MIN) {
target_size = DNS_JOURNAL_SIZE_MIN;
}
@ -2834,7 +2839,8 @@ index_to_disk(dns_journal_t *j) {
unsigned char *p;
unsigned int rawbytes;
rawbytes = j->header.index_size * sizeof(journal_rawpos_t);
rawbytes = ISC_CHECKED_MUL(j->header.index_size,
sizeof(journal_rawpos_t));
p = j->rawindex;
for (i = 0; i < j->header.index_size; i++) {

View File

@ -2123,11 +2123,11 @@ cleanup:
ISC_LIST_UNLINK(glue_list, this, link);
}
if (rdatalist != NULL) {
isc_mem_put(mctx, rdatalist,
rdatalist_size * sizeof(*rdatalist));
isc_mem_cput(mctx, rdatalist, rdatalist_size,
sizeof(*rdatalist));
}
if (rdata != NULL) {
isc_mem_put(mctx, rdata, rdata_size * sizeof(*rdata));
isc_mem_cput(mctx, rdata, rdata_size, sizeof(*rdata));
}
if (target_mem != NULL) {
isc_mem_put(mctx, target_mem, target_size);
@ -2599,7 +2599,7 @@ load_raw(dns_loadctx_t *lctx) {
cleanup:
if (rdata != NULL) {
isc_mem_put(mctx, rdata, rdata_size * sizeof(*rdata));
isc_mem_cput(mctx, rdata, rdata_size, sizeof(*rdata));
}
if (target_mem != NULL) {
isc_mem_put(mctx, target_mem, target_size);
@ -2753,10 +2753,7 @@ grow_rdatalist(int new_len, dns_rdatalist_t *oldlist, int old_len,
ISC_LIST(dns_rdatalist_t) save;
dns_rdatalist_t *this;
newlist = isc_mem_get(mctx, new_len * sizeof(*newlist));
if (newlist == NULL) {
return (NULL);
}
newlist = isc_mem_cget(mctx, new_len, sizeof(newlist[0]));
ISC_LIST_INIT(save);
while ((this = ISC_LIST_HEAD(*current)) != NULL) {
@ -2786,7 +2783,7 @@ grow_rdatalist(int new_len, dns_rdatalist_t *oldlist, int old_len,
INSIST(rdlcount == old_len);
if (oldlist != NULL) {
isc_mem_put(mctx, oldlist, old_len * sizeof(*oldlist));
isc_mem_cput(mctx, oldlist, old_len, sizeof(*oldlist));
}
return (newlist);
}
@ -2804,11 +2801,7 @@ grow_rdata(int new_len, dns_rdata_t *oldlist, int old_len,
dns_rdatalist_t *this;
dns_rdata_t *rdata;
newlist = isc_mem_get(mctx, new_len * sizeof(*newlist));
if (newlist == NULL) {
return (NULL);
}
memset(newlist, 0, new_len * sizeof(*newlist));
newlist = isc_mem_cget(mctx, new_len, sizeof(*newlist));
/*
* Copy current relinking.
@ -2851,7 +2844,7 @@ grow_rdata(int new_len, dns_rdata_t *oldlist, int old_len,
}
INSIST(rdcount == old_len || rdcount == 0);
if (oldlist != NULL) {
isc_mem_put(mctx, oldlist, old_len * sizeof(*oldlist));
isc_mem_cput(mctx, oldlist, old_len, sizeof(*oldlist));
}
return (newlist);
}

View File

@ -2116,7 +2116,8 @@ setgluecachestats(dns_db_t *db, isc_stats_t *stats) {
static dns_glue_t *
new_gluelist(isc_mem_t *mctx, dns_name_t *name) {
dns_glue_t *glue = isc_mem_getx(mctx, sizeof(*glue), ISC_MEM_ZERO);
dns_glue_t *glue = isc_mem_get(mctx, sizeof(*glue));
*glue = (dns_glue_t){ 0 };
dns_name_t *gluename = dns_fixedname_initname(&glue->fixedname);
isc_mem_attach(mctx, &glue->mctx);

View File

@ -1508,28 +1508,15 @@ create_node(isc_mem_t *mctx, const dns_name_t *name, dns_rbtnode_t **nodep) {
* Allocate space for the node structure, the name, and the offsets.
*/
nodelen = sizeof(dns_rbtnode_t) + region.length + labels + 1;
node = isc_mem_getx(mctx, nodelen, ISC_MEM_ZERO);
node->is_root = 0;
node->parent = NULL;
node->right = NULL;
node->left = NULL;
node->down = NULL;
node->data = NULL;
node->hashnext = NULL;
node->hashval = 0;
node = isc_mem_get(mctx, nodelen);
*node = (dns_rbtnode_t){
.nsec = DNS_RBT_NSEC_NORMAL,
.color = BLACK,
};
ISC_LINK_INIT(node, deadlink);
node->locknum = 0;
node->wild = 0;
node->dirty = 0;
isc_refcount_init(&node->references, 0);
node->find_callback = 0;
node->nsec = DNS_RBT_NSEC_NORMAL;
node->color = BLACK;
/*
* The following is stored to make reconstructing a name from the
@ -1582,8 +1569,6 @@ hash_add_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name) {
*/
static void
hashtable_new(dns_rbt_t *rbt, uint8_t index, uint8_t bits) {
size_t size;
REQUIRE(rbt->hashbits[index] == 0U);
REQUIRE(rbt->hashtable[index] == NULL);
REQUIRE(bits >= ISC_HASH_MIN_BITS);
@ -1591,15 +1576,16 @@ hashtable_new(dns_rbt_t *rbt, uint8_t index, uint8_t bits) {
rbt->hashbits[index] = bits;
size = ISC_HASHSIZE(rbt->hashbits[index]) * sizeof(dns_rbtnode_t *);
rbt->hashtable[index] = isc_mem_getx(rbt->mctx, size, ISC_MEM_ZERO);
rbt->hashtable[index] = isc_mem_cget(rbt->mctx,
ISC_HASHSIZE(rbt->hashbits[index]),
sizeof(dns_rbtnode_t *));
}
static void
hashtable_free(dns_rbt_t *rbt, uint8_t index) {
size_t size = ISC_HASHSIZE(rbt->hashbits[index]) *
sizeof(dns_rbtnode_t *);
isc_mem_put(rbt->mctx, rbt->hashtable[index], size);
isc_mem_cput(rbt->mctx, rbt->hashtable[index],
ISC_HASHSIZE(rbt->hashbits[index]),
sizeof(dns_rbtnode_t *));
rbt->hashbits[index] = 0U;
rbt->hashtable[index] = NULL;

View File

@ -530,9 +530,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log) {
for (i = 0; i < rbtdb->node_lock_count; i++) {
INSIST(ISC_LIST_EMPTY(rbtdb->lru[i]));
}
isc_mem_put(rbtdb->common.mctx, rbtdb->lru,
rbtdb->node_lock_count *
sizeof(dns_slabheaderlist_t));
isc_mem_cput(rbtdb->common.mctx, rbtdb->lru,
rbtdb->node_lock_count,
sizeof(dns_slabheaderlist_t));
}
/*
* Clean up dead node buckets.
@ -541,8 +541,8 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log) {
for (i = 0; i < rbtdb->node_lock_count; i++) {
INSIST(ISC_LIST_EMPTY(rbtdb->deadnodes[i]));
}
isc_mem_put(rbtdb->common.mctx, rbtdb->deadnodes,
rbtdb->node_lock_count * sizeof(dns_rbtnodelist_t));
isc_mem_cput(rbtdb->common.mctx, rbtdb->deadnodes,
rbtdb->node_lock_count, sizeof(dns_rbtnodelist_t));
}
/*
* Clean up heap objects.
@ -551,8 +551,8 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log) {
for (i = 0; i < rbtdb->node_lock_count; i++) {
isc_heap_destroy(&rbtdb->heaps[i]);
}
isc_mem_put(rbtdb->hmctx, rbtdb->heaps,
rbtdb->node_lock_count * sizeof(isc_heap_t *));
isc_mem_cput(rbtdb->hmctx, rbtdb->heaps, rbtdb->node_lock_count,
sizeof(isc_heap_t *));
}
if (rbtdb->rrsetstats != NULL) {
@ -565,8 +565,8 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log) {
isc_stats_detach(&rbtdb->gluecachestats);
}
isc_mem_put(rbtdb->common.mctx, rbtdb->node_locks,
rbtdb->node_lock_count * sizeof(rbtdb_nodelock_t));
isc_mem_cput(rbtdb->common.mctx, rbtdb->node_locks,
rbtdb->node_lock_count, sizeof(rbtdb_nodelock_t));
TREE_DESTROYLOCK(&rbtdb->tree_lock);
isc_refcount_destroy(&rbtdb->common.references);
if (rbtdb->loop != NULL) {

View File

@ -310,8 +310,8 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name,
if ((shuffle || sort)) {
if (count > MAX_SHUFFLE) {
in = isc_mem_get(cctx->mctx, count * sizeof(*in));
out = isc_mem_get(cctx->mctx, count * sizeof(*out));
in = isc_mem_cget(cctx->mctx, count, sizeof(*in));
out = isc_mem_cget(cctx->mctx, count, sizeof(*out));
if (in == NULL || out == NULL) {
shuffle = sort = false;
}
@ -467,10 +467,10 @@ rollback:
cleanup:
if (out != NULL && out != out_fixed) {
isc_mem_put(cctx->mctx, out, count * sizeof(*out));
isc_mem_cput(cctx->mctx, out, count, sizeof(*out));
}
if (in != NULL && in != in_fixed) {
isc_mem_put(cctx->mctx, in, count * sizeof(*in));
isc_mem_cput(cctx->mctx, in, count, sizeof(*in));
}
return (result);
}

View File

@ -224,7 +224,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
* Remember the original number of items.
*/
nalloc = nitems;
x = isc_mem_get(mctx, nalloc * sizeof(struct xrdata));
x = isc_mem_cget(mctx, nalloc, sizeof(struct xrdata));
/*
* Save all of the rdata members into an array.
@ -329,12 +329,11 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
* Allocate the memory, set up a buffer, start copying in
* data.
*/
rawbuf = isc_mem_getx(mctx, buflen, ISC_MEM_ZERO);
rawbuf = isc_mem_cget(mctx, 1, buflen);
#if DNS_RDATASET_FIXED
/* Allocate temporary offset table. */
offsettable = isc_mem_getx(mctx, nalloc * sizeof(unsigned int),
ISC_MEM_ZERO);
offsettable = isc_mem_cget(mctx, nalloc, sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
region->base = rawbuf;
@ -385,13 +384,13 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
#if DNS_RDATASET_FIXED
fillin_offsets(offsetbase, offsettable, nalloc);
isc_mem_put(mctx, offsettable, nalloc * sizeof(unsigned int));
isc_mem_cput(mctx, offsettable, nalloc, sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
result = ISC_R_SUCCESS;
free_rdatas:
isc_mem_put(mctx, x, nalloc * sizeof(struct xrdata));
isc_mem_cput(mctx, x, nalloc, sizeof(struct xrdata));
return (result);
}
@ -685,8 +684,8 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
*/
tcurrent += (tcount * 4);
offsettable = isc_mem_getx(
mctx, (ocount + oncount) * sizeof(unsigned int), ISC_MEM_ZERO);
offsettable = isc_mem_cget(mctx, (ocount + oncount),
sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
/*
@ -791,8 +790,8 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
#if DNS_RDATASET_FIXED
fillin_offsets(offsetbase, offsettable, ocount + oncount);
isc_mem_put(mctx, offsettable,
(ocount + oncount) * sizeof(unsigned int));
isc_mem_cput(mctx, offsettable, (ocount + oncount),
sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
INSIST(tcurrent == tstart + tlength);
@ -909,8 +908,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
#if DNS_RDATASET_FIXED
offsetbase = tcurrent;
offsettable = isc_mem_getx(mctx, mcount * sizeof(unsigned int),
ISC_MEM_ZERO);
offsettable = isc_mem_cget(mctx, mcount, sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
/*
@ -966,7 +964,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
#if DNS_RDATASET_FIXED
fillin_offsets(offsetbase, offsettable, mcount);
isc_mem_put(mctx, offsettable, mcount * sizeof(unsigned int));
isc_mem_cput(mctx, offsettable, mcount, sizeof(unsigned int));
#endif /* if DNS_RDATASET_FIXED */
INSIST(tcurrent == tstart + tlength);

View File

@ -72,8 +72,8 @@ dns_remote_init(dns_remote_t *remote, unsigned int count,
remote->mctx = mctx;
if (addrs != NULL) {
remote->addresses = isc_mem_get(mctx,
count * sizeof(isc_sockaddr_t));
remote->addresses = isc_mem_cget(mctx, count,
sizeof(isc_sockaddr_t));
memmove(remote->addresses, addrs,
count * sizeof(isc_sockaddr_t));
} else {
@ -81,16 +81,16 @@ dns_remote_init(dns_remote_t *remote, unsigned int count,
}
if (srcs != NULL) {
remote->sources = isc_mem_get(mctx,
count * sizeof(isc_sockaddr_t));
remote->sources = isc_mem_cget(mctx, count,
sizeof(isc_sockaddr_t));
memmove(remote->sources, srcs, count * sizeof(isc_sockaddr_t));
} else {
remote->sources = NULL;
}
if (keynames != NULL) {
remote->keynames = isc_mem_get(mctx,
count * sizeof(keynames[0]));
remote->keynames = isc_mem_cget(mctx, count,
sizeof(keynames[0]));
for (i = 0; i < count; i++) {
remote->keynames[i] = NULL;
}
@ -108,8 +108,8 @@ dns_remote_init(dns_remote_t *remote, unsigned int count,
}
if (tlsnames != NULL) {
remote->tlsnames = isc_mem_get(mctx,
count * sizeof(tlsnames[0]));
remote->tlsnames = isc_mem_cget(mctx, count,
sizeof(tlsnames[0]));
for (i = 0; i < count; i++) {
remote->tlsnames[i] = NULL;
}
@ -127,7 +127,7 @@ dns_remote_init(dns_remote_t *remote, unsigned int count,
}
if (mark) {
remote->ok = isc_mem_get(mctx, count * sizeof(bool));
remote->ok = isc_mem_cget(mctx, count, sizeof(bool));
for (i = 0; i < count; i++) {
remote->ok[i] = false;
}
@ -199,19 +199,19 @@ dns_remote_clear(dns_remote_t *remote) {
}
if (remote->ok != NULL) {
isc_mem_put(mctx, remote->ok, count * sizeof(bool));
isc_mem_cput(mctx, remote->ok, count, sizeof(bool));
remote->ok = NULL;
}
if (remote->addresses != NULL) {
isc_mem_put(mctx, remote->addresses,
count * sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, remote->addresses, count,
sizeof(isc_sockaddr_t));
remote->addresses = NULL;
}
if (remote->sources != NULL) {
isc_mem_put(mctx, remote->sources,
count * sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, remote->sources, count,
sizeof(isc_sockaddr_t));
remote->sources = NULL;
}
@ -225,8 +225,8 @@ dns_remote_clear(dns_remote_t *remote) {
remote->keynames[i] = NULL;
}
}
isc_mem_put(mctx, remote->keynames,
count * sizeof(dns_name_t *));
isc_mem_cput(mctx, remote->keynames, count,
sizeof(dns_name_t *));
remote->keynames = NULL;
}
@ -240,8 +240,8 @@ dns_remote_clear(dns_remote_t *remote) {
remote->tlsnames[i] = NULL;
}
}
isc_mem_put(mctx, remote->tlsnames,
count * sizeof(dns_name_t *));
isc_mem_cput(mctx, remote->tlsnames, count,
sizeof(dns_name_t *));
remote->tlsnames = NULL;
}

View File

@ -138,9 +138,8 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
isc_mem_attach(mctx, &requestmgr->mctx);
uint32_t nloops = isc_loopmgr_nloops(requestmgr->loopmgr);
requestmgr->requests = isc_mem_getx(
requestmgr->mctx, nloops * sizeof(requestmgr->requests[0]),
ISC_MEM_ZERO);
requestmgr->requests = isc_mem_cget(requestmgr->mctx, nloops,
sizeof(requestmgr->requests[0]));
for (size_t i = 0; i < nloops; i++) {
ISC_LIST_INIT(requestmgr->requests[i]);
@ -230,8 +229,8 @@ requestmgr_destroy(dns_requestmgr_t *requestmgr) {
for (size_t i = 0; i < nloops; i++) {
INSIST(ISC_LIST_EMPTY(requestmgr->requests[i]));
}
isc_mem_put(requestmgr->mctx, requestmgr->requests,
nloops * sizeof(requestmgr->requests[0]));
isc_mem_cput(requestmgr->mctx, requestmgr->requests, nloops,
sizeof(requestmgr->requests[0]));
if (requestmgr->dispatchv4 != NULL) {
dns_dispatch_detach(&requestmgr->dispatchv4);

View File

@ -10797,8 +10797,8 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name,
* into it if one exists.
*/
node->data = algorithms =
isc_mem_regetx(resolver->mctx, algorithms,
algorithms_len, len, ISC_MEM_ZERO);
isc_mem_creget(resolver->mctx, algorithms,
algorithms_len, len, sizeof(char));
/* store the new length */
algorithms[0] = len;
}
@ -10863,8 +10863,6 @@ isc_result_t
dns_resolver_disable_ds_digest(dns_resolver_t *resolver, const dns_name_t *name,
unsigned int digest_type) {
unsigned int len, mask;
unsigned char *tmp;
unsigned char *digests;
isc_result_t result;
dns_rbtnode_t *node = NULL;
@ -10892,7 +10890,7 @@ dns_resolver_disable_ds_digest(dns_resolver_t *resolver, const dns_name_t *name,
result = dns_rbt_addnode(resolver->digests, name, &node);
if (result == ISC_R_SUCCESS || result == ISC_R_EXISTS) {
digests = node->data;
unsigned char *digests = node->data;
/* If digests is set, digests[0] contains its length. */
if (digests == NULL || len > *digests) {
/*
@ -10901,7 +10899,8 @@ dns_resolver_disable_ds_digest(dns_resolver_t *resolver, const dns_name_t *name,
* bitfield and copy the old (smaller) bitfield
* into it if one exists.
*/
tmp = isc_mem_getx(resolver->mctx, len, ISC_MEM_ZERO);
unsigned char *tmp = isc_mem_cget(resolver->mctx, 1,
len);
if (digests != NULL) {
memmove(tmp, digests, *digests);
}

View File

@ -25,6 +25,7 @@
#include <isc/mem.h>
#include <isc/net.h>
#include <isc/netaddr.h>
#include <isc/overflow.h>
#include <isc/result.h>
#include <isc/util.h>
@ -259,8 +260,8 @@ expand_entries(dns_rrl_t *rrl, int newsize) {
}
bsize = sizeof(dns_rrl_block_t) +
(newsize - 1) * sizeof(dns_rrl_entry_t);
b = isc_mem_getx(rrl->mctx, bsize, ISC_MEM_ZERO);
ISC_CHECKED_MUL((newsize - 1), sizeof(dns_rrl_entry_t));
b = isc_mem_cget(rrl->mctx, 1, bsize);
b->size = bsize;
e = b->entries;
@ -298,7 +299,8 @@ free_old_hash(dns_rrl_t *rrl) {
isc_mem_put(rrl->mctx, old_hash,
sizeof(*old_hash) +
(old_hash->length - 1) * sizeof(old_hash->bins[0]));
ISC_CHECKED_MUL((old_hash->length - 1),
sizeof(old_hash->bins[0])));
rrl->old_hash = NULL;
}
@ -323,8 +325,9 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) {
}
new_bins = hash_divisor(new_bins);
hsize = sizeof(dns_rrl_hash_t) + (new_bins - 1) * sizeof(hash->bins[0]);
hash = isc_mem_getx(rrl->mctx, hsize, ISC_MEM_ZERO);
hsize = sizeof(dns_rrl_hash_t) +
ISC_CHECKED_MUL((new_bins - 1), sizeof(hash->bins[0]));
hash = isc_mem_cget(rrl->mctx, 1, hsize);
hash->length = new_bins;
rrl->hash_gen ^= 1;
hash->gen = rrl->hash_gen;
@ -1321,13 +1324,15 @@ dns_rrl_view_destroy(dns_view_t *view) {
h = rrl->hash;
if (h != NULL) {
isc_mem_put(rrl->mctx, h,
sizeof(*h) + (h->length - 1) * sizeof(h->bins[0]));
sizeof(*h) + ISC_CHECKED_MUL((h->length - 1),
sizeof(h->bins[0])));
}
h = rrl->old_hash;
if (h != NULL) {
isc_mem_put(rrl->mctx, h,
sizeof(*h) + (h->length - 1) * sizeof(h->bins[0]));
sizeof(*h) + ISC_CHECKED_MUL((h->length - 1),
sizeof(h->bins[0])));
}
isc_mem_putanddetach(&rrl->mctx, rrl, sizeof(*rrl));
@ -1340,10 +1345,12 @@ dns_rrl_init(dns_rrl_t **rrlp, dns_view_t *view, int min_entries) {
*rrlp = NULL;
rrl = isc_mem_getx(view->mctx, sizeof(*rrl), ISC_MEM_ZERO);
rrl = isc_mem_get(view->mctx, sizeof(*rrl));
*rrl = (dns_rrl_t){
.ts_bases[0] = isc_stdtime_now(),
};
isc_mem_attach(view->mctx, &rrl->mctx);
isc_mutex_init(&rrl->lock);
rrl->ts_bases[0] = isc_stdtime_now();
view->rrl = rrl;

View File

@ -65,7 +65,7 @@ dns_ssutable_create(isc_mem_t *mctx, dns_ssutable_t **tablep) {
REQUIRE(tablep != NULL && *tablep == NULL);
REQUIRE(mctx != NULL);
table = isc_mem_get(mctx, sizeof(dns_ssutable_t));
table = isc_mem_get(mctx, sizeof(*table));
isc_refcount_init(&table->references, 1);
table->mctx = NULL;
isc_mem_attach(mctx, &table->mctx);
@ -93,8 +93,8 @@ destroy(dns_ssutable_t *table) {
isc_mem_put(mctx, rule->name, sizeof(*rule->name));
}
if (rule->types != NULL) {
isc_mem_put(mctx, rule->types,
rule->ntypes * sizeof(*rule->types));
isc_mem_cput(mctx, rule->types, rule->ntypes,
sizeof(*rule->types));
}
ISC_LIST_UNLINK(table->rules, rule, link);
rule->magic = 0;
@ -169,7 +169,7 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant,
rule->ntypes = ntypes;
if (ntypes > 0) {
rule->types = isc_mem_get(mctx, ntypes * sizeof(*rule->types));
rule->types = isc_mem_cget(mctx, ntypes, sizeof(*rule->types));
memmove(rule->types, types, ntypes * sizeof(*rule->types));
} else {
rule->types = NULL;

View File

@ -26,6 +26,7 @@
#include <isc/loop.h>
#include <isc/md.h>
#include <isc/mutex.h>
#include <isc/overflow.h>
#include <isc/random.h>
#include <isc/ratelimiter.h>
#include <isc/refcount.h>
@ -1492,8 +1493,8 @@ zone_freedbargs(dns_zone_t *zone) {
for (i = 0; i < zone->db_argc; i++) {
isc_mem_free(zone->mctx, zone->db_argv[i]);
}
isc_mem_put(zone->mctx, zone->db_argv,
zone->db_argc * sizeof(*zone->db_argv));
isc_mem_cput(zone->mctx, zone->db_argv, zone->db_argc,
sizeof(*zone->db_argv));
}
zone->db_argc = 0;
zone->db_argv = NULL;
@ -1511,7 +1512,7 @@ dns_zone_getdbtype(dns_zone_t *zone, char ***argv, isc_mem_t *mctx) {
REQUIRE(argv != NULL && *argv == NULL);
LOCK_ZONE(zone);
size = (zone->db_argc + 1) * sizeof(char *);
size = ISC_CHECKED_MUL((zone->db_argc + 1), sizeof(char *));
for (i = 0; i < zone->db_argc; i++) {
size += strlen(zone->db_argv[i]) + 1;
}
@ -1520,7 +1521,7 @@ dns_zone_getdbtype(dns_zone_t *zone, char ***argv, isc_mem_t *mctx) {
tmp = mem;
tmp2 = mem;
base = mem;
tmp2 += (zone->db_argc + 1) * sizeof(char *);
tmp2 += ISC_CHECKED_MUL((zone->db_argc + 1), sizeof(char *));
for (i = 0; i < zone->db_argc; i++) {
*tmp++ = tmp2;
strlcpy(tmp2, zone->db_argv[i], size - (tmp2 - base));
@ -1546,7 +1547,7 @@ dns_zone_setdbtype(dns_zone_t *zone, unsigned int dbargc,
LOCK_ZONE(zone);
/* Set up a new database argument list. */
argv = isc_mem_get(zone->mctx, dbargc * sizeof(*argv));
argv = isc_mem_cget(zone->mctx, dbargc, sizeof(*argv));
for (i = 0; i < dbargc; i++) {
argv[i] = NULL;
}
@ -18258,9 +18259,8 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *netmgr,
isc_ratelimiter_create(loop, &zmgr->startupnotifyrl);
isc_ratelimiter_create(loop, &zmgr->startuprefreshrl);
zmgr->mctxpool = isc_mem_getx(zmgr->mctx,
zmgr->workers * sizeof(zmgr->mctxpool[0]),
ISC_MEM_ZERO);
zmgr->mctxpool = isc_mem_cget(zmgr->mctx, zmgr->workers,
sizeof(zmgr->mctxpool[0]));
for (size_t i = 0; i < zmgr->workers; i++) {
isc_mem_create(&zmgr->mctxpool[i]);
isc_mem_setname(zmgr->mctxpool[i], "zonemgr-mctxpool");
@ -18473,8 +18473,8 @@ zonemgr_free(dns_zonemgr_t *zmgr) {
isc_ratelimiter_detach(&zmgr->startupnotifyrl);
isc_ratelimiter_detach(&zmgr->startuprefreshrl);
isc_mem_put(zmgr->mctx, zmgr->mctxpool,
zmgr->workers * sizeof(zmgr->mctxpool[0]));
isc_mem_cput(zmgr->mctx, zmgr->mctxpool, zmgr->workers,
sizeof(zmgr->mctxpool[0]));
isc_rwlock_destroy(&zmgr->urlock);
isc_rwlock_destroy(&zmgr->rwlock);

View File

@ -404,11 +404,13 @@ record_nsec3(const vctx_t *vctx, const unsigned char *rawhash,
len = sizeof(*element) + nsec3->next_length * 2 + nsec3->salt_length;
element = isc_mem_getx(vctx->mctx, len, ISC_MEM_ZERO);
element->hash = nsec3->hash;
element->salt_length = nsec3->salt_length;
element->next_length = nsec3->next_length;
element->iterations = nsec3->iterations;
element = isc_mem_get(vctx->mctx, len);
*element = (struct nsec3_chain_fixed){
.hash = nsec3->hash,
.salt_length = nsec3->salt_length,
.next_length = nsec3->next_length,
.iterations = nsec3->iterations,
};
cp = (unsigned char *)(element + 1);
memmove(cp, nsec3->salt, nsec3->salt_length);
cp += nsec3->salt_length;
@ -1707,7 +1709,7 @@ verify_nodes(vctx_t *vctx, isc_result_t *vresult) {
zonecut = NULL;
count = dns_rdataset_count(&vctx->keyset);
dstkeys = isc_mem_get(vctx->mctx, sizeof(*dstkeys) * count);
dstkeys = isc_mem_cget(vctx->mctx, count, sizeof(*dstkeys));
for (result = dns_rdataset_first(&vctx->keyset);
result == ISC_R_SUCCESS; result = dns_rdataset_next(&vctx->keyset))
@ -1898,7 +1900,7 @@ done:
while (nkeys-- > 0U) {
dst_key_free(&dstkeys[nkeys]);
}
isc_mem_put(vctx->mctx, dstkeys, sizeof(*dstkeys) * count);
isc_mem_cput(vctx->mctx, dstkeys, count, sizeof(*dstkeys));
if (dbiter != NULL) {
dns_dbiterator_destroy(&dbiter);
}

View File

@ -218,7 +218,7 @@ restart:
if (*s == '\0') {
/* We have reached the end of the string. */
*argcp = n;
*argvp = isc_mem_get(mctx, n * sizeof(char *));
*argvp = isc_mem_cget(mctx, n, sizeof(char *));
} else {
char *p = s;
while (*p != ' ' && *p != '\t' && *p != '\0' && *p != '{') {

View File

@ -170,8 +170,6 @@ hashmap_dump_table(const isc_hashmap_t *hashmap, const uint8_t idx) {
static void
hashmap_create_table(isc_hashmap_t *hashmap, const uint8_t idx,
const uint8_t bits) {
size_t size;
REQUIRE(hashmap->tables[idx].hashbits == HASHMAP_NO_BITS);
REQUIRE(hashmap->tables[idx].table == NULL);
REQUIRE(bits >= HASHMAP_MIN_BITS);
@ -183,11 +181,9 @@ hashmap_create_table(isc_hashmap_t *hashmap, const uint8_t idx,
.size = HASHSIZE(bits),
};
size = hashmap->tables[idx].size *
sizeof(hashmap->tables[idx].table[0]);
hashmap->tables[idx].table = isc_mem_getx(hashmap->mctx, size,
ISC_MEM_ZERO);
hashmap->tables[idx].table =
isc_mem_cget(hashmap->mctx, hashmap->tables[idx].size,
sizeof(hashmap->tables[idx].table[0]));
}
static void

View File

@ -115,8 +115,8 @@ isc_heap_destroy(isc_heap_t **heapp) {
REQUIRE(VALID_HEAP(heap));
if (heap->array != NULL) {
isc_mem_put(heap->mctx, heap->array,
heap->size * sizeof(void *));
isc_mem_cput(heap->mctx, heap->array, heap->size,
sizeof(void *));
}
heap->magic = 0;
isc_mem_putanddetach(&heap->mctx, heap, sizeof(*heap));
@ -133,8 +133,8 @@ resize(isc_heap_t *heap) {
old_bytes = ISC_CHECKED_MUL(heap->size, sizeof(void *));
heap->size = new_size;
heap->array = isc_mem_reget(heap->mctx, heap->array, old_bytes,
new_bytes);
heap->array = isc_mem_creget(heap->mctx, heap->array, old_bytes,
new_bytes, sizeof(char));
}
static void

View File

@ -58,9 +58,8 @@
#define EXPONENTS(hg) (CHUNKS - DENORMALS(hg))
#define BUCKETS(hg) (EXPONENTS(hg) * MANTISSAS(hg))
#define MAXCHUNK(hg) EXPONENTS(hg)
#define CHUNKSIZE(hg) MANTISSAS(hg)
#define CHUNKBYTES(hg) (CHUNKSIZE(hg) * sizeof(hg_bucket_t))
#define MAXCHUNK(hg) EXPONENTS(hg)
#define CHUNKSIZE(hg) MANTISSAS(hg)
typedef atomic_uint_fast64_t hg_bucket_t;
typedef atomic_ptr(hg_bucket_t) hg_chunk_t;
@ -107,7 +106,8 @@ isc_histo_destroy(isc_histo_t **hgp) {
for (uint c = 0; c < CHUNKS; c++) {
if (hg->chunk[c] != NULL) {
isc_mem_put(hg->mctx, hg->chunk[c], CHUNKBYTES(hg));
isc_mem_cput(hg->mctx, hg->chunk[c], CHUNKSIZE(hg),
sizeof(hg_bucket_t));
}
}
isc_mem_putanddetach(&hg->mctx, hg, sizeof(*hg));
@ -232,15 +232,16 @@ key_to_new_bucket(isc_histo_t *hg, uint key) {
uint chunksize = CHUNKSIZE(hg);
uint chunk = key / chunksize;
uint bucket = key % chunksize;
size_t bytes = CHUNKBYTES(hg);
hg_bucket_t *old_cp = NULL;
hg_bucket_t *new_cp = isc_mem_getx(hg->mctx, bytes, ISC_MEM_ZERO);
hg_bucket_t *new_cp = isc_mem_cget(hg->mctx, CHUNKSIZE(hg),
sizeof(hg_bucket_t));
hg_chunk_t *cpp = &hg->chunk[chunk];
if (atomic_compare_exchange_strong_acq_rel(cpp, &old_cp, new_cp)) {
return (&new_cp[bucket]);
} else {
/* lost the race, so use the winner's chunk */
isc_mem_put(hg->mctx, new_cp, bytes);
isc_mem_cput(hg->mctx, new_cp, CHUNKSIZE(hg),
sizeof(hg_bucket_t));
return (&old_cp[bucket]);
}
}
@ -374,8 +375,8 @@ isc_histomulti_create(isc_mem_t *mctx, uint sigbits, isc_histomulti_t **hmp) {
uint size = isc_tid_count();
INSIST(size > 0);
isc_histomulti_t *hm = isc_mem_getx(
mctx, STRUCT_FLEX_SIZE(hm, hg, size), ISC_MEM_ZERO);
isc_histomulti_t *hm = isc_mem_cget(mctx, 1,
STRUCT_FLEX_SIZE(hm, hg, size));
*hm = (isc_histomulti_t){
.magic = HISTOMULTI_MAGIC,
.size = size,

View File

@ -199,7 +199,6 @@ maybe_rehash(isc_ht_t *ht, size_t newcount) {
static void
hashtable_new(isc_ht_t *ht, const uint8_t idx, const uint8_t bits) {
size_t size;
REQUIRE(ht->hashbits[idx] == HT_NO_BITS);
REQUIRE(ht->table[idx] == NULL);
REQUIRE(bits >= HT_MIN_BITS);
@ -208,15 +207,12 @@ hashtable_new(isc_ht_t *ht, const uint8_t idx, const uint8_t bits) {
ht->hashbits[idx] = bits;
ht->size[idx] = HASHSIZE(ht->hashbits[idx]);
size = ht->size[idx] * sizeof(isc_ht_node_t *);
ht->table[idx] = isc_mem_getx(ht->mctx, size, ISC_MEM_ZERO);
ht->table[idx] = isc_mem_cget(ht->mctx, ht->size[idx],
sizeof(isc_ht_node_t *));
}
static void
hashtable_free(isc_ht_t *ht, const uint8_t idx) {
size_t size = ht->size[idx] * sizeof(isc_ht_node_t *);
for (size_t i = 0; i < ht->size[idx]; i++) {
isc_ht_node_t *node = ht->table[idx][i];
while (node != NULL) {
@ -228,7 +224,9 @@ hashtable_free(isc_ht_t *ht, const uint8_t idx) {
}
}
isc_mem_put(ht->mctx, ht->table[idx], size);
isc_mem_cput(ht->mctx, ht->table[idx], ht->size[idx],
sizeof(isc_ht_node_t *));
ht->hashbits[idx] = HT_NO_BITS;
ht->table[idx] = NULL;
}

View File

@ -1147,8 +1147,8 @@ isc_buffer_reserve(isc_buffer_t *restrict dbuf, const unsigned int size) {
}
dbuf->dynamic = true;
} else {
dbuf->base = isc_mem_reget(dbuf->mctx, dbuf->base, dbuf->length,
len);
dbuf->base = isc_mem_creget(dbuf->mctx, dbuf->base,
dbuf->length, len, sizeof(char));
}
dbuf->length = (unsigned int)len;

View File

@ -21,6 +21,7 @@
#include <isc/attributes.h>
#include <isc/lang.h>
#include <isc/mutex.h>
#include <isc/overflow.h>
#include <isc/types.h>
ISC_LANG_BEGINDECLS
@ -128,47 +129,30 @@ extern unsigned int isc_mem_defaultflags;
*/
/*%
* Flags that can be passed to isc_mem_*x() variants of the macros.
*
* The definitions of the macros have been pulled directly from jemalloc.h
* and checked for consistency in mem.c.
*
*\li ISC_MEM_ALIGN(alignment) - use when you need aligned allocation,
*
* NOTE: Set the matching flag, when freeing aligned memory allocation.
*
*\li ISC_MEM_ZERO - fill the memory with zeroes before returning
*\li ISC__MEM_ZERO - fill the memory with zeroes before returning
*/
#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
#if __SIZEOF_POINTER__ == 4
#define ISC_MEM_ALIGN(a) ((int)(ffs((int)(a)) - 1))
#else
#define ISC_MEM_ALIGN(a) \
((int)(((size_t)(a) < (size_t)INT_MAX) \
? ffs((int)(a)) - 1 \
: ffs((int)(((size_t)(a)) >> 32)) + 31))
#endif
#else
#define ISC_MEM_ALIGN(a) (a & 0)
#endif
#define ISC_MEM_ZERO ((int)0x40)
#define ISC__MEM_ZERO ((int)0x40)
#define isc_mem_get(c, s) isc__mem_get((c), (s), 0 _ISC_MEM_FILELINE)
#define isc_mem_getx(c, s, f) isc__mem_get((c), (s), (f)_ISC_MEM_FILELINE)
#define isc_mem_get(c, s) isc__mem_get((c), (s), 0 _ISC_MEM_FILELINE)
#define isc_mem_cget(c, n, s) \
isc__mem_get((c), ISC_CHECKED_MUL((n), (s)), \
ISC__MEM_ZERO _ISC_MEM_FILELINE)
#define isc_mem_reget(c, p, o, n) \
isc__mem_reget((c), (p), (o), (n), 0 _ISC_MEM_FILELINE)
#define isc_mem_regetx(c, p, o, n, f) \
isc__mem_reget((c), (p), (o), (n), (f)_ISC_MEM_FILELINE)
#define isc_mem_creget(c, p, o, n, s) \
isc__mem_reget((c), (p), ISC_CHECKED_MUL((o), (s)), \
ISC_CHECKED_MUL((n), (s)), \
ISC__MEM_ZERO _ISC_MEM_FILELINE)
#define isc_mem_allocate(c, s) isc__mem_allocate((c), (s), 0 _ISC_MEM_FILELINE)
#define isc_mem_allocatex(c, s, f) \
isc__mem_allocate((c), (s), (f)_ISC_MEM_FILELINE)
#define isc_mem_callocate(c, n, s) \
isc__mem_callocate((c), (n), (s), 0 _ISC_MEM_FILELINE)
#define isc_mem_callocate(c, n, s) \
isc__mem_allocate((c), ISC_CHECKED_MUL((n), (s)), \
ISC__MEM_ZERO _ISC_MEM_FILELINE)
#define isc_mem_reallocate(c, p, s) \
isc__mem_reallocate((c), (p), (s), 0 _ISC_MEM_FILELINE)
#define isc_mem_reallocatex(c, p, s, f) \
isc__mem_reallocate((c), (p), (s), (f)_ISC_MEM_FILELINE)
#define isc_mem_strdup(c, p) isc__mem_strdup((c), (p)_ISC_MEM_FILELINE)
#define isc_mem_strndup(c, p, l) \
isc__mem_strndup((c), (p), (l)_ISC_MEM_FILELINE)
@ -179,31 +163,22 @@ extern unsigned int isc_mem_defaultflags;
isc__mem_put((c), (p), (s), 0 _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_putx(c, p, s, f) \
do { \
isc__mem_put((c), (p), (s), (f)_ISC_MEM_FILELINE); \
(p) = NULL; \
#define isc_mem_cput(c, p, n, s) \
do { \
isc__mem_put((c), (p), ISC_CHECKED_MUL((n), (s)), \
ISC__MEM_ZERO _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_putanddetach(c, p, s) \
do { \
isc__mem_putanddetach((c), (p), (s), 0 _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_putanddetachx(c, p, s, f) \
do { \
isc__mem_putanddetach((c), (p), (s), (f)_ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_free(c, p) \
do { \
isc__mem_free((c), (p), 0 _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_freex(c, p, f) \
do { \
isc__mem_free((c), (p), (f)_ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mempool_put(c, p) \
do { \
isc__mempool_put((c), (p)_ISC_MEM_FILELINE); \
@ -517,10 +492,6 @@ ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
void *
isc__mem_allocate(isc_mem_t *, size_t, int _ISC_MEM_FLARG);
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
void *
isc__mem_callocate(isc_mem_t *, size_t, size_t, int _ISC_MEM_FLARG);
ISC_ATTR_DEALLOCATOR_IDX(isc__mem_free, 2)
void *
isc__mem_reallocate(isc_mem_t *, void *, size_t, int _ISC_MEM_FLARG);

View File

@ -477,9 +477,8 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
}
if (lcfg->channellist_count > 0) {
isc_mem_put(mctx, lcfg->channellists,
lcfg->channellist_count *
sizeof(ISC_LIST(isc_logchannellist_t)));
isc_mem_cput(mctx, lcfg->channellists, lcfg->channellist_count,
sizeof(ISC_LIST(isc_logchannellist_t)));
}
lcfg->dynamic = false;
@ -974,13 +973,9 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
*/
static void
sync_channellist(isc_logconfig_t *lcfg) {
unsigned int bytes;
isc_log_t *lctx;
void *lists;
REQUIRE(VALID_CONFIG(lcfg));
lctx = lcfg->lctx;
isc_log_t *lctx = lcfg->lctx;
REQUIRE(lctx->category_count != 0);
@ -988,18 +983,10 @@ sync_channellist(isc_logconfig_t *lcfg) {
return;
}
bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t));
lcfg->channellists = isc_mem_creget(
lctx->mctx, lcfg->channellists, lcfg->channellist_count,
lctx->category_count, sizeof(ISC_LIST(isc_logchannellist_t)));
lists = isc_mem_getx(lctx->mctx, bytes, ISC_MEM_ZERO);
if (lcfg->channellist_count != 0) {
bytes = lcfg->channellist_count *
sizeof(ISC_LIST(isc_logchannellist_t));
memmove(lists, lcfg->channellists, bytes);
isc_mem_put(lctx->mctx, lcfg->channellists, bytes);
}
lcfg->channellists = lists;
lcfg->channellist_count = lctx->category_count;
}

View File

@ -339,8 +339,8 @@ isc_loopmgr_create(isc_mem_t *mctx, uint32_t nloops, isc_loopmgr_t **loopmgrp) {
isc_barrier_init(&loopmgr->starting, loopmgr->nloops);
isc_barrier_init(&loopmgr->stopping, loopmgr->nloops);
loopmgr->loops = isc_mem_get(
loopmgr->mctx, loopmgr->nloops * sizeof(loopmgr->loops[0]));
loopmgr->loops = isc_mem_cget(loopmgr->mctx, loopmgr->nloops,
sizeof(loopmgr->loops[0]));
for (size_t i = 0; i < loopmgr->nloops; i++) {
isc_loop_t *loop = &loopmgr->loops[i];
loop_init(loop, loopmgr, i);
@ -533,8 +533,8 @@ isc_loopmgr_destroy(isc_loopmgr_t **loopmgrp) {
isc_loop_t *loop = &loopmgr->loops[i];
loop_close(loop);
}
isc_mem_put(loopmgr->mctx, loopmgr->loops,
loopmgr->nloops * sizeof(loopmgr->loops[0]));
isc_mem_cput(loopmgr->mctx, loopmgr->loops, loopmgr->nloops,
sizeof(loopmgr->loops[0]));
isc_barrier_destroy(&loopmgr->starting);
isc_barrier_destroy(&loopmgr->stopping);

View File

@ -306,7 +306,8 @@ mem_get(isc_mem_t *ctx, size_t size, int flags) {
ret = mallocx(size, flags);
INSIST(ret != NULL);
if ((flags & ISC_MEM_ZERO) == 0 && (ctx->flags & ISC_MEMFLAG_FILL) != 0)
if ((flags & ISC__MEM_ZERO) == 0 &&
(ctx->flags & ISC_MEMFLAG_FILL) != 0)
{
memset(ret, 0xbe, size); /* Mnemonic for "beef". */
}
@ -338,7 +339,8 @@ mem_realloc(isc_mem_t *ctx, void *old_ptr, size_t old_size, size_t new_size,
new_ptr = rallocx(old_ptr, new_size, flags);
INSIST(new_ptr != NULL);
if ((flags & ISC_MEM_ZERO) == 0 && (ctx->flags & ISC_MEMFLAG_FILL) != 0)
if ((flags & ISC__MEM_ZERO) == 0 &&
(ctx->flags & ISC_MEMFLAG_FILL) != 0)
{
ssize_t diff_size = new_size - old_size;
void *diff_ptr = (uint8_t *)new_ptr + old_size;
@ -383,10 +385,7 @@ mem_initialize(void) {
* Check if the values copied from jemalloc still match
*/
#ifdef JEMALLOC_API_SUPPORTED
RUNTIME_CHECK(ISC_MEM_ZERO == MALLOCX_ZERO);
RUNTIME_CHECK(ISC_MEM_ALIGN(0) == MALLOCX_ALIGN(0));
RUNTIME_CHECK(ISC_MEM_ALIGN(sizeof(void *)) ==
MALLOCX_ALIGN(sizeof(void *)));
RUNTIME_CHECK(ISC__MEM_ZERO == MALLOCX_ZERO);
#endif /* JEMALLOC_API_SUPPORTED */
isc_mutex_init(&contextslock);
@ -416,7 +415,7 @@ mem_create(isc_mem_t **ctxp, unsigned int debugging, unsigned int flags) {
REQUIRE(ctxp != NULL && *ctxp == NULL);
ctx = mallocx(sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline()));
ctx = malloc(sizeof(*ctx));
INSIST(ctx != NULL);
*ctx = (isc_mem_t){
@ -441,8 +440,7 @@ mem_create(isc_mem_t **ctxp, unsigned int debugging, unsigned int flags) {
if ((ctx->debugging & ISC_MEM_DEBUGRECORD) != 0) {
unsigned int i;
ctx->debuglist =
mallocx((DEBUG_TABLE_COUNT * sizeof(debuglist_t)), 0);
ctx->debuglist = calloc(DEBUG_TABLE_COUNT, sizeof(debuglist_t));
INSIST(ctx->debuglist != NULL);
for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
@ -489,8 +487,7 @@ destroy(isc_mem_t *ctx) {
}
}
sdallocx(ctx->debuglist,
(DEBUG_TABLE_COUNT * sizeof(debuglist_t)), 0);
free(ctx->debuglist);
}
#endif /* if ISC_MEM_TRACKLINES */
@ -499,7 +496,7 @@ destroy(isc_mem_t *ctx) {
if (ctx->checkfree) {
INSIST(atomic_load(&ctx->inuse) == 0);
}
sdallocx(ctx, sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline()));
free(ctx);
}
void
@ -819,13 +816,6 @@ isc__mem_allocate(isc_mem_t *ctx, size_t size, int flags FLARG) {
return (ptr);
}
void *
isc__mem_callocate(isc_mem_t *ctx, size_t count, size_t size, int flags FLARG) {
size_t bytes = ISC_CHECKED_MUL(count, size);
return (isc__mem_allocate(ctx, bytes,
(flags | ISC_MEM_ZERO) FLARG_PASS));
}
void *
isc__mem_reget(isc_mem_t *ctx, void *old_ptr, size_t old_size, size_t new_size,
int flags FLARG) {

View File

@ -2956,8 +2956,8 @@ isc_nm_http_set_endpoints(isc_nmsocket_t *listener,
for (size_t i = 0; i < isc_loopmgr_nloops(loopmgr); i++) {
isc__networker_t *worker =
&listener->worker->netmgr->workers[i];
http_endpoints_data_t *data = isc_mem_getx(
worker->loop->mctx, sizeof(*data), ISC_MEM_ZERO);
http_endpoints_data_t *data = isc_mem_cget(worker->loop->mctx,
1, sizeof(*data));
isc__nmsocket_attach(listener, &data->listener);
isc_nm_http_endpoints_attach(eps, &data->endpoints);
@ -2981,8 +2981,8 @@ http_init_listener_endpoints(isc_nmsocket_t *listener,
INSIST(nworkers > 0);
listener->h2.listener_endpoints =
isc_mem_get(listener->worker->mctx,
sizeof(isc_nm_http_endpoints_t *) * nworkers);
isc_mem_cget(listener->worker->mctx, nworkers,
sizeof(isc_nm_http_endpoints_t *));
listener->h2.n_listener_endpoints = nworkers;
for (size_t i = 0; i < nworkers; i++) {
listener->h2.listener_endpoints[i] = NULL;
@ -3003,9 +3003,9 @@ http_cleanup_listener_endpoints(isc_nmsocket_t *listener) {
isc_nm_http_endpoints_detach(
&listener->h2.listener_endpoints[i]);
}
isc_mem_put(listener->worker->mctx, listener->h2.listener_endpoints,
sizeof(isc_nm_http_endpoints_t *) *
listener->h2.n_listener_endpoints);
isc_mem_cput(listener->worker->mctx, listener->h2.listener_endpoints,
listener->h2.n_listener_endpoints,
sizeof(isc_nm_http_endpoints_t *));
listener->h2.n_listener_endpoints = 0;
}

View File

@ -216,8 +216,8 @@ isc_netmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t **netmgrp) {
atomic_init(&netmgr->keepalive, 30000);
atomic_init(&netmgr->advertised, 30000);
netmgr->workers =
isc_mem_get(mctx, netmgr->nloops * sizeof(netmgr->workers[0]));
netmgr->workers = isc_mem_cget(mctx, netmgr->nloops,
sizeof(netmgr->workers[0]));
isc_loopmgr_teardown(loopmgr, netmgr_teardown, netmgr);
@ -269,8 +269,8 @@ nm_destroy(isc_nm_t **mgr0) {
isc_mutex_destroy(&mgr->lock);
isc_mem_put(mgr->mctx, mgr->workers,
mgr->nloops * sizeof(mgr->workers[0]));
isc_mem_cput(mgr->mctx, mgr->workers, mgr->nloops,
sizeof(mgr->workers[0]));
isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(*mgr));
}
@ -457,8 +457,8 @@ nmsocket_cleanup(void *arg) {
/*
* Now free them.
*/
isc_mem_put(sock->worker->mctx, sock->children,
sock->nchildren * sizeof(*sock));
isc_mem_cput(sock->worker->mctx, sock->children,
sock->nchildren, sizeof(*sock));
sock->children = NULL;
sock->nchildren = 0;
}
@ -2223,8 +2223,8 @@ set_tlsctx_workers(isc_nmsocket_t *listener, isc_tlsctx_t *tlsctx) {
for (size_t i = 0; i < nworkers; i++) {
isc__networker_t *worker =
&listener->worker->netmgr->workers[i];
settlsctx_data_t *data = isc_mem_getx(
worker->loop->mctx, sizeof(*data), ISC_MEM_ZERO);
settlsctx_data_t *data = isc_mem_cget(worker->loop->mctx, 1,
sizeof(*data));
isc__nmsocket_attach(listener, &data->listener);
isc_tlsctx_attach(tlsctx, &data->tlsctx);

View File

@ -444,7 +444,6 @@ isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog,
isc_quota_t *quota, isc_nmsocket_t **sockp) {
isc_nmsocket_t *sock = NULL;
size_t children_size = 0;
uv_os_sock_t fd = -1;
isc_result_t result = ISC_R_UNSET;
isc__networker_t *worker = &mgr->workers[0];
@ -462,9 +461,8 @@ isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
sock->nchildren = (workers == ISC_NM_LISTEN_ALL) ? (uint32_t)mgr->nloops
: workers;
children_size = sock->nchildren * sizeof(sock->children[0]);
sock->children = isc_mem_getx(worker->mctx, children_size,
ISC_MEM_ZERO);
sock->children = isc_mem_cget(worker->mctx, sock->nchildren,
sizeof(sock->children[0]));
isc__nmsocket_barrier_init(sock);

View File

@ -1451,8 +1451,8 @@ tls_init_listener_tlsctx(isc_nmsocket_t *listener, isc_tlsctx_t *ctx) {
(size_t)isc_loopmgr_nloops(listener->worker->netmgr->loopmgr);
INSIST(nworkers > 0);
listener->tlsstream.listener_tls_ctx = isc_mem_get(
listener->worker->mctx, sizeof(isc_tlsctx_t *) * nworkers);
listener->tlsstream.listener_tls_ctx = isc_mem_cget(
listener->worker->mctx, nworkers, sizeof(isc_tlsctx_t *));
listener->tlsstream.n_listener_tls_ctx = nworkers;
for (size_t i = 0; i < nworkers; i++) {
listener->tlsstream.listener_tls_ctx[i] = NULL;
@ -1472,10 +1472,9 @@ tls_cleanup_listener_tlsctx(isc_nmsocket_t *listener) {
for (size_t i = 0; i < listener->tlsstream.n_listener_tls_ctx; i++) {
isc_tlsctx_free(&listener->tlsstream.listener_tls_ctx[i]);
}
isc_mem_put(listener->worker->mctx,
listener->tlsstream.listener_tls_ctx,
sizeof(isc_tlsctx_t *) *
listener->tlsstream.n_listener_tls_ctx);
isc_mem_cput(
listener->worker->mctx, listener->tlsstream.listener_tls_ctx,
listener->tlsstream.n_listener_tls_ctx, sizeof(isc_tlsctx_t *));
listener->tlsstream.n_listener_tls_ctx = 0;
}

View File

@ -210,7 +210,6 @@ isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
isc_nm_recv_cb_t cb, void *cbarg, isc_nmsocket_t **sockp) {
isc_result_t result = ISC_R_UNSET;
isc_nmsocket_t *sock = NULL;
size_t children_size = 0;
uv_os_sock_t fd = -1;
isc__networker_t *worker = &mgr->workers[0];
@ -231,9 +230,8 @@ isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
sock->nchildren = (workers == ISC_NM_LISTEN_ALL) ? (uint32_t)mgr->nloops
: workers;
children_size = sock->nchildren * sizeof(sock->children[0]);
sock->children = isc_mem_getx(worker->mctx, children_size,
ISC_MEM_ZERO);
sock->children = isc_mem_cget(worker->mctx, sock->nchildren,
sizeof(sock->children[0]));
isc__nmsocket_barrier_init(sock);

View File

@ -57,9 +57,8 @@ isc_stats_detach(isc_stats_t **statsp) {
if (isc_refcount_decrement(&stats->references) == 1) {
isc_refcount_destroy(&stats->references);
isc_mem_put(stats->mctx, stats->counters,
sizeof(isc__atomic_statcounter_t) *
stats->ncounters);
isc_mem_cput(stats->mctx, stats->counters, stats->ncounters,
sizeof(isc__atomic_statcounter_t));
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
}
}
@ -183,8 +182,8 @@ isc_stats_resize(isc_stats_t **statsp, int ncounters) {
uint32_t counter = atomic_load_acquire(&stats->counters[i]);
atomic_store_release(&newcounters[i], counter);
}
isc_mem_put(stats->mctx, stats->counters,
sizeof(isc__atomic_statcounter_t) * stats->ncounters);
isc_mem_cput(stats->mctx, stats->counters, stats->ncounters,
sizeof(isc__atomic_statcounter_t));
stats->counters = newcounters;
stats->ncounters = ncounters;
}

View File

@ -62,7 +62,7 @@ isc_symtab_create(isc_mem_t *mctx, unsigned int size,
symtab->mctx = NULL;
isc_mem_attach(mctx, &symtab->mctx);
symtab->table = isc_mem_get(mctx, size * sizeof(eltlist_t));
symtab->table = isc_mem_cget(mctx, size, sizeof(eltlist_t));
for (i = 0; i < size; i++) {
INIT_LIST(symtab->table[i]);
}
@ -101,8 +101,8 @@ isc_symtab_destroy(isc_symtab_t **symtabp) {
isc_mem_put(symtab->mctx, elt, sizeof(*elt));
}
}
isc_mem_put(symtab->mctx, symtab->table,
symtab->size * sizeof(eltlist_t));
isc_mem_cput(symtab->mctx, symtab->table, symtab->size,
sizeof(eltlist_t));
symtab->magic = 0;
isc_mem_putanddetach(&symtab->mctx, symtab, sizeof(*symtab));
}
@ -177,7 +177,7 @@ grow_table(isc_symtab_t *symtab) {
newmax = newsize * 3 / 4;
INSIST(newsize > 0U && newmax > 0U);
newtable = isc_mem_get(symtab->mctx, newsize * sizeof(eltlist_t));
newtable = isc_mem_cget(symtab->mctx, newsize, sizeof(eltlist_t));
for (i = 0; i < newsize; i++) {
INIT_LIST(newtable[i]);
@ -197,8 +197,8 @@ grow_table(isc_symtab_t *symtab) {
}
}
isc_mem_put(symtab->mctx, symtab->table,
symtab->size * sizeof(eltlist_t));
isc_mem_cput(symtab->mctx, symtab->table, symtab->size,
sizeof(eltlist_t));
symtab->table = newtable;
symtab->size = newsize;

View File

@ -195,8 +195,7 @@ isc__tls_initialize(void) {
RUNTIME_CHECK(OPENSSL_init_ssl(opts, NULL) == 1);
#else
nlocks = CRYPTO_num_locks();
locks = isc_mem_getx(isc__tls_mctx, nlocks * sizeof(locks[0]),
ISC_MEM_ZERO);
locks = isc_mem_cget(isc__tls_mctx, nlocks, sizeof(locks[0]));
isc_mutexblock_init(locks, nlocks);
CRYPTO_set_locking_callback(isc__tls_lock_callback);
CRYPTO_THREADID_set_callback(isc__tls_set_thread_id);
@ -245,7 +244,7 @@ isc__tls_shutdown(void) {
if (locks != NULL) {
isc_mutexblock_destroy(locks, nlocks);
isc_mem_put(isc__tls_mctx, locks, nlocks * sizeof(locks[0]));
isc_mem_cput(isc__tls_mctx, locks, nlocks, sizeof(locks[0]));
locks = NULL;
}
#endif

View File

@ -77,7 +77,7 @@ isccc_symtab_create(unsigned int size,
if (symtab == NULL) {
return (ISC_R_NOMEMORY);
}
symtab->table = malloc(size * sizeof(eltlist_t));
symtab->table = calloc(size, sizeof(eltlist_t));
if (symtab->table == NULL) {
free(symtab);
return (ISC_R_NOMEMORY);

View File

@ -2425,19 +2425,10 @@ resume:
}
/* Grow stack? */
if (stackcount == pushed) {
void *newstack;
uint32_t newlen = stackcount + 16;
size_t newsize, oldsize;
newsize = newlen * sizeof(*stack);
oldsize = stackcount * sizeof(*stack);
newstack = isc_mem_get(mctx, newsize);
if (stackcount != 0) {
memmove(newstack, stack, oldsize);
isc_mem_put(mctx, stack, oldsize);
}
stack = newstack;
stackcount = newlen;
stack = isc_mem_creget(mctx, stack, stackcount,
stackcount + 16,
sizeof(stack[0]));
stackcount += 16;
}
stack[pushed++] = UNCONST(cfg_list_next(element));
goto newlist;
@ -2447,7 +2438,7 @@ resume:
goto resume;
}
if (stack != NULL) {
isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
isc_mem_cput(mctx, stack, stackcount, sizeof(*stack));
}
isc_symtab_destroy(&symtab);
*countp = count;

View File

@ -301,8 +301,8 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
}
CHECK(cfg_create_obj(pctx, type, &obj));
obj->value.tuple = isc_mem_get(pctx->mctx,
nfields * sizeof(cfg_obj_t *));
obj->value.tuple = isc_mem_cget(pctx->mctx, nfields,
sizeof(cfg_obj_t *));
for (f = fields, i = 0; f->name != NULL; f++, i++) {
obj->value.tuple[i] = NULL;
}
@ -401,8 +401,8 @@ free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj) {
CLEANUP_OBJ(obj->value.tuple[i]);
nfields++;
}
isc_mem_put(pctx->mctx, obj->value.tuple,
nfields * sizeof(cfg_obj_t *));
isc_mem_cput(pctx->mctx, obj->value.tuple, nfields,
sizeof(cfg_obj_t *));
}
bool

View File

@ -371,9 +371,9 @@ client_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
if (isc_buffer_base(buffer) == client->tcpbuf) {
size_t used = isc_buffer_usedlength(buffer);
client->tcpbuf = isc_mem_reget(client->manager->mctx,
client->tcpbuf,
client->tcpbuf_size, used);
client->tcpbuf =
isc_mem_creget(client->manager->mctx, client->tcpbuf,
client->tcpbuf_size, used, sizeof(char));
client->tcpbuf_size = used;
r.base = client->tcpbuf;
r.length = used;

View File

@ -322,8 +322,8 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx,
mgr->magic = IFMGR_MAGIC;
*mgrp = mgr;
mgr->clientmgrs = isc_mem_get(mgr->mctx,
mgr->ncpus * sizeof(mgr->clientmgrs[0]));
mgr->clientmgrs = isc_mem_cget(mgr->mctx, mgr->ncpus,
sizeof(mgr->clientmgrs[0]));
for (size_t i = 0; i < mgr->ncpus; i++) {
result = ns_clientmgr_create(mgr->sctx, mgr->loopmgr,
mgr->aclenv, (int)i,
@ -371,8 +371,8 @@ ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) {
for (size_t i = 0; i < mgr->ncpus; i++) {
ns_clientmgr_detach(&mgr->clientmgrs[i]);
}
isc_mem_put(mgr->mctx, mgr->clientmgrs,
mgr->ncpus * sizeof(mgr->clientmgrs[0]));
isc_mem_cput(mgr->mctx, mgr->clientmgrs, mgr->ncpus,
sizeof(mgr->clientmgrs[0]));
if (mgr->sctx != NULL) {
ns_server_detach(&mgr->sctx);

View File

@ -731,8 +731,8 @@ query_reset(ns_client_t *client, bool everything) {
ns_client_putrdataset(client, &client->query.dns64_sigaaaa);
}
if (client->query.dns64_aaaaok != NULL) {
isc_mem_put(client->manager->mctx, client->query.dns64_aaaaok,
client->query.dns64_aaaaoklen * sizeof(bool));
isc_mem_cput(client->manager->mctx, client->query.dns64_aaaaok,
client->query.dns64_aaaaoklen, sizeof(bool));
client->query.dns64_aaaaok = NULL;
client->query.dns64_aaaaoklen = 0;
}
@ -4962,7 +4962,7 @@ dns64_aaaaok(ns_client_t *client, dns_rdataset_t *rdataset,
}
count = dns_rdataset_count(rdataset);
aaaaok = isc_mem_get(client->manager->mctx, sizeof(bool) * count);
aaaaok = isc_mem_cget(client->manager->mctx, count, sizeof(bool));
isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
if (dns_dns64_aaaaok(dns64, &netaddr, client->signer, env, flags,
@ -4976,14 +4976,14 @@ dns64_aaaaok(ns_client_t *client, dns_rdataset_t *rdataset,
}
}
if (aaaaok != NULL) {
isc_mem_put(client->manager->mctx, aaaaok,
sizeof(bool) * count);
isc_mem_cput(client->manager->mctx, aaaaok, count,
sizeof(bool));
}
return (true);
}
if (aaaaok != NULL) {
isc_mem_put(client->manager->mctx, aaaaok,
sizeof(bool) * count);
isc_mem_cput(client->manager->mctx, aaaaok, count,
sizeof(bool));
}
return (false);
}

View File

@ -1700,8 +1700,7 @@ send_update(ns_client_t *client, dns_zone_t *zone) {
*/
if (ssutable != NULL) {
ruleslen = request->counts[DNS_SECTION_UPDATE];
rules = isc_mem_getx(mctx, sizeof(*rules) * ruleslen,
ISC_MEM_ZERO);
rules = isc_mem_cget(mctx, ruleslen, sizeof(*rules));
}
for (rule = 0,
@ -1912,7 +1911,7 @@ failure:
}
if (rules != NULL) {
isc_mem_put(mctx, rules, sizeof(*rules) * ruleslen);
isc_mem_cput(mctx, rules, ruleslen, sizeof(*rules));
}
if (ssutable != NULL) {
@ -3461,7 +3460,7 @@ common:
}
if (rules != NULL) {
isc_mem_put(mctx, rules, sizeof(*rules) * ruleslen);
isc_mem_cput(mctx, rules, ruleslen, sizeof(*rules));
}
if (ssutable != NULL) {

View File

@ -128,11 +128,10 @@ init_items(isc_mem_t *mctx) {
void *pval = NULL;
uint32_t ival = ~0U;
dns_qp_t *qp = NULL;
size_t bytes = ITEM_COUNT * sizeof(*item);
uint64_t start;
start = isc_time_monotonic();
item = isc_mem_allocatex(mctx, bytes, ISC_MEM_ZERO);
item = isc_mem_callocate(mctx, ITEM_COUNT, sizeof(*item));
/* ensure there are no duplicate names */
dns_qp_create(mctx, &item_methods, NULL, &qp);
@ -152,7 +151,7 @@ init_items(isc_mem_t *mctx) {
double time = (double)(isc_time_monotonic() - start) / NS_PER_SEC;
printf("%f sec to create %zu items, %f/sec %zu bytes\n", time,
ITEM_COUNT, ITEM_COUNT / time, bytes);
ITEM_COUNT, ITEM_COUNT / time, ITEM_COUNT * sizeof(*item));
}
static void
@ -821,7 +820,7 @@ startup(void *arg) {
uint32_t nloops = isc_loopmgr_nloops(loopmgr);
size_t bytes = sizeof(struct bench_state) +
sizeof(struct thread_args) * nloops;
struct bench_state *bctx = isc_mem_getx(mctx, bytes, ISC_MEM_ZERO);
struct bench_state *bctx = isc_mem_cget(mctx, 1, bytes);
*bctx = (struct bench_state){
.loopmgr = loopmgr,
@ -872,10 +871,11 @@ setup_tickers(isc_mem_t *mctx, isc_loopmgr_t *loopmgr) {
uint32_t nloops = isc_loopmgr_nloops(loopmgr);
for (uint32_t i = 0; i < nloops; i++) {
isc_loop_t *loop = isc_loop_get(loopmgr, i);
struct ticker *ticker = isc_mem_getx(mctx, sizeof(*ticker),
ISC_MEM_ZERO);
struct ticker *ticker = isc_mem_get(mctx, sizeof(*ticker));
*ticker = (struct ticker){
.loopmgr = loopmgr,
};
isc_mem_attach(mctx, &ticker->mctx);
ticker->loopmgr = loopmgr;
isc_loop_setup(loop, start_ticker, ticker);
isc_loop_teardown(loop, stop_ticker, ticker);
}

View File

@ -314,7 +314,7 @@ setup_test(void **state) {
setup_loopmgr(state);
nm = isc_mem_get(mctx, MAX_NM * sizeof(nm[0]));
nm = isc_mem_cget(mctx, MAX_NM, sizeof(nm[0]));
for (size_t i = 0; i < MAX_NM; i++) {
isc_netmgr_create(mctx, loopmgr, &nm[i]);
assert_non_null(nm[i]);
@ -348,7 +348,7 @@ teardown_test(void **state ISC_ATTR_UNUSED) {
isc_netmgr_destroy(&nm[i]);
assert_null(nm[i]);
}
isc_mem_put(mctx, nm, MAX_NM * sizeof(nm[0]));
isc_mem_cput(mctx, nm, MAX_NM, sizeof(nm[0]));
teardown_loopmgr(state);

View File

@ -48,9 +48,9 @@ test_hashmap_full(uint8_t init_bits, uintptr_t count) {
isc_result_t result;
test_node_t *nodes, *long_nodes, *upper_nodes;
nodes = isc_mem_get(mctx, count * sizeof(nodes[0]));
long_nodes = isc_mem_get(mctx, count * sizeof(nodes[0]));
upper_nodes = isc_mem_get(mctx, count * sizeof(nodes[0]));
nodes = isc_mem_cget(mctx, count, sizeof(nodes[0]));
long_nodes = isc_mem_cget(mctx, count, sizeof(nodes[0]));
upper_nodes = isc_mem_cget(mctx, count, sizeof(nodes[0]));
isc_hashmap_create(mctx, init_bits, ISC_HASHMAP_CASE_SENSITIVE,
&hashmap);
@ -172,9 +172,9 @@ test_hashmap_full(uint8_t init_bits, uintptr_t count) {
isc_hashmap_destroy(&hashmap);
assert_null(hashmap);
isc_mem_put(mctx, nodes, count * sizeof(nodes[0]));
isc_mem_put(mctx, long_nodes, count * sizeof(nodes[0]));
isc_mem_put(mctx, upper_nodes, count * sizeof(nodes[0]));
isc_mem_cput(mctx, nodes, count, sizeof(nodes[0]));
isc_mem_cput(mctx, long_nodes, count, sizeof(nodes[0]));
isc_mem_cput(mctx, upper_nodes, count, sizeof(nodes[0]));
}
static void
@ -187,7 +187,7 @@ test_hashmap_iterator(void) {
size_t tksize;
test_node_t *nodes;
nodes = isc_mem_get(mctx, count * sizeof(nodes[0]));
nodes = isc_mem_cget(mctx, count, sizeof(nodes[0]));
isc_hashmap_create(mctx, HASHMAP_MIN_BITS, ISC_HASHMAP_CASE_SENSITIVE,
&hashmap);
@ -310,7 +310,7 @@ test_hashmap_iterator(void) {
isc_hashmap_destroy(&hashmap);
assert_null(hashmap);
isc_mem_put(mctx, nodes, count * sizeof(nodes[0]));
isc_mem_cput(mctx, nodes, count, sizeof(nodes[0]));
}
/* 1 bit, 120 elements test, full rehashing */

View File

@ -126,72 +126,8 @@ ISC_RUN_TEST_IMPL(isc_mem_get) {
isc_mempool_destroy(&mp1);
}
#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
/* aligned memory system tests */
ISC_RUN_TEST_IMPL(isc_mem_get_align) {
isc_mem_t *mctx2 = NULL;
void *ptr;
size_t alignment;
uintptr_t aligned;
/* Check different alignment sizes up to the page size */
for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) {
size_t size = alignment / 2 - 1;
ptr = isc_mem_getx(mctx, size, ISC_MEM_ALIGN(alignment));
/* Check if the pointer is properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
/* Check if we can resize to <alignment, 2*alignment> range */
ptr = isc_mem_regetx(mctx, ptr, size, size * 2 + alignment,
ISC_MEM_ALIGN(alignment));
/* Check if the pointer is still properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
isc_mem_putx(mctx, ptr, size * 2 + alignment,
ISC_MEM_ALIGN(alignment));
/* Check whether isc_mem_putanddetach_detach() also works */
isc_mem_create(&mctx2);
ptr = isc_mem_getx(mctx2, size, ISC_MEM_ALIGN(alignment));
isc_mem_putanddetachx(&mctx2, ptr, size,
ISC_MEM_ALIGN(alignment));
}
}
/* aligned memory system tests */
ISC_RUN_TEST_IMPL(isc_mem_allocate_align) {
void *ptr;
size_t alignment;
uintptr_t aligned;
/* Check different alignment sizes up to the page size */
for (alignment = sizeof(void *); alignment <= 4096; alignment *= 2) {
size_t size = alignment / 2 - 1;
ptr = isc_mem_allocatex(mctx, size, ISC_MEM_ALIGN(alignment));
/* Check if the pointer is properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
/* Check if we can resize to <alignment, 2*alignment> range */
ptr = isc_mem_reallocatex(mctx, ptr, size * 2 + alignment,
ISC_MEM_ALIGN(alignment));
/* Check if the pointer is still properly aligned */
aligned = (((uintptr_t)ptr / alignment) * alignment);
assert_ptr_equal(aligned, (uintptr_t)ptr);
isc_mem_freex(mctx, ptr, ISC_MEM_ALIGN(alignment));
}
}
#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
/* zeroed memory system tests */
ISC_RUN_TEST_IMPL(isc_mem_get_zero) {
ISC_RUN_TEST_IMPL(isc_mem_cget_zero) {
uint8_t *ptr;
bool zeroed;
uint8_t expected[4096] = { 0 };
@ -211,12 +147,12 @@ ISC_RUN_TEST_IMPL(isc_mem_get_zero) {
return;
}
ptr = isc_mem_getx(mctx, sizeof(expected), ISC_MEM_ZERO);
ptr = isc_mem_cget(mctx, 1, sizeof(expected));
assert_memory_equal(ptr, expected, sizeof(expected));
isc_mem_put(mctx, ptr, sizeof(expected));
}
ISC_RUN_TEST_IMPL(isc_mem_allocate_zero) {
ISC_RUN_TEST_IMPL(isc_mem_callocate_zero) {
uint8_t *ptr;
bool zeroed;
uint8_t expected[4096] = { 0 };
@ -236,7 +172,7 @@ ISC_RUN_TEST_IMPL(isc_mem_allocate_zero) {
return;
}
ptr = isc_mem_allocatex(mctx, sizeof(expected), ISC_MEM_ZERO);
ptr = isc_mem_callocate(mctx, 1, sizeof(expected));
assert_memory_equal(ptr, expected, sizeof(expected));
isc_mem_free(mctx, ptr);
}
@ -315,26 +251,26 @@ ISC_RUN_TEST_IMPL(isc_mem_reget) {
isc_mem_put(mctx, data, REGET_SHRINK_SIZE);
}
ISC_RUN_TEST_IMPL(isc_mem_reallocatex) {
ISC_RUN_TEST_IMPL(isc_mem_reallocate) {
uint8_t *data = NULL;
/* test that we can reallocate NULL */
data = isc_mem_reallocatex(mctx, NULL, REGET_INIT_SIZE, 0);
data = isc_mem_reallocate(mctx, NULL, REGET_INIT_SIZE);
assert_non_null(data);
isc_mem_free(mctx, data);
/* test that we can re-get a zero-length allocation */
data = isc_mem_allocatex(mctx, 0, 0);
data = isc_mem_allocate(mctx, 0);
assert_non_null(data);
data = isc_mem_reallocatex(mctx, data, REGET_INIT_SIZE, 0);
data = isc_mem_reallocate(mctx, data, REGET_INIT_SIZE);
assert_non_null(data);
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
data[i] = i % UINT8_MAX;
}
data = isc_mem_reallocatex(mctx, data, REGET_GROW_SIZE, 0);
data = isc_mem_reallocate(mctx, data, REGET_GROW_SIZE);
assert_non_null(data);
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
@ -345,7 +281,7 @@ ISC_RUN_TEST_IMPL(isc_mem_reallocatex) {
data[i - 1] = i % UINT8_MAX;
}
data = isc_mem_reallocatex(mctx, data, REGET_SHRINK_SIZE, 0);
data = isc_mem_reallocate(mctx, data, REGET_SHRINK_SIZE);
assert_non_null(data);
for (size_t i = REGET_SHRINK_SIZE; i > 0; i--) {
@ -544,16 +480,12 @@ ISC_RUN_TEST_IMPL(isc_mem_benchmark) {
ISC_TEST_LIST_START
ISC_TEST_ENTRY(isc_mem_get)
#if defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC)
ISC_TEST_ENTRY(isc_mem_get_align)
ISC_TEST_ENTRY(isc_mem_allocate_align)
#endif /* defined(HAVE_MALLOC_NP_H) || defined(HAVE_JEMALLOC) */
ISC_TEST_ENTRY(isc_mem_get_zero)
ISC_TEST_ENTRY(isc_mem_allocate_zero)
ISC_TEST_ENTRY(isc_mem_cget_zero)
ISC_TEST_ENTRY(isc_mem_callocate_zero)
ISC_TEST_ENTRY(isc_mem_inuse)
ISC_TEST_ENTRY(isc_mem_zeroget)
ISC_TEST_ENTRY(isc_mem_reget)
ISC_TEST_ENTRY(isc_mem_reallocatex)
ISC_TEST_ENTRY(isc_mem_reallocate)
#if ISC_MEM_TRACKLINES
ISC_TEST_ENTRY(isc_mem_noflags)

View File

@ -115,7 +115,7 @@ isc_mutex_thread(void *arg) {
}
ISC_RUN_TEST_IMPL(isc_mutex_benchmark) {
isc_thread_t *threads = isc_mem_get(mctx, sizeof(*threads) * workers);
isc_thread_t *threads = isc_mem_cget(mctx, workers, sizeof(*threads));
isc_time_t ts1, ts2;
double t;
int dc;
@ -201,7 +201,7 @@ ISC_RUN_TEST_IMPL(isc_mutex_benchmark) {
isc_mutex_destroy(&lock);
isc_mem_put(mctx, threads, sizeof(*threads) * workers);
isc_mem_cput(mctx, threads, workers, sizeof(*threads));
}
ISC_TEST_LIST_START

View File

@ -520,7 +520,7 @@ blockfrequency(uint16_t *values, size_t length) {
assert_true(numblocks < 100);
assert_true(numbits >= (mbits * numblocks));
pi = isc_mem_get(mctx, numblocks * sizeof(double));
pi = isc_mem_cget(mctx, numblocks, sizeof(double));
assert_non_null(pi);
for (i = 0; i < numblocks; i++) {
@ -543,7 +543,7 @@ blockfrequency(uint16_t *values, size_t length) {
chi_square *= 4 * mbits;
isc_mem_put(mctx, pi, numblocks * sizeof(double));
isc_mem_cput(mctx, pi, numblocks, sizeof(double));
p_value = igamc(numblocks * 0.5, chi_square * 0.5);

View File

@ -105,7 +105,8 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_enqueue) { assert_int_equal(ticks, 1); }
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_enqueue) {
isc_result_t result;
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
result = isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
&rlstat->event);
@ -123,8 +124,9 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_enqueue_shutdown) {
}
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_enqueue_shutdown) {
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
isc_rlevent_t *event = NULL;
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
expect_assert_failure(
isc_ratelimiter_enqueue(NULL, mainloop, tick, NULL, &event));
@ -156,8 +158,9 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_dequeue) { /* */
}
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_dequeue) {
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
isc_rlevent_t *fake = isc_mem_get(mctx, sizeof(*fake));
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
&rlstat->event),
@ -225,12 +228,14 @@ ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_pertick_interval) {
isc_ratelimiter_setpertic(rl, 1);
isc_ratelimiter_setpushpop(rl, false);
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tock, rlstat,
&rlstat->event),
ISC_R_SUCCESS);
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
&rlstat->event),
ISC_R_SUCCESS);
@ -258,12 +263,14 @@ ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_pushpop) {
isc_ratelimiter_setpertic(rl, 2);
isc_ratelimiter_setpushpop(rl, true);
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tock, rlstat,
&rlstat->event),
ISC_R_SUCCESS);
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
*rlstat = (rlstat_t){ 0 };
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
&rlstat->event),
ISC_R_SUCCESS);

View File

@ -71,7 +71,7 @@ setup_env(void **unused __attribute__((__unused__))) {
}
assert_int_not_equal(delay_loop, 0);
rnd = isc_mem_get(mctx, loops * sizeof(rnd[0]));
rnd = isc_mem_cget(mctx, loops, sizeof(rnd[0]));
for (size_t i = 0; i < loops; i++) {
rnd[i] = (uint8_t)isc_random_uniform(100);
}
@ -81,7 +81,7 @@ setup_env(void **unused __attribute__((__unused__))) {
static int
teardown_env(void **state __attribute__((__unused__))) {
isc_mem_put(mctx, rnd, loops * sizeof(rnd[0]));
isc_mem_cput(mctx, rnd, loops, sizeof(rnd[0]));
return (0);
}
@ -316,7 +316,7 @@ isc__rwlock_benchmark(isc_thread_t *threads, unsigned int nthreads,
}
ISC_RUN_TEST_IMPL(isc_rwlock_benchmark) {
isc_thread_t *threads = isc_mem_get(mctx, sizeof(*threads) * workers);
isc_thread_t *threads = isc_mem_cget(mctx, workers, sizeof(*threads));
memset(threads, 0, sizeof(*threads) * workers);
@ -330,7 +330,7 @@ ISC_RUN_TEST_IMPL(isc_rwlock_benchmark) {
isc__rwlock_benchmark(threads, nthreads, 100);
}
isc_mem_put(mctx, threads, sizeof(*threads) * workers);
isc_mem_cput(mctx, threads, workers, sizeof(*threads));
}
ISC_TEST_LIST_START

View File

@ -124,7 +124,7 @@ isc_spinlock_thread(void *arg) {
}
ISC_RUN_TEST_IMPL(isc_spinlock_benchmark) {
isc_thread_t *threads = isc_mem_get(mctx, sizeof(*threads) * workers);
isc_thread_t *threads = isc_mem_cget(mctx, workers, sizeof(*threads));
isc_time_t ts1, ts2;
double t;
int dc;
@ -211,7 +211,7 @@ ISC_RUN_TEST_IMPL(isc_spinlock_benchmark) {
isc_spinlock_destroy(&lock);
isc_mem_put(mctx, threads, sizeof(*threads) * workers);
isc_mem_cput(mctx, threads, workers, sizeof(*threads));
}
ISC_TEST_LIST_START