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

Do extra manual isc_mem_cget() conversions

Some of the cases weren't caught by the coccinelle and there were some
places where cget+memmove() could get converted to simple creget().
This commit is contained in:
Ondřej Surý 2023-08-23 10:00:12 +02:00
parent 89fcb6f897
commit 55c29b8d83
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
22 changed files with 95 additions and 191 deletions

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

View File

@ -2823,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);
@ -2835,8 +2834,8 @@ lookforsoa:
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

@ -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

@ -173,12 +173,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 +180,17 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) {
return (ISC_R_SUCCESS);
}
addrs = isc_mem_cget(mctx, n, sizeof(isc_sockaddr_t));
sources = isc_mem_cget(mctx, n, sizeof(isc_sockaddr_t));
keys = isc_mem_cget(mctx, n, sizeof(dns_name_t *));
tlss = isc_mem_cget(mctx, n, sizeof(dns_name_t *));
labels = isc_mem_cget(mctx, n, sizeof(dns_name_t *));
if (ipkl->addrs != NULL) {
memmove(addrs, ipkl->addrs,
ipkl->allocated * sizeof(isc_sockaddr_t));
isc_mem_cput(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_cput(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_cput(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_cput(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_cput(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(isc_sockaddr_t));
ipkl->sources = isc_mem_creget(mctx, ipkl->addrs, ipkl->allocated, n,
sizeof(isc_sockaddr_t));
ipkl->keys = isc_mem_creget(mctx, ipkl->addrs, ipkl->allocated, n,
sizeof(dns_name_t *));
ipkl->tlss = isc_mem_creget(mctx, ipkl->addrs, ipkl->allocated, n,
sizeof(dns_name_t *));
ipkl->labels = isc_mem_creget(mctx, ipkl->addrs, ipkl->allocated, n,
sizeof(dns_name_t *));
ipkl->allocated = n;
return (ISC_R_SUCCESS);
isc_mem_cput(mctx, addrs, n, sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, sources, n, sizeof(isc_sockaddr_t));
isc_mem_cput(mctx, tlss, n, sizeof(dns_name_t *));
isc_mem_cput(mctx, keys, n, sizeof(dns_name_t *));
isc_mem_cput(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,7 +589,7 @@ 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);
memmove(mem, &rawheader, sizeof(rawheader));
@ -704,7 +705,8 @@ 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));
@ -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;
}
@ -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

@ -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

@ -1582,8 +1582,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 +1589,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

@ -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]);

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,7 +260,7 @@ expand_entries(dns_rrl_t *rrl, int newsize) {
}
bsize = sizeof(dns_rrl_block_t) +
(newsize - 1) * sizeof(dns_rrl_entry_t);
ISC_CHECKED_MUL((newsize - 1), sizeof(dns_rrl_entry_t));
b = isc_mem_getx(rrl->mctx, bsize, ISC_MEM_ZERO);
b->size = bsize;
@ -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,7 +325,8 @@ 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]);
hsize = sizeof(dns_rrl_hash_t) +
ISC_CHECKED_MUL((new_bins - 1), sizeof(hash->bins[0]));
hash = isc_mem_getx(rrl->mctx, hsize, ISC_MEM_ZERO);
hash->length = new_bins;
rrl->hash_gen ^= 1;
@ -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));

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);

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>
@ -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));

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

@ -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]);
}
}

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

@ -973,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);
@ -987,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

@ -441,8 +441,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 +488,7 @@ destroy(isc_mem_t *ctx) {
}
}
sdallocx(ctx->debuglist,
(DEBUG_TABLE_COUNT * sizeof(debuglist_t)), 0);
free(ctx->debuglist);
}
#endif /* if ISC_MEM_TRACKLINES */

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

@ -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

@ -195,8 +195,7 @@ isc__tls_initialize(void) {
RUNTIME_CHECK(OPENSSL_init_ssl(opts, NULL) == 1);
#else
nlocks = CRYPTO_num_locks();
locks = isc_mem_cgetx(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);

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;

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