isc_event_allocate() cannot fail, remove the fail handling blocks

isc_event_allocate() calls isc_mem_get() to allocate the event structure.  As
isc_mem_get() cannot fail softly (e.g. it never returns NULL), the
isc_event_allocate() cannot return NULL, hence we remove the (ret == NULL)
handling blocks using the semantic patch from the previous commit.
This commit is contained in:
Ondřej Surý 2019-08-29 10:29:53 +02:00
parent 2d12def6ee
commit 50e109d659
21 changed files with 15 additions and 196 deletions

View file

@ -2633,10 +2633,6 @@ force_timeout(dig_query_t *query) {
event = isc_event_allocate(mctx, query, ISC_TIMEREVENT_IDLE,
connect_timeout, query,
sizeof(isc_event_t));
if (event == NULL) {
fatal("isc_event_allocate: %s",
isc_result_totext(ISC_R_NOMEMORY));
}
isc_task_send(global_task, &event);
/*

View file

@ -1570,8 +1570,6 @@ assignwork(isc_task_t *task, isc_task_t *worker) {
sevent = (sevent_t *)
isc_event_allocate(mctx, task, SIGNER_EVENT_WORK,
sign, NULL, sizeof(sevent_t));
if (sevent == NULL)
fatal("failed to allocate event\n");
sevent->node = node;
sevent->fname = fname;
@ -1627,8 +1625,6 @@ sign(isc_task_t *task, isc_event_t *event) {
wevent = (sevent_t *)
isc_event_allocate(mctx, task, SIGNER_EVENT_WRITE,
writenode, NULL, sizeof(sevent_t));
if (wevent == NULL)
fatal("failed to allocate event\n");
wevent->node = node;
wevent->fname = fname;
isc_task_send(master, ISC_EVENT_PTR(&wevent));

View file

@ -2827,8 +2827,6 @@ catz_create_chg_task(dns_catz_entry_t *entry, dns_catz_zone_t *origin,
event = (catz_chgzone_event_t *) isc_event_allocate(view->mctx, origin,
type, action, NULL,
sizeof(*event));
if (event == NULL)
return (ISC_R_NOMEMORY);
event->cbd = (catz_cb_data_t *) udata;
event->entry = NULL;
@ -13565,8 +13563,6 @@ named_server_delzone(named_server_t *server, isc_lex_t *lex,
dns_zone_attach(zone, &dz->zone);
dzevent = isc_event_allocate(named_g_mctx, server, NAMED_EVENT_DELZONE,
rmzone, dz, sizeof(isc_event_t));
if (dzevent == NULL)
CHECK(ISC_R_NOMEMORY);
dns_zone_gettask(zone, &task);
isc_task_send(task, &dzevent);

View file

@ -213,10 +213,6 @@ syncptr(sample_instance_t *inst, dns_name_t *name,
SYNCPTR_WRITE_EVENT,
syncptr_write, NULL,
sizeof(syncptrevent_t));
if (pevent == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
isc_buffer_init(&pevent->b, pevent->buf, sizeof(pevent->buf));
dns_fixedname_init(&pevent->ptr_target_name);

View file

@ -556,20 +556,12 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
DNS_EVENT_CACHECLEAN,
incremental_cleaning_action,
cleaner, sizeof(isc_event_t));
if (cleaner->resched_event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
cleaner->overmem_event =
isc_event_allocate(cache->mctx, cleaner,
DNS_EVENT_CACHEOVERMEM,
overmem_cleaning_action,
cleaner, sizeof(isc_event_t));
if (cleaner->overmem_event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
}
return (ISC_R_SUCCESS);

View file

@ -1342,10 +1342,6 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name,
event = (dns_clientresevent_t *)
isc_event_allocate(mctx, tclone, DNS_EVENT_CLIENTRESDONE,
action, arg, sizeof(*event));
if (event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
event->result = DNS_R_SERVFAIL;
ISC_LIST_INIT(event->answerlist);
@ -1733,10 +1729,6 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
isc_event_allocate(client->mctx, tclone,
DNS_EVENT_CLIENTREQDONE,
action, arg, sizeof(*event));
if (event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
ctx = isc_mem_get(client->mctx, sizeof(*ctx));
if (ctx == NULL)
@ -2847,8 +2839,6 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass,
uctx->event = (dns_clientupdateevent_t *)
isc_event_allocate(client->mctx, tclone, DNS_EVENT_UPDATEDONE,
action, arg, sizeof(*uctx->event));
if (uctx->event == NULL)
goto fail;
if (zonename != NULL) {
uctx->zonename = dns_fixedname_name(&uctx->zonefname);
result = dns_name_copy(zonename, uctx->zonename, NULL);
@ -2924,11 +2914,8 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass,
event = isc_event_allocate(client->mctx, dns_client_startupdate,
DNS_EVENT_STARTUPDATE, startupdate,
uctx, sizeof(*event));
if (event != NULL) {
result = ISC_R_SUCCESS;
isc_task_send(task, &event);
} else
result = ISC_R_NOMEMORY;
result = ISC_R_SUCCESS;
isc_task_send(task, &event);
}
if (result == ISC_R_SUCCESS)
return (result);

View file

@ -2444,10 +2444,6 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
DNS_EVENT_DISPATCHCONTROL,
destroy_disp, disp,
sizeof(isc_event_t));
if (disp->ctlevent == NULL) {
result = ISC_R_NOMEMORY;
goto kill_task;
}
isc_task_setname(disp->task[0], "tcpdispatch", disp);
@ -2485,11 +2481,6 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
return (ISC_R_SUCCESS);
/*
* Error returns.
*/
kill_task:
isc_task_detach(&disp->task[0]);
kill_socket:
isc_socket_detach(&disp->socket);
deallocate_dispatch:
@ -2897,10 +2888,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
DNS_EVENT_DISPATCHCONTROL,
destroy_disp, disp,
sizeof(isc_event_t));
if (disp->ctlevent == NULL) {
result = ISC_R_NOMEMORY;
goto kill_task;
}
disp->sepool = NULL;
if (isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t),
@ -2942,7 +2929,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
*/
kill_ctlevent:
isc_event_free(&disp->ctlevent);
kill_task:
for (i = 0; i < disp->ntasks; i++) {
isc_task_detach(&disp->task[i]);
}
@ -3554,8 +3540,6 @@ dns_dispatch_importrecv(dns_dispatch_t *disp, isc_event_t *event) {
isc_event_allocate(disp->mgr->mctx, NULL,
DNS_EVENT_IMPORTRECVDONE, udp_shrecv,
disp, sizeof(isc_socketevent_t));
if (newsevent == NULL)
return;
buf = allocate_udp_buffer(disp);
if (buf == NULL) {

View file

@ -807,9 +807,6 @@ check_file_size_and_maybe_reopen(dns_dtenv_t *env) {
*/
event = isc_event_allocate(env->mctx, NULL, DNS_EVENT_FREESTORAGE,
perform_reopen, env, sizeof(*event));
if (event == NULL) {
goto unlock_and_return;
}
isc_task_attach(env->reopen_task, &reopen_task);
isc_task_send(reopen_task, &event);
env->reopen_queued = true;

View file

@ -377,10 +377,6 @@ dns_lookup_create(isc_mem_t *mctx, const dns_name_t *name, dns_rdatatype_t type,
ievent = isc_event_allocate(mctx, lookup, DNS_EVENT_LOOKUPDONE,
action, arg, sizeof(*lookup->event));
if (ievent == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_lookup;
}
lookup->event = (dns_lookupevent_t *)ievent;
lookup->event->ev_destroy = levent_destroy;
lookup->event->ev_destroy_arg = mctx;
@ -426,7 +422,6 @@ dns_lookup_create(isc_mem_t *mctx, const dns_name_t *name, dns_rdatatype_t type,
isc_task_detach(&lookup->task);
cleanup_lookup:
isc_mem_putanddetach(&mctx, lookup, sizeof(*lookup));
return (result);

View file

@ -3078,8 +3078,6 @@ task_send(dns_loadctx_t *lctx) {
event = isc_event_allocate(lctx->mctx, NULL,
DNS_EVENT_MASTERQUANTUM,
load_quantum, lctx, sizeof(*event));
if (event == NULL)
return (ISC_R_NOMEMORY);
isc_task_send(lctx->task, &event);
return (ISC_R_SUCCESS);
}

View file

@ -1444,8 +1444,6 @@ task_send(dns_dumpctx_t *dctx) {
event = isc_event_allocate(dctx->mctx, NULL, DNS_EVENT_DUMPQUANTUM,
dump_quantum, dctx, sizeof(*event));
if (event == NULL)
return (ISC_R_NOMEMORY);
isc_task_send(dctx->task, &event);
return (ISC_R_SUCCESS);
}

View file

@ -1052,8 +1052,6 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) {
free_rbtdb_callback,
rbtdb,
sizeof(isc_event_t));
if (event == NULL)
continue;
isc_task_send(rbtdb->task, &event);
return;
}
@ -1861,16 +1859,11 @@ cleanup_dead_nodes(dns_rbtdb_t *rbtdb, int bucketnum) {
DNS_EVENT_RBTPRUNE,
prune_tree, node,
sizeof(isc_event_t));
if (ev != NULL) {
new_reference(rbtdb, node);
db = NULL;
attach((dns_db_t *)rbtdb, &db);
ev->ev_sender = db;
isc_task_send(rbtdb->task, &ev);
} else {
ISC_LIST_APPEND(rbtdb->deadnodes[bucketnum],
node, deadlink);
}
new_reference(rbtdb, node);
db = NULL;
attach((dns_db_t *)rbtdb, &db);
ev->ev_sender = db;
isc_task_send(rbtdb->task, &ev);
} else {
delete_node(rbtdb, node);
}
@ -2067,34 +2060,12 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node,
DNS_EVENT_RBTPRUNE,
prune_tree, node,
sizeof(isc_event_t));
if (ev != NULL) {
new_reference(rbtdb, node);
db = NULL;
attach((dns_db_t *)rbtdb, &db);
ev->ev_sender = db;
isc_task_send(rbtdb->task, &ev);
no_reference = false;
} else {
/*
* XXX: this is a weird situation. We could
* ignore this error case, but then the stale
* node will unlikely be purged except via a
* rare condition such as manual cleanup. So
* we queue it in the deadnodes list, hoping
* the memory shortage is temporary and the node
* will be deleted later.
*/
isc_log_write(dns_lctx,
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_CACHE,
ISC_LOG_INFO,
"decrement_reference: failed to "
"allocate pruning event");
INSIST(node->data == NULL);
INSIST(!ISC_LINK_LINKED(node, deadlink));
ISC_LIST_APPEND(rbtdb->deadnodes[bucket], node,
deadlink);
}
new_reference(rbtdb, node);
db = NULL;
attach((dns_db_t *)rbtdb, &db);
ev->ev_sender = db;
isc_task_send(rbtdb->task, &ev);
no_reference = false;
} else {
delete_node(rbtdb, node);
}

View file

@ -736,10 +736,6 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
request->event = (dns_requestevent_t *)
isc_event_allocate(mctx, task, DNS_EVENT_REQUESTDONE,
action, arg, sizeof(dns_requestevent_t));
if (request->event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
isc_task_attach(task, &tclone);
request->event->ev_sender = task;
request->event->request = request;
@ -926,10 +922,6 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message,
request->event = (dns_requestevent_t *)
isc_event_allocate(mctx, task, DNS_EVENT_REQUESTDONE,
action, arg, sizeof(dns_requestevent_t));
if (request->event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
isc_task_attach(task, &tclone);
request->event->ev_sender = task;
request->event->request = request;

View file

@ -4620,10 +4620,6 @@ fctx_join(fetchctx_t *fctx, isc_task_t *task, const isc_sockaddr_t *client,
event = (dns_fetchevent_t *)
isc_event_allocate(fctx->res->mctx, tclone, DNS_EVENT_FETCHDONE,
action, arg, sizeof(*event));
if (event == NULL) {
isc_task_detach(&tclone);
return (ISC_R_NOMEMORY);
}
event->result = DNS_R_SERVFAIL;
event->qtype = fctx->type;
event->db = NULL;

View file

@ -3048,10 +3048,6 @@ dns_validator_create(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
DNS_EVENT_VALIDATORSTART,
validator_start, NULL,
sizeof(dns_validatorevent_t));
if (event == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_val;
}
isc_task_attach(task, &tclone);
event->validator = val;
event->result = ISC_R_FAILURE;
@ -3114,7 +3110,6 @@ dns_validator_create(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
isc_task_detach(&tclone);
isc_event_free(ISC_EVENT_PTR(&event));
cleanup_val:
dns_view_weakdetach(&val->view);
isc_mem_put(view->mctx, val, sizeof(*val));

View file

@ -2189,12 +2189,12 @@ dns_zone_asyncload(dns_zone_t *zone, bool newonly,
{
isc_event_t *e;
dns_asyncload_t *asl = NULL;
isc_result_t result = ISC_R_SUCCESS;
REQUIRE(DNS_ZONE_VALID(zone));
if (zone->zmgr == NULL)
if (zone->zmgr == NULL) {
return (ISC_R_FAILURE);
}
/* If we already have a load pending, stop now */
LOCK_ZONE(zone);
@ -2214,8 +2214,6 @@ dns_zone_asyncload(dns_zone_t *zone, bool newonly,
DNS_EVENT_ZONELOAD,
zone_asyncload, asl,
sizeof(isc_event_t));
if (e == NULL)
CHECK(ISC_R_NOMEMORY);
zone_iattach(zone, &asl->zone);
DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_LOADPENDING);
@ -2223,12 +2221,6 @@ dns_zone_asyncload(dns_zone_t *zone, bool newonly,
UNLOCK_ZONE(zone);
return (ISC_R_SUCCESS);
failure:
if (asl != NULL)
isc_mem_put(zone->mctx, asl, sizeof (*asl));
UNLOCK_ZONE(zone);
return (result);
}
bool
@ -11363,8 +11355,6 @@ notify_send_queue(dns_notify_t *notify, bool startup) {
INSIST(notify->event == NULL);
e = isc_event_allocate(notify->mctx, NULL, DNS_EVENT_NOTIFYSENDTOADDR,
notify_send_toaddr, notify, sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
if (startup)
notify->event = e;
e->ev_arg = notify;
@ -12667,10 +12657,6 @@ queue_soa_query(dns_zone_t *zone) {
e = isc_event_allocate(zone->mctx, NULL, DNS_EVENT_ZONE,
soa_query, zone, sizeof(isc_event_t));
if (e == NULL) {
cancel_refresh(zone);
return;
}
/*
* Attach so that we won't clean up
@ -14877,8 +14863,6 @@ zone_send_secureserial(dns_zone_t *zone, uint32_t serial) {
DNS_EVENT_ZONESECURESERIAL,
receive_secure_serial, zone->secure,
sizeof(struct secure_event));
if (e == NULL)
return (ISC_R_NOMEMORY);
((struct secure_event *)e)->serial = serial;
INSIST(LOCKED_ZONE(zone->secure));
zone_iattach(zone->secure, &dummy);
@ -15339,8 +15323,6 @@ zone_send_securedb(dns_zone_t *zone, dns_db_t *db) {
DNS_EVENT_ZONESECUREDB,
receive_secure_db, zone->secure,
sizeof(struct secure_event));
if (e == NULL)
return (ISC_R_NOMEMORY);
dns_db_attach(db, &dummy);
((struct secure_event *)e)->db = dummy;
INSIST(LOCKED_ZONE(zone->secure));
@ -17040,8 +17022,6 @@ zmgr_start_xfrin_ifquota(dns_zonemgr_t *zmgr, dns_zone_t *zone) {
*/
e = isc_event_allocate(zmgr->mctx, zmgr, DNS_EVENT_ZONESTARTXFRIN,
got_transfer_quota, zone, sizeof(isc_event_t));
if (e == NULL)
return (ISC_R_NOMEMORY);
LOCK_ZONE(zone);
INSIST(zone->statelist == &zmgr->waiting_for_xfrin);
@ -17097,10 +17077,6 @@ zonemgr_getio(dns_zonemgr_t *zmgr, bool high,
io->event = isc_event_allocate(zmgr->mctx, task, DNS_EVENT_IOREADY,
action, arg, sizeof(*io->event));
if (io->event == NULL) {
isc_mem_put(zmgr->mctx, io, sizeof(*io));
return (ISC_R_NOMEMORY);
}
io->zmgr = zmgr;
io->high = high;
@ -19253,10 +19229,6 @@ dns_zone_keydone(dns_zone_t *zone, const char *keystr) {
e = isc_event_allocate(zone->mctx, zone, DNS_EVENT_KEYDONE, keydone,
zone, sizeof(struct keydone));
if (e == NULL) {
result = ISC_R_NOMEMORY;
goto failure;
}
kd = (struct keydone *) e;
if (strcasecmp(keystr, "all") == 0) {
@ -19558,10 +19530,6 @@ dns_zone_setnsec3param(dns_zone_t *zone, uint8_t hash, uint8_t flags,
e = isc_event_allocate(zone->mctx, zone, DNS_EVENT_SETNSEC3PARAM,
setnsec3param, zone, sizeof(struct np3event));
if (e == NULL) {
result = ISC_R_NOMEMORY;
goto failure;
}
npe = (struct np3event *) e;
np = &npe->params;
@ -19823,10 +19791,6 @@ dns_zone_setserial(dns_zone_t *zone, uint32_t serial) {
e = isc_event_allocate(zone->mctx, zone, DNS_EVENT_SETSERIAL,
setserial, zone, sizeof(struct ssevent));
if (e == NULL) {
result = ISC_R_NOMEMORY;
goto failure;
}
sse = (struct ssevent *)e;
sse->serial = serial;

View file

@ -224,10 +224,6 @@ isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx, isc_task_t *task,
isc_task_attach(task, &cloned_task);
event = isc_event_allocate(mctx, cloned_task, ISC_APPEVENT_SHUTDOWN,
action, arg, sizeof(*event));
if (event == NULL) {
isc_task_detach(&cloned_task);
return (ISC_R_NOMEMORY);
}
LOCK(&ctx->lock);
ISC_LINK_INIT(event, ev_link);

View file

@ -785,8 +785,6 @@ isc_task_onshutdown(isc_task_t *task0, isc_taskaction_t action,
action,
arg,
sizeof(*event));
if (event == NULL)
return (ISC_R_NOMEMORY);
LOCK(&task->lock);
if (TASK_SHUTTINGDOWN(task)) {

View file

@ -1451,9 +1451,6 @@ allocate_socketevent(isc_mem_t *mctx, void *sender,
eventtype, action, arg,
sizeof(*ev));
if (ev == NULL)
return (NULL);
ev->result = ISC_R_UNSET;
ISC_LINK_INIT(ev, ev_link);
ev->region.base = NULL;
@ -4645,10 +4642,6 @@ isc_socket_accept(isc_socket_t *sock0,
dev = (isc_socket_newconnev_t *)
isc_event_allocate(manager->mctx, task, ISC_SOCKEVENT_NEWCONN,
action, arg, sizeof(*dev));
if (dev == NULL) {
UNLOCK(&sock->lock);
return (ISC_R_NOMEMORY);
}
ISC_LINK_INIT(dev, ev_link);
result = allocate_socket(manager, sock->type, &nsock);
@ -4720,10 +4713,6 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr,
ISC_SOCKEVENT_CONNECT,
action, arg,
sizeof(*dev));
if (dev == NULL) {
UNLOCK(&sock->lock);
return (ISC_R_NOMEMORY);
}
ISC_LINK_INIT(dev, ev_link);
if (sock->connecting) {

View file

@ -983,8 +983,6 @@ allocate_socketevent(isc_mem_t *mctx, isc_socket_t *sock,
ev = (isc_socketevent_t *)isc_event_allocate(mctx, sock, eventtype,
action, arg,
sizeof(*ev));
if (ev == NULL)
return (NULL);
ev->result = ISC_R_IOERROR; // XXXMLG temporary change to detect failure to set
ISC_LINK_INIT(ev, ev_link);
@ -3062,10 +3060,6 @@ isc_socket_accept(isc_socket_t *sock,
adev = (isc_socket_newconnev_t *)
isc_event_allocate(manager->mctx, task, ISC_SOCKEVENT_NEWCONN,
action, arg, sizeof(*adev));
if (adev == NULL) {
UNLOCK(&sock->lock);
return (ISC_R_NOMEMORY);
}
ISC_LINK_INIT(adev, ev_link);
result = allocate_socket(manager, sock->type, &nsock);
@ -3210,10 +3204,6 @@ isc_socket_connect(isc_socket_t *sock, const isc_sockaddr_t *addr,
ISC_SOCKEVENT_CONNECT,
action, arg,
sizeof(*cdev));
if (cdev == NULL) {
UNLOCK(&sock->lock);
return (ISC_R_NOMEMORY);
}
ISC_LINK_INIT(cdev, ev_link);
if (sock->connected) {

View file

@ -1534,8 +1534,6 @@ send_update_event(ns_client_t *client, dns_zone_t *zone) {
event = (update_event_t *)
isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
update_action, NULL, sizeof(*event));
if (event == NULL)
FAIL(ISC_R_NOMEMORY);
event->zone = zone;
event->result = ISC_R_SUCCESS;
@ -1548,9 +1546,6 @@ send_update_event(ns_client_t *client, dns_zone_t *zone) {
dns_zone_gettask(zone, &zonetask);
isc_task_send(zonetask, ISC_EVENT_PTR(&event));
failure:
if (event != NULL)
isc_event_free(ISC_EVENT_PTR(&event));
return (result);
}
@ -3489,8 +3484,6 @@ send_forward_event(ns_client_t *client, dns_zone_t *zone) {
event = (update_event_t *)
isc_event_allocate(client->mctx, client, DNS_EVENT_UPDATE,
forward_action, NULL, sizeof(*event));
if (event == NULL)
FAIL(ISC_R_NOMEMORY);
event->zone = zone;
event->result = ISC_R_SUCCESS;