]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Refactor the isc_mempool_create() usage using the semantic patch
authorOndřej Surý <ondrej@isc.org>
Sun, 2 Feb 2020 07:50:41 +0000 (08:50 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 3 Feb 2020 07:27:16 +0000 (08:27 +0100)
The isc_mempool_create() function now cannot fail with ISC_R_MEMORY.
This commit removes all the checks on the return code using the semantic
patch from previous commit, as isc_mempool_create() now returns void.

bin/dig/dighost.c
bin/plugins/filter-aaaa.c
bin/tests/optional/adb_test.c
bin/tests/optional/mempool_test.c
lib/dns/adb.c
lib/dns/dispatch.c
lib/dns/message.c
lib/isc/tests/mem_test.c

index b9bc11603bfd9b35cd8d49687b8b3cda8466be87..c92ea2903a05b2f6393e3d151cb8473fd573c409 100644 (file)
@@ -1396,8 +1396,7 @@ setup_libs(void) {
        check_result(result, "dst_lib_init");
        is_dst_up = true;
 
-       result = isc_mempool_create(mctx, COMMSIZE, &commctx);
-       check_result(result, "isc_mempool_create");
+       isc_mempool_create(mctx, COMMSIZE, &commctx);
        isc_mempool_setname(commctx, "COMMPOOL");
        /*
         * 6 and 2 set as reasonable parameters for 3 or 4 nameserver
index f24e7d45c529e0d05c8cfb5e94f461501d0eed5b..5a647e57b1ca276ee1a59fa4620e5d7bbef7f58e 100644 (file)
@@ -374,8 +374,8 @@ plugin_register(const char *parameters,
                                       cfg_line, mctx, lctx, actx));
        }
 
-       CHECK(isc_mempool_create(mctx, sizeof(filter_data_t),
-                                &inst->datapool));
+       isc_mempool_create(mctx, sizeof(filter_data_t),
+                                &inst->datapool);
        CHECK(isc_ht_init(&inst->ht, mctx, 16));
        isc_mutex_init(&inst->hlock);
 
index 859c772effcb3c1be00920b0ac78922abf55f58e..41295874388bb2ed9a197860fd97bd03eff51794 100644 (file)
@@ -297,8 +297,8 @@ main(int argc, char **argv) {
        isc_mem_create(&mctx);
 
        cmp = NULL;
-       RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
-                     == ISC_R_SUCCESS);
+       isc_mempool_create(mctx, sizeof(client_t), &cmp)
+                     ;
        isc_mempool_setname(cmp, "adb test clients");
 
        result = isc_log_create(mctx, &lctx, &lcfg);
index bc359f41f3edaa068e648fce52156546be55ef6b..485443c9098d270cbd6d449cd5f251ca370c7c4b 100644 (file)
@@ -34,10 +34,10 @@ main(int argc, char *argv[]) {
        isc_mem_create(&mctx);
 
        mp1 = NULL;
-       RUNTIME_CHECK(isc_mempool_create(mctx, 24, &mp1) == ISC_R_SUCCESS);
+       isc_mempool_create(mctx, 24, &mp1);
 
        mp2 = NULL;
-       RUNTIME_CHECK(isc_mempool_create(mctx, 31, &mp2) == ISC_R_SUCCESS);
+       isc_mempool_create(mctx, 31, &mp2);
 
        isc_mempool_associatelock(mp1, &lock);
        isc_mempool_associatelock(mp2, &lock);
index 98b013dff5585cf7330db6790fe83042343e2e4c..d7f25494dbd356bf616245fef4fd0477080ea008 100644 (file)
@@ -2646,9 +2646,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
         * Memory pools
         */
 #define MPINIT(t, p, n) do { \
-       result = isc_mempool_create(mem, sizeof(t), &(p)); \
-       if (result != ISC_R_SUCCESS) \
-               goto fail2; \
+       isc_mempool_create(mem, sizeof(t), &(p)); \
        isc_mempool_setfreemax((p), FREE_ITEMS); \
        isc_mempool_setfillcount((p), FILL_COUNT); \
        isc_mempool_setname((p), n); \
index 47ff2bc9bc00faed7b4a897a6bfcce34b53c0194..d1b3189138396a5ee0d505c52ac66c7577ae5496 100644 (file)
@@ -1762,25 +1762,16 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp)
        isc_mutex_init(&mgr->spool_lock);
 
        mgr->depool = NULL;
-       if (isc_mempool_create(mgr->mctx, sizeof(dns_dispatchevent_t),
-                              &mgr->depool) != ISC_R_SUCCESS) {
-               result = ISC_R_NOMEMORY;
-               goto kill_locks;
-       }
+       isc_mempool_create(mgr->mctx, sizeof(dns_dispatchevent_t),
+                              &mgr->depool);
 
        mgr->rpool = NULL;
-       if (isc_mempool_create(mgr->mctx, sizeof(dns_dispentry_t),
-                              &mgr->rpool) != ISC_R_SUCCESS) {
-               result = ISC_R_NOMEMORY;
-               goto kill_depool;
-       }
+       isc_mempool_create(mgr->mctx, sizeof(dns_dispentry_t),
+                              &mgr->rpool);
 
        mgr->dpool = NULL;
-       if (isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t),
-                              &mgr->dpool) != ISC_R_SUCCESS) {
-               result = ISC_R_NOMEMORY;
-               goto kill_rpool;
-       }
+       isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t),
+                              &mgr->dpool);
 
        isc_mempool_setname(mgr->depool, "dispmgr_depool");
        isc_mempool_setmaxalloc(mgr->depool, 32768);
@@ -1835,11 +1826,8 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp)
 
  kill_dpool:
        isc_mempool_destroy(&mgr->dpool);
- kill_rpool:
        isc_mempool_destroy(&mgr->rpool);
- kill_depool:
        isc_mempool_destroy(&mgr->depool);
- kill_locks:
        isc_mutex_destroy(&mgr->spool_lock);
        isc_mutex_destroy(&mgr->bpool_lock);
        isc_mutex_destroy(&mgr->dpool_lock);
@@ -1986,11 +1974,7 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr,
                        mgr->maxbuffers = maxbuffers;
                }
        } else {
-               result = isc_mempool_create(mgr->mctx, buffersize, &mgr->bpool);
-               if (result != ISC_R_SUCCESS) {
-                       UNLOCK(&mgr->buffer_lock);
-                       return (result);
-               }
+               isc_mempool_create(mgr->mctx, buffersize, &mgr->bpool);
                isc_mempool_setname(mgr->bpool, "dispmgr_bpool");
                isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
                isc_mempool_setfreemax(mgr->bpool, maxbuffers);
@@ -2009,10 +1993,8 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr,
                UNLOCK(&mgr->buffer_lock);
                return (ISC_R_SUCCESS);
        }
-       result = isc_mempool_create(mgr->mctx, sizeof(dispsocket_t),
+       isc_mempool_create(mgr->mctx, sizeof(dispsocket_t),
                                    &mgr->spool);
-       if (result != ISC_R_SUCCESS)
-               goto cleanup;
 
        isc_mempool_setname(mgr->spool, "dispmgr_spool");
        isc_mempool_setmaxalloc(mgr->spool, maxrequests);
@@ -2857,11 +2839,8 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
                        ISC_LIST_INIT(disp->port_table[i]);
                }
 
-               result = isc_mempool_create(mgr->mctx, sizeof(dispportentry_t),
+               isc_mempool_create(mgr->mctx, sizeof(dispportentry_t),
                                            &disp->portpool);
-               if (result != ISC_R_SUCCESS) {
-                       goto deallocate_dispatch;
-               }
                isc_mempool_setname(disp->portpool, "disp_portpool");
                isc_mempool_setfreemax(disp->portpool, 128);
        }
@@ -2892,12 +2871,8 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
                                            sizeof(isc_event_t));
 
        disp->sepool = NULL;
-       if (isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t),
-                              &disp->sepool) != ISC_R_SUCCESS)
-       {
-               result = ISC_R_NOMEMORY;
-               goto kill_ctlevent;
-       }
+       isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t),
+                              &disp->sepool);
 
        isc_mutex_init(&disp->sepool_lock);
 
@@ -2929,11 +2904,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
        /*
         * Error returns.
         */
- kill_ctlevent:
-       isc_event_free(&disp->ctlevent);
-       for (i = 0; i < disp->ntasks; i++) {
-               isc_task_detach(&disp->task[i]);
-       }
  kill_socket:
        if (disp->socket != NULL) {
                isc_socket_detach(&disp->socket);
index 282357c770a7c5d14c40f9d5bf0342b349a49393..acecc37e1cbf7e78c459e3a7b3b21a5cf7428c20 100644 (file)
@@ -743,17 +743,13 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp)
         * Ok, it is safe to allocate (and then "goto cleanup" if failure)
         */
 
-       result = isc_mempool_create(m->mctx, sizeof(dns_name_t), &m->namepool);
-       if (result != ISC_R_SUCCESS)
-               goto cleanup;
+       isc_mempool_create(m->mctx, sizeof(dns_name_t), &m->namepool);
        isc_mempool_setfillcount(m->namepool, NAME_COUNT);
        isc_mempool_setfreemax(m->namepool, NAME_COUNT);
        isc_mempool_setname(m->namepool, "msg:names");
 
-       result = isc_mempool_create(m->mctx, sizeof(dns_rdataset_t),
+       isc_mempool_create(m->mctx, sizeof(dns_rdataset_t),
                                    &m->rdspool);
-       if (result != ISC_R_SUCCESS)
-               goto cleanup;
        isc_mempool_setfillcount(m->rdspool, RDATASET_COUNT);
        isc_mempool_setfreemax(m->rdspool, RDATASET_COUNT);
        isc_mempool_setname(m->rdspool, "msg:rdataset");
index a923cc58d21c6f41bb34f0817a6b440ed2fb8b30..0b55e29035f6ea2f8dcad2af1c795b057710f880 100644 (file)
@@ -69,7 +69,6 @@ _teardown(void **state) {
 /* general memory system tests */
 static void
 isc_mem_test(void **state) {
-       isc_result_t result;
        void *items1[50];
        void *items2[50];
        void *tmp;
@@ -79,11 +78,8 @@ isc_mem_test(void **state) {
 
        UNUSED(state);
 
-       result = isc_mempool_create(test_mctx, 24, &mp1);
-       assert_int_equal(result, ISC_R_SUCCESS);
-
-       result = isc_mempool_create(test_mctx, 31, &mp2);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       isc_mempool_create(test_mctx, 24, &mp1);
+       isc_mempool_create(test_mctx, 31, &mp2);
 
        isc_mempool_setfreemax(mp1, MP1_FREEMAX);
        isc_mempool_setfillcount(mp1, MP1_FILLCNT);
@@ -148,8 +144,7 @@ isc_mem_test(void **state) {
        isc_mempool_destroy(&mp1);
        isc_mempool_destroy(&mp2);
 
-       result = isc_mempool_create(test_mctx, 2, &mp1);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       isc_mempool_create(test_mctx, 2, &mp1);
 
        tmp = isc_mempool_get(mp1);
        assert_non_null(tmp);
@@ -460,8 +455,7 @@ isc_mempool_benchmark(void **state) {
 
        isc_mutex_init(&mplock);
 
-       result = isc_mempool_create(test_mctx, ITEM_SIZE, &mp);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       isc_mempool_create(test_mctx, ITEM_SIZE, &mp);
 
        isc_mempool_associatelock(mp, &mplock);