mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-19 08:33:44 -04:00
Merge branch 'ondrej/isc_mempool_create_cannot_fail' into 'master'
isc_mempool_create() cannot fail See merge request isc-projects/bind9!2988
This commit is contained in:
commit
9286548c7e
11 changed files with 76 additions and 72 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
49
cocci/isc_mempool_create_cannot_fail.cocci
Normal file
49
cocci/isc_mempool_create_cannot_fail.cocci
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
@@
|
||||
expression V;
|
||||
@@
|
||||
|
||||
- V =
|
||||
isc_mempool_create(...);
|
||||
- assert_int_equal(V, ISC_R_SUCCESS);
|
||||
|
||||
@@
|
||||
expression V;
|
||||
@@
|
||||
|
||||
- V =
|
||||
isc_mempool_create(...);
|
||||
- check_result(V, ...);
|
||||
|
||||
@@
|
||||
@@
|
||||
|
||||
- CHECK(
|
||||
isc_mempool_create(...)
|
||||
- )
|
||||
;
|
||||
|
||||
@@
|
||||
@@
|
||||
|
||||
- RUNTIME_CHECK(
|
||||
isc_mempool_create(...)
|
||||
- == ISC_R_SUCCESS)
|
||||
;
|
||||
|
||||
@@
|
||||
expression V;
|
||||
statement S;
|
||||
@@
|
||||
|
||||
- V =
|
||||
isc_mempool_create(...);
|
||||
- if (V != ISC_R_SUCCESS) S
|
||||
|
||||
@@
|
||||
statement S;
|
||||
@@
|
||||
|
||||
- if (
|
||||
isc_mempool_create(...)
|
||||
- != ISC_R_SUCCESS) S
|
||||
+ ;
|
||||
|
|
@ -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); \
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ isc_mem_renderjson(void *memobj0);
|
|||
* Memory pools
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
|
||||
/*%<
|
||||
* Create a memory pool.
|
||||
|
|
|
|||
|
|
@ -1535,7 +1535,7 @@ isc_mem_gettag(isc_mem_t *ctx0) {
|
|||
* Memory pool stuff
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
|
||||
isc__mem_t *mctx = (isc__mem_t *)mctx0;
|
||||
isc__mempool_t *mpctx;
|
||||
|
|
@ -1579,8 +1579,6 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
|
|||
ISC_LIST_INITANDAPPEND(mctx->pools, mpctx, link);
|
||||
mctx->poolcnt++;
|
||||
MCTXUNLOCK(mctx);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue