]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Cleanup the isc_mempool_get() calls
authorOndřej Surý <ondrej@isc.org>
Wed, 24 Feb 2021 21:47:08 +0000 (22:47 +0100)
committerOndřej Surý <ondrej@sury.org>
Wed, 3 Mar 2021 14:32:01 +0000 (15:32 +0100)
Use the semantic patch to cleanup the error handling from
isc_mempool_get() since it can't fail now and it will always return a
valid chunk of memory.

bin/dig/dighost.c
bin/plugins/filter-aaaa.c
bin/tests/system/hooks/driver/test-async.c
lib/dns/adb.c
lib/dns/dispatch.c
lib/dns/message.c

index ff72aea4a559578c41c027ffd94abe6745a3f285..acd7225e9e9998b0e2cf1855338ec4a83093ad5d 100644 (file)
@@ -2434,9 +2434,6 @@ setup_lookup(dig_lookup_t *lookup) {
        }
 
        lookup->sendspace = isc_mempool_get(commctx);
-       if (lookup->sendspace == NULL) {
-               fatal("memory allocation failure");
-       }
 
        result = dns_compress_init(&cctx, -1, mctx);
        check_result(result, "dns_compress_init");
index f530b596ad119b463c8f176142263cb4158476b5..31e6e7cfd49e24e41fe40b32e92d103d97d85e11 100644 (file)
@@ -516,9 +516,6 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) {
        isc_result_t result;
 
        client_state = isc_mempool_get(inst->datapool);
-       if (client_state == NULL) {
-               return;
-       }
 
        client_state->mode = NONE;
        client_state->flags = 0;
index f1669e9fe956128fc767b06e5fb6f4c3e98fc295..68bf5d9db5061bf29f0659ac787c89157a804982 100644 (file)
@@ -231,9 +231,6 @@ client_state_create(const query_ctx_t *qctx, async_instance_t *inst) {
        isc_result_t result;
 
        state = isc_mempool_get(inst->datapool);
-       if (state == NULL) {
-               return;
-       }
 
        LOCK(&inst->hlock);
        result = isc_ht_add(inst->ht, (const unsigned char *)&qctx->client,
index fbe347d35088636620b26e0af498c1933f8afc92..3665bf0ea14c49dde75a7128d34ee313f41086b5 100644 (file)
@@ -1735,9 +1735,6 @@ new_adbname(dns_adb_t *adb, const dns_name_t *dnsname) {
        dns_adbname_t *name;
 
        name = isc_mempool_get(adb->nmp);
-       if (name == NULL) {
-               return (NULL);
-       }
 
        dns_name_init(&name->name, NULL);
        dns_name_dup(dnsname, adb->mctx, &name->name);
@@ -1807,9 +1804,6 @@ new_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
        dns_adbnamehook_t *nh;
 
        nh = isc_mempool_get(adb->nhmp);
-       if (nh == NULL) {
-               return (NULL);
-       }
 
        nh->magic = DNS_ADBNAMEHOOK_MAGIC;
        nh->entry = entry;
@@ -1839,9 +1833,6 @@ new_adblameinfo(dns_adb_t *adb, const dns_name_t *qname,
        dns_adblameinfo_t *li;
 
        li = isc_mempool_get(adb->limp);
-       if (li == NULL) {
-               return (NULL);
-       }
 
        dns_name_init(&li->qname, NULL);
        dns_name_dup(qname, adb->mctx, &li->qname);
@@ -1875,9 +1866,6 @@ new_adbentry(dns_adb_t *adb) {
        dns_adbentry_t *e;
 
        e = isc_mempool_get(adb->emp);
-       if (e == NULL) {
-               return (NULL);
-       }
 
        e->magic = DNS_ADBENTRY_MAGIC;
        e->lock_bucket = DNS_ADB_INVALIDBUCKET;
@@ -1956,9 +1944,6 @@ new_adbfind(dns_adb_t *adb) {
        dns_adbfind_t *h;
 
        h = isc_mempool_get(adb->ahmp);
-       if (h == NULL) {
-               return (NULL);
-       }
 
        /*
         * Public members.
@@ -1994,9 +1979,6 @@ new_adbfetch(dns_adb_t *adb) {
        dns_adbfetch_t *f;
 
        f = isc_mempool_get(adb->afmp);
-       if (f == NULL) {
-               return (NULL);
-       }
 
        f->magic = 0;
        f->fetch = NULL;
@@ -2056,9 +2038,6 @@ new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
        dns_adbaddrinfo_t *ai;
 
        ai = isc_mempool_get(adb->aimp);
-       if (ai == NULL) {
-               return (NULL);
-       }
 
        ai->magic = DNS_ADBADDRINFO_MAGIC;
        ai->sockaddr = entry->sockaddr;
index d2f6e2c826e2b986af90093fb19fe2b4e36d7580..ada4cce97779de592a2945af487b95b9fc04b0ab 100644 (file)
@@ -704,9 +704,6 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest,
                dispsock->socket = NULL;
        } else {
                dispsock = isc_mempool_get(mgr->spool);
-               if (dispsock == NULL) {
-                       return (ISC_R_NOMEMORY);
-               }
 
                disp->nsockets++;
                dispsock->socket = NULL;
@@ -951,12 +948,6 @@ allocate_udp_buffer(dns_dispatch_t *disp) {
 
        temp = isc_mempool_get(bpool);
 
-       if (temp == NULL) {
-               LOCK(&disp->mgr->buffer_lock);
-               disp->mgr->buffers--;
-               UNLOCK(&disp->mgr->buffer_lock);
-       }
-
        return (temp);
 }
 
index 602edc7a1063bad35a4329f07d09e79f54713667..425d8d05ef100ed27bbfd6d8bf0bacb7cf4937c4 100644 (file)
@@ -1009,9 +1009,6 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
 
        for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
                name = isc_mempool_get(msg->namepool);
-               if (name == NULL) {
-                       return (ISC_R_NOMEMORY);
-               }
                free_name = true;
 
                offsets = newoffsets(msg);
@@ -1108,10 +1105,6 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
                        goto cleanup;
                }
                rdataset = isc_mempool_get(msg->rdspool);
-               if (rdataset == NULL) {
-                       result = ISC_R_NOMEMORY;
-                       goto cleanup;
-               }
 
                /*
                 * Convert rdatalist to rdataset, and attach the latter to
@@ -1260,9 +1253,6 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
                istsig = false;
 
                name = isc_mempool_get(msg->namepool);
-               if (name == NULL) {
-                       return (ISC_R_NOMEMORY);
-               }
                free_name = true;
 
                offsets = newoffsets(msg);
@@ -1564,10 +1554,6 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
 
                if (result == ISC_R_NOTFOUND) {
                        rdataset = isc_mempool_get(msg->rdspool);
-                       if (rdataset == NULL) {
-                               result = ISC_R_NOMEMORY;
-                               goto cleanup;
-                       }
                        free_rdataset = true;
 
                        rdatalist = newrdatalist(msg);
@@ -2577,9 +2563,6 @@ dns_message_gettempname(dns_message_t *msg, dns_name_t **item) {
        REQUIRE(item != NULL && *item == NULL);
 
        *item = isc_mempool_get(msg->namepool);
-       if (*item == NULL) {
-               return (ISC_R_NOMEMORY);
-       }
        dns_name_init(*item, NULL);
 
        return (ISC_R_SUCCESS);
@@ -2617,9 +2600,6 @@ dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
        REQUIRE(item != NULL && *item == NULL);
 
        *item = isc_mempool_get(msg->rdspool);
-       if (*item == NULL) {
-               return (ISC_R_NOMEMORY);
-       }
 
        dns_rdataset_init(*item);