From: Ondřej Surý Date: Sun, 2 Feb 2020 07:50:41 +0000 (+0100) Subject: Refactor the isc_mempool_create() usage using the semantic patch X-Git-Tag: v9.16.0~37^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eb3f71a3eca6c5faee5543ac2e5cf8e6f4f5ead;p=thirdparty%2Fbind9.git Refactor the isc_mempool_create() usage using the semantic patch 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. --- diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index b9bc11603bf..c92ea2903a0 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -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 diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index f24e7d45c52..5a647e57b1c 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -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); diff --git a/bin/tests/optional/adb_test.c b/bin/tests/optional/adb_test.c index 859c772effc..41295874388 100644 --- a/bin/tests/optional/adb_test.c +++ b/bin/tests/optional/adb_test.c @@ -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); diff --git a/bin/tests/optional/mempool_test.c b/bin/tests/optional/mempool_test.c index bc359f41f3e..485443c9098 100644 --- a/bin/tests/optional/mempool_test.c +++ b/bin/tests/optional/mempool_test.c @@ -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); diff --git a/lib/dns/adb.c b/lib/dns/adb.c index 98b013dff55..d7f25494dbd 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -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); \ diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 47ff2bc9bc0..d1b31891383 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -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); diff --git a/lib/dns/message.c b/lib/dns/message.c index 282357c770a..acecc37e1cb 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -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"); diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index a923cc58d21..0b55e29035f 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -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);