]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Do extra manual isc_mem_cget() conversions
authorOndřej Surý <ondrej@isc.org>
Wed, 23 Aug 2023 08:00:12 +0000 (10:00 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 31 Aug 2023 20:08:35 +0000 (22:08 +0200)
Some of the cases weren't caught by the coccinelle and there were some
places where cget+memmove() could get converted to simple creget().

22 files changed:
bin/named/config.c
bin/nsupdate/nsupdate.c
lib/dns/compress.c
lib/dns/ipkeylist.c
lib/dns/journal.c
lib/dns/master.c
lib/dns/rbt.c
lib/dns/request.c
lib/dns/rrl.c
lib/dns/ssu.c
lib/dns/zone.c
lib/isc/hashmap.c
lib/isc/histo.c
lib/isc/ht.c
lib/isc/log.c
lib/isc/mem.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/udp.c
lib/isc/tls.c
lib/isccc/symtab.c
lib/isccfg/check.c
tests/bench/qpmulti.c

index bffd8bdcf3fe0a689027a4adb1961de044e1511a..c0ac33a8b829dd1794b4322dcb63d6d8c5b5e51a 100644 (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 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 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) {                                      \
+               array = isc_mem_creget(mctx, array, oldlen, newlen, \
+                                      sizeof(array[0]));           \
+               oldlen = newlen;                                    \
        }
 
 isc_result_t
index 47ff134f3a8dfb046855c27954de0d6e0b7e23da..3e673f493da4e86f07e3546724e24d1e427025e8 100644 (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) {
index f176263dd991eded48987281bd56a4a056f0c1bc..2fbdf212f55b32b6f42ec786edb7ba0017d25246 100644 (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;
index d4e2869f42dd1dc6c63739fdcbd7cdbda205158d..d0a2b015e6cb72f3a6f5fd1d971b679b07f65d53 100644 (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);
 }
index 7961c667cb226affc2500239810c59c0a371417d..12e1713ae3b62ea6abc5989a6001a7b379ff7d47 100644 (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++) {
index 8d1b966a29a914b53b75dc83fdd2396bf2eba4f5..b8f1bfaff629f1e0476feef6eae16aebf5c70288 100644 (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);
 }
index 9109a9ce057724835dcb6aee7f65b190ef686746..62385f939d0a14587c4f01cc135da2148530e5f1 100644 (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;
index 5abc1c5f40c8e635804de4c2e36e10494742a13c..a5a729157073c568a33a2eac180028de61221212 100644 (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]);
 
index 308a64b9550e5773fecfddfa3db59d2e8af04c46..328e9506d485370d8c24a2c62d1aeb7aad85e876 100644 (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));
index e7c2ff4f3dbdd9d86ed796f03ea7385bb74ee5d1..2f43c9e3f1653a87a819fdc9187a58a1142eb0f5 100644 (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);
index e9c8d534906271ce5cb9223accb86fb61bd8e950..d65680b9ebb80c2935dac27799365dc974180202 100644 (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));
index 12c1822b9b1a97235a0ac40a0a88da7fb17ce745..b54e61137e8702ac4447248b815a6835c682144d 100644 (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
index b44dab0cb42cde05405361ad512dc1db680d3549..a16a4244e64c7a06dd0ec2d7073889531844fcbd 100644 (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]);
        }
 }
index 6f2ff5e60ac83bcb72f85bb4a55039120e61f62c..f602e7195acfb529c052bbb3caae96b9d75f530d 100644 (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;
 }
index b0a9f620d526f87e8f6d2760ddda67e8adad7d66..9db7a91d775db0de3b2ae86470b63f0864866600 100644 (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));
-
-       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 = isc_mem_creget(
+               lctx->mctx, lcfg->channellists, lcfg->channellist_count,
+               lctx->category_count, sizeof(ISC_LIST(isc_logchannellist_t)));
 
-       lcfg->channellists = lists;
        lcfg->channellist_count = lctx->category_count;
 }
 
index 4199428f2e52fcb0cb20f075da1a72aa7a7b7302..2689965a0dfe47b5f4eb2ee77e3482cf4f296323 100644 (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 */
 
index 10a71a6d2ea3e8966edcba466d3300eaa5717761..db07202b80f693d41b553773ac7ee6495eebdd78 100644 (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);
 
index 56ea1e5fa8c5ed932f21330fad5fccfb7358eb8f..4671b9f9f0a5c0e02b54124acbf94f8b4fea4c08 100644 (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);
 
index 2f15f3fd2ccd544cc1e24d6fdfbadab6ac0abd51..b740af7023a673e3c0d565cb4557d82eca29bfff 100644 (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);
index 15ab4fc2ca0f06ccfb2917b9cfb46fe1809df5ba..c6757c7f685b95dcfa58c0e06613e318442335aa 100644 (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);
index a1740814dc5793bb4a6161141fed30dd7601ced6..96720174eca8e5edf9230b918437f2284c4c42bd 100644 (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;
index f45e38257728ee136b02f9f3355f5c8e3c0ff660..39b56e3e13d15fc37ffd94bc11ff3a02c3f73810 100644 (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