From ae83801e2b8e87260dea59a445f3c41bb5eb9944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 16 Jul 2019 15:52:14 +0200 Subject: [PATCH] Remove blocks checking whether isc_mem_get() failed using the coccinelle --- bin/confgen/ddns-confgen.c | 2 - bin/confgen/rndc-confgen.c | 2 - bin/delv/delv.c | 18 --- bin/dnssec/dnssec-cds.c | 23 ---- bin/dnssec/dnssec-signzone.c | 8 -- bin/named/config.c | 25 ---- bin/named/controlconf.c | 31 +---- bin/named/server.c | 48 +------- bin/named/statschannel.c | 2 - bin/named/tkeyconf.c | 4 - bin/named/tsigconf.c | 4 - bin/named/unix/dlz_dlopen_driver.c | 4 - bin/named/win32/dlz_dlopen_driver.c | 4 - bin/named/zoneconf.c | 19 --- bin/nsupdate/nsupdate.c | 32 ++--- bin/rndc/rndc.c | 2 - bin/tests/optional/db_test.c | 2 - bin/tests/optional/rbt_test.c | 4 - bin/tests/optional/sock_test.c | 9 +- bin/tests/wire_test.c | 4 - contrib/dlz/drivers/dlz_bdb_driver.c | 7 -- contrib/dlz/drivers/dlz_bdbhpt_driver.c | 7 -- contrib/dlz/drivers/dlz_filesystem_driver.c | 13 +- contrib/dlz/drivers/dlz_ldap_driver.c | 6 - contrib/dlz/drivers/dlz_odbc_driver.c | 6 - contrib/dlz/drivers/dlz_postgres_driver.c | 2 - contrib/dlz/drivers/sdlz_helper.c | 14 --- doc/dev/dev.md | 4 - lib/bind9/check.c | 3 - lib/dns/acl.c | 12 -- lib/dns/adb.c | 5 +- lib/dns/badcache.c | 17 --- lib/dns/byaddr.c | 11 -- lib/dns/cache.c | 7 -- lib/dns/catz.c | 19 +-- lib/dns/client.c | 26 ---- lib/dns/compress.c | 4 - lib/dns/db.c | 6 - lib/dns/dbtable.c | 4 +- lib/dns/diff.c | 8 -- lib/dns/dispatch.c | 41 +----- lib/dns/dlz.c | 8 -- lib/dns/dns64.c | 2 - lib/dns/dnsrps.c | 6 - lib/dns/dnssec.c | 12 +- lib/dns/dnstap.c | 4 - lib/dns/dst_api.c | 14 +-- lib/dns/dst_parse.c | 4 +- lib/dns/dyndb.c | 6 - lib/dns/ecdb.c | 6 - lib/dns/forward.c | 14 --- lib/dns/geoip2.c | 3 +- lib/dns/gssapi_link.c | 6 - lib/dns/hmac_link.c | 3 - lib/dns/ipkeylist.c | 31 +---- lib/dns/iptable.c | 2 - lib/dns/journal.c | 21 +--- lib/dns/keytable.c | 5 - lib/dns/lookup.c | 14 --- lib/dns/master.c | 12 -- lib/dns/masterdump.c | 14 --- lib/dns/message.c | 8 -- lib/dns/name.c | 6 - lib/dns/nta.c | 4 - lib/dns/openssldh_link.c | 6 +- lib/dns/opensslecdsa_link.c | 2 - lib/dns/openssleddsa_link.c | 4 - lib/dns/opensslrsa_link.c | 4 - lib/dns/order.c | 4 - lib/dns/peer.c | 18 +-- lib/dns/pkcs11ecdsa_link.c | 108 ++++------------ lib/dns/pkcs11eddsa_link.c | 112 ++++------------- lib/dns/pkcs11rsa_link.c | 130 +++----------------- lib/dns/portlist.c | 6 - lib/dns/rbt.c | 16 +-- lib/dns/rbtdb.c | 95 +++----------- lib/dns/rdataslab.c | 25 ---- lib/dns/request.c | 4 - lib/dns/resolver.c | 64 +--------- lib/dns/rpz.c | 9 -- lib/dns/rrl.c | 27 +--- lib/dns/sdb.c | 22 ---- lib/dns/sdlz.c | 14 --- lib/dns/ssu.c | 18 --- lib/dns/stats.c | 2 - lib/dns/tests/tsig_test.c | 5 +- lib/dns/tkey.c | 14 --- lib/dns/tsec.c | 2 - lib/dns/tsig.c | 20 +-- lib/dns/update.c | 2 - lib/dns/validator.c | 4 - lib/dns/view.c | 16 +-- lib/dns/xfrin.c | 2 - lib/dns/zone.c | 64 +--------- lib/dns/zoneverify.c | 3 - lib/dns/zt.c | 5 - lib/irs/context.c | 4 - lib/irs/dnsconf.c | 11 -- lib/irs/getaddrinfo.c | 13 -- lib/irs/resconf.c | 8 -- lib/isc/buffer.c | 11 +- lib/isc/commandline.c | 2 - lib/isc/counter.c | 2 - lib/isc/event.c | 4 - lib/isc/heap.c | 4 - lib/isc/ht.c | 13 +- lib/isc/httpd.c | 19 --- lib/isc/lex.c | 10 -- lib/isc/log.c | 29 +---- lib/isc/pk11.c | 12 -- lib/isc/pool.c | 6 - lib/isc/portset.c | 2 - lib/isc/radix.c | 13 -- lib/isc/ratelimiter.c | 2 - lib/isc/symtab.c | 17 +-- lib/isc/task.c | 5 +- lib/isc/taskpool.c | 6 - lib/isc/timer.c | 4 - lib/isc/unix/ifiter_getifaddrs.c | 2 - lib/isc/unix/socket.c | 16 +-- lib/isc/win32/interfaceiter.c | 10 -- lib/isc/win32/socket.c | 9 -- lib/isccfg/aclconf.c | 2 - lib/isccfg/namedconf.c | 8 +- lib/isccfg/parser.c | 14 --- lib/ns/client.c | 33 +---- lib/ns/interfacemgr.c | 6 - lib/ns/listenlist.c | 4 - lib/ns/query.c | 2 - lib/ns/server.c | 2 - lib/ns/xfrout.c | 18 --- lib/samples/nsprobe.c | 20 --- lib/samples/sample-update.c | 24 ---- 133 files changed, 151 insertions(+), 1717 deletions(-) diff --git a/bin/confgen/ddns-confgen.c b/bin/confgen/ddns-confgen.c index ab783b14de..45603f0757 100644 --- a/bin/confgen/ddns-confgen.c +++ b/bin/confgen/ddns-confgen.c @@ -222,8 +222,6 @@ main(int argc, char **argv) { if (suffix != NULL) { len = strlen(keyname) + strlen(suffix) + 2; keybuf = isc_mem_get(mctx, len); - if (keybuf == NULL) - fatal("failed to allocate memory for keyname"); snprintf(keybuf, len, "%s.%s", keyname, suffix); keyname = (const char *) keybuf; } diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index 3694034c0a..ad2536e0c8 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -222,8 +222,6 @@ main(int argc, char **argv) { char *buf; len = strlen(chrootdir) + strlen(keyfile) + 2; buf = isc_mem_get(mctx, len); - if (buf == NULL) - fatal("isc_mem_get(%d) failed\n", len); snprintf(buf, len, "%s%s%s", chrootdir, (*keyfile != '/') ? "/" : "", keyfile); diff --git a/bin/delv/delv.c b/bin/delv/delv.c index d07f2bb49f..f33ffb3210 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -436,8 +436,6 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner, do { t = isc_mem_get(mctx, len); - if (t == NULL) - return (ISC_R_NOMEMORY); isc_buffer_init(&target, t, len); if (short_form) { @@ -819,8 +817,6 @@ addserver(dns_client_t *client) { fatal("Use of IPv4 disabled by -6"); } sa = isc_mem_get(mctx, sizeof(*sa)); - if (sa == NULL) - return (ISC_R_NOMEMORY); ISC_LINK_INIT(sa, link); isc_sockaddr_fromin(sa, &in4, destport); ISC_LIST_APPEND(servers, sa, link); @@ -829,8 +825,6 @@ addserver(dns_client_t *client) { fatal("Use of IPv6 disabled by -4"); } sa = isc_mem_get(mctx, sizeof(*sa)); - if (sa == NULL) - return (ISC_R_NOMEMORY); ISC_LINK_INIT(sa, link); isc_sockaddr_fromin6(sa, &in6, destport); ISC_LIST_APPEND(servers, sa, link); @@ -858,10 +852,6 @@ addserver(dns_client_t *client) { cur->ai_family != AF_INET6) continue; sa = isc_mem_get(mctx, sizeof(*sa)); - if (sa == NULL) { - result = ISC_R_NOMEMORY; - break; - } memset(sa, 0, sizeof(*sa)); ISC_LINK_INIT(sa, link); memmove(&sa->type, cur->ai_addr, cur->ai_addrlen); @@ -934,10 +924,6 @@ findserver(dns_client_t *client) { struct in_addr localhost; localhost.s_addr = htonl(INADDR_LOOPBACK); sa = isc_mem_get(mctx, sizeof(*sa)); - if (sa == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } isc_sockaddr_fromin(sa, &localhost, destport); ISC_LINK_INIT(sa, link); @@ -946,10 +932,6 @@ findserver(dns_client_t *client) { if (use_ipv6) { sa = isc_mem_get(mctx, sizeof(*sa)); - if (sa == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } isc_sockaddr_fromin6(sa, &in6addr_loopback, destport); ISC_LINK_INIT(sa, link); diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index ba54acbd8a..673442c4ae 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -530,9 +530,6 @@ match_keyset_dsset(dns_rdataset_t *keyset, dns_rdataset_t *dsset, nkey = dns_rdataset_count(keyset); keytable = isc_mem_get(mctx, sizeof(keyinfo_t) * nkey); - if (keytable == NULL) { - fatal("out of memory"); - } for (result = dns_rdataset_first(keyset), i = 0; result == ISC_R_SUCCESS; @@ -610,10 +607,6 @@ matching_sigs(keyinfo_t *keytbl, dns_rdataset_t *rdataset, int i; algo = isc_mem_get(mctx, nkey); - if (algo == NULL) { - fatal("allocating RRSIG/DNSKEY match list: %s", - isc_result_totext(ISC_R_NOMEMORY)); - } memset(algo, 0, nkey); for (result = dns_rdataset_first(sigset); @@ -747,10 +740,6 @@ rdata_get(void) { dns_rdata_t *rdata; rdata = isc_mem_get(mctx, sizeof(*rdata)); - if (rdata == NULL) { - fatal("allocating DS rdata: %s", - isc_result_totext(ISC_R_NOMEMORY)); - } dns_rdata_init(rdata); return (rdata); @@ -835,10 +824,6 @@ make_new_ds_set(ds_maker_func_t *ds_from_rdata, dns_rdatalist_t *dslist; dslist = isc_mem_get(mctx, sizeof(*dslist)); - if (dslist == NULL) { - fatal("allocating new DS list: %s", - isc_result_totext(ISC_R_NOMEMORY)); - } dns_rdatalist_init(dslist); dslist->rdclass = rdclass; @@ -907,10 +892,6 @@ consistent_digests(dns_rdataset_t *dsset) { n = dns_rdataset_count(dsset); arrdata = isc_mem_get(mctx, n * sizeof(dns_rdata_t)); - if (arrdata == NULL) { - fatal("allocating DS rdata array: %s", - isc_result_totext(ISC_R_NOMEMORY)); - } for (result = dns_rdataset_first(dsset), i = 0; result == ISC_R_SUCCESS; @@ -926,10 +907,6 @@ consistent_digests(dns_rdataset_t *dsset) { * Convert sorted arrdata to more accessible format */ ds = isc_mem_get(mctx, n * sizeof(dns_rdata_ds_t)); - if (ds == NULL) { - fatal("allocating unpacked DS array: %s", - isc_result_totext(ISC_R_NOMEMORY)); - } for (i = 0; i < n; i++) { result = dns_rdata_tostruct(&arrdata[i], &ds[i], NULL); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index b01d15b58c..cecf7b02be 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -1496,8 +1496,6 @@ assignwork(isc_task_t *task, isc_task_t *worker) { } fname = isc_mem_get(mctx, sizeof(dns_fixedname_t)); - if (fname == NULL) - fatal("out of memory"); name = dns_fixedname_initname(fname); node = NULL; found = false; @@ -2930,8 +2928,6 @@ writeset(const char *prefix, dns_rdatatype_t type) { if (dsdir != NULL) filenamelen += strlen(dsdir) + 1; filename = isc_mem_get(mctx, filenamelen); - if (filename == NULL) - fatal("out of memory"); if (dsdir != NULL) snprintf(filename, filenamelen, "%s/", dsdir); else @@ -3811,8 +3807,6 @@ main(int argc, char *argv[]) { } else { tempfilelen = strlen(output) + 20; tempfile = isc_mem_get(mctx, tempfilelen); - if (tempfile == NULL) - fatal("out of memory"); result = isc_file_mktemplate(output, tempfile, tempfilelen); check_result(result, "isc_file_mktemplate"); @@ -3842,8 +3836,6 @@ main(int argc, char *argv[]) { fatal("failed to create task: %s", isc_result_totext(result)); tasks = isc_mem_get(mctx, ntasks * sizeof(isc_task_t *)); - if (tasks == NULL) - fatal("out of memory"); for (i = 0; i < (int)ntasks; i++) { tasks[i] = NULL; result = isc_task_create(taskmgr, 0, &tasks[i]); diff --git a/bin/named/config.c b/bin/named/config.c index 300a21b161..d2af0ec922 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -512,16 +512,9 @@ named_config_getiplist(const cfg_obj_t *config, const cfg_obj_t *list, } dscps = isc_mem_get(mctx, count * sizeof(isc_dscp_t)); - if (dscps == NULL) - return (ISC_R_NOMEMORY); } addrs = isc_mem_get(mctx, count * sizeof(isc_sockaddr_t)); - if (addrs == NULL) { - if (dscps != NULL) - isc_mem_put(mctx, dscps, count * sizeof(isc_dscp_t)); - return (ISC_R_NOMEMORY); - } for (element = cfg_list_first(addrlist); element != NULL; @@ -697,8 +690,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, newsize = newlen * sizeof(*lists); oldsize = listcount * sizeof(*lists); tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; if (listcount != 0) { memmove(tmp, lists, oldsize); isc_mem_put(mctx, lists, oldsize); @@ -733,8 +724,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, newsize = newlen * sizeof(*stack); oldsize = stackcount * sizeof(*stack); tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; if (stackcount != 0) { memmove(tmp, stack, oldsize); isc_mem_put(mctx, stack, oldsize); @@ -761,8 +750,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, newsize = newlen * sizeof(isc_sockaddr_t); oldsize = addrcount * sizeof(isc_sockaddr_t); tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; if (addrcount != 0) { memmove(tmp, addrs, oldsize); isc_mem_put(mctx, addrs, oldsize); @@ -773,8 +760,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, newsize = newlen * sizeof(isc_dscp_t); oldsize = dscpcount * sizeof(isc_dscp_t); tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; if (dscpcount != 0) { memmove(tmp, dscps, oldsize); isc_mem_put(mctx, dscps, oldsize); @@ -785,8 +770,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, newsize = newlen * sizeof(dns_name_t *); oldsize = keycount * sizeof(dns_name_t *); tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; if (keycount != 0) { memmove(tmp, keys, oldsize); isc_mem_put(mctx, keys, oldsize); @@ -806,8 +789,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, if (!cfg_obj_isstring(key)) continue; keys[i - 1] = isc_mem_get(mctx, sizeof(dns_name_t)); - if (keys[i - 1] == NULL) - goto cleanup; dns_name_init(keys[i - 1], NULL); keystr = cfg_obj_asstring(key); @@ -838,8 +819,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, oldsize = addrcount * sizeof(isc_sockaddr_t); if (i != 0) { tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; memmove(tmp, addrs, newsize); } else tmp = NULL; @@ -851,8 +830,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, oldsize = dscpcount * sizeof(isc_dscp_t); if (i != 0) { tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; memmove(tmp, dscps, newsize); } else tmp = NULL; @@ -864,8 +841,6 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list, oldsize = keycount * sizeof(dns_name_t *); if (i != 0) { tmp = isc_mem_get(mctx, newsize); - if (tmp == NULL) - goto cleanup; memmove(tmp, keys, newsize); } else tmp = NULL; diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 7c69c24442..f3a8513a93 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -369,9 +369,8 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) { ccregion.rstart = isc_buffer_base(&conn->ccmsg.buffer); ccregion.rend = isc_buffer_used(&conn->ccmsg.buffer); - secret.rstart = isc_mem_get(listener->mctx, key->secret.length); - if (secret.rstart == NULL) - goto cleanup; + secret.rstart = isc_mem_get(listener->mctx, + key->secret.length); memmove(secret.rstart, key->secret.base, key->secret.length); secret.rend = secret.rstart + key->secret.length; algorithm = key->algorithm; @@ -561,8 +560,6 @@ newconnection(controllistener_t *listener, isc_socket_t *sock) { isc_result_t result; conn = isc_mem_get(listener->mctx, sizeof(*conn)); - if (conn == NULL) - return (ISC_R_NOMEMORY); conn->sock = sock; isccc_ccmsg_init(listener->mctx, sock, &conn->ccmsg); @@ -729,8 +726,6 @@ controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx, if (newstr == NULL) goto cleanup; key = isc_mem_get(mctx, sizeof(*key)); - if (key == NULL) - goto cleanup; key->keyname = newstr; key->algorithm = DST_ALG_UNKNOWN; key->secret.base = NULL; @@ -819,15 +814,6 @@ register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist, keyid->secret.length = isc_buffer_usedlength(&b); keyid->secret.base = isc_mem_get(mctx, keyid->secret.length); - if (keyid->secret.base == NULL) { - cfg_obj_log(keydef, named_g_lctx, - ISC_LOG_WARNING, - "couldn't register key '%s': " - "out of memory", keyid->keyname); - ISC_LIST_UNLINK(*keyids, keyid, link); - free_controlkey(keyid, mctx); - break; - } memmove(keyid->secret.base, isc_buffer_base(&b), keyid->secret.length); } @@ -868,8 +854,6 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) { CHECK(cfg_map_get(config, "key", &key)); keyid = isc_mem_get(mctx, sizeof(*keyid)); - if (keyid == NULL) - CHECK(ISC_R_NOMEMORY); keyid->keyname = isc_mem_strdup(mctx, cfg_obj_asstring(cfg_map_getname(key))); keyid->secret.base = NULL; @@ -911,14 +895,7 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) { } keyid->secret.length = isc_buffer_usedlength(&b); - keyid->secret.base = isc_mem_get(mctx, - keyid->secret.length); - if (keyid->secret.base == NULL) { - cfg_obj_log(key, named_g_lctx, ISC_LOG_WARNING, - "couldn't register key '%s': " - "out of memory", keyid->keyname); - CHECK(ISC_R_NOMEMORY); - } + keyid->secret.base = isc_mem_get(mctx, keyid->secret.length); memmove(keyid->secret.base, isc_buffer_base(&b), keyid->secret.length); ISC_LIST_APPEND(*keyids, keyid, link); @@ -1125,8 +1102,6 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, isc_result_t result = ISC_R_SUCCESS; listener = isc_mem_get(mctx, sizeof(*listener)); - if (listener == NULL) - result = ISC_R_NOMEMORY; if (result == ISC_R_SUCCESS) { listener->mctx = NULL; diff --git a/bin/named/server.c b/bin/named/server.c index 5691cdc489..b987111d76 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -1945,10 +1945,6 @@ conf_dnsrps_sadd(conf_dnsrps_ctx_t *ctx, const char *p, ...) { if (ctx->cstr == NULL) { ctx->cstr = isc_mem_get(ctx->mctx, 256); - if (ctx->cstr == NULL) { - ctx->result = ISC_R_NOMEMORY; - return (false); - } ctx->cstr[0] = '\0'; ctx->cstr_size = 256; } @@ -1964,10 +1960,6 @@ conf_dnsrps_sadd(conf_dnsrps_ctx_t *ctx, const char *p, ...) { new_cstr_size = ((cur_len + new_len)/256 + 1) * 256; new_cstr = isc_mem_get(ctx->mctx, new_cstr_size); - if (new_cstr == NULL) { - ctx->result = ISC_R_NOMEMORY; - return (false); - } memmove(new_cstr, ctx->cstr, cur_len); isc_mem_put(ctx->mctx, ctx->cstr, ctx->cstr_size); @@ -4372,10 +4364,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, isc_mem_detach(&hmctx); } nsc = isc_mem_get(mctx, sizeof(*nsc)); - if (nsc == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } nsc->cache = NULL; dns_cache_attach(cache, &nsc->cache); nsc->primaryview = view; @@ -5796,10 +5784,6 @@ configure_forward(const cfg_obj_t *config, dns_view_t *view, { const cfg_obj_t *forwarder = cfg_listelt_value(element); fwd = isc_mem_get(view->mctx, sizeof(dns_forwarder_t)); - if (fwd == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } fwd->addr = *cfg_obj_assockaddr(forwarder); if (isc_sockaddr_getport(&fwd->addr) == 0) isc_sockaddr_setport(&fwd->addr, port); @@ -6857,9 +6841,6 @@ dotat(dns_keytable_t *keytable, dns_keynode_t *keynode, void *arg) { view->name, namebuf); tat = isc_mem_get(dotat_arg->view->mctx, sizeof(*tat)); - if (tat == NULL) { - return; - } tat->mctx = NULL; tat->task = NULL; @@ -7326,9 +7307,8 @@ configure_session_key(const cfg_obj_t **maps, named_server_t *server, INSIST(server->session_keyalg == DST_ALG_UNKNOWN); INSIST(server->session_keybits == 0); - server->session_keyname = isc_mem_get(mctx, sizeof(dns_name_t)); - if (server->session_keyname == NULL) - goto cleanup; + server->session_keyname = isc_mem_get(mctx, + sizeof(dns_name_t)); dns_name_init(server->session_keyname, NULL); CHECK(dns_name_dup(keyname, mctx, server->session_keyname)); @@ -7537,10 +7517,6 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, } nzcfg = isc_mem_get(view->mctx, sizeof(*nzcfg)); - if (nzcfg == NULL) { - dns_view_setnewzones(view, false, NULL, NULL, 0ULL); - return (ISC_R_NOMEMORY); - } /* * We attach the parser that was used for config as well @@ -9170,10 +9146,6 @@ load_configuration(const char *filename, named_server_t *server, } else { altsecret = isc_mem_get(server->sctx->mctx, sizeof(*altsecret)); - if (altsecret == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } isc_buffer_init(&b, altsecret->secret, sizeof(altsecret->secret)); result = isc_hex_decodestring(str, &b); @@ -9398,9 +9370,7 @@ load_zones(named_server_t *server, bool init, bool reconfig) { dns_view_t *view; ns_zoneload_t *zl; - zl = isc_mem_get(server->mctx, sizeof (*zl)); - if (zl == NULL) - return (ISC_R_NOMEMORY); + zl = isc_mem_get(server->mctx, sizeof(*zl)); zl->server = server; zl->reconfig = reconfig; @@ -9952,10 +9922,6 @@ named_add_reserved_dispatch(named_server_t *server, } dispatch = isc_mem_get(server->mctx, sizeof(*dispatch)); - if (dispatch == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dispatch->addr = *addr; dispatch->dispatchgen = server->dispatchgen; @@ -10629,8 +10595,6 @@ add_zone_tolist(dns_zone_t *zone, void *uap) { struct zonelistentry *zle; zle = isc_mem_get(dctx->mctx, sizeof *zle); - if (zle == NULL) - return (ISC_R_NOMEMORY); zle->zone = NULL; dns_zone_attach(zone, &zle->zone); ISC_LINK_INIT(zle, link); @@ -10653,8 +10617,6 @@ add_view_tolist(struct dumpcontext *dctx, dns_view_t *view) { return (ISC_R_SUCCESS); vle = isc_mem_get(dctx->mctx, sizeof *vle); - if (vle == NULL) - return (ISC_R_NOMEMORY); vle->view = NULL; dns_view_attach(view, &vle->view); ISC_LINK_INIT(vle, link); @@ -10847,8 +10809,6 @@ named_server_dumpdb(named_server_t *server, isc_lex_t *lex, return (ISC_R_UNEXPECTEDEND); dctx = isc_mem_get(server->mctx, sizeof(*dctx)); - if (dctx == NULL) - return (ISC_R_NOMEMORY); dctx->mctx = server->mctx; dctx->dumpcache = true; @@ -13655,8 +13615,6 @@ named_server_delzone(named_server_t *server, isc_lex_t *lex, /* Send cleanup event */ dz = isc_mem_get(named_g_mctx, sizeof(*dz)); - if (dz == NULL) - CHECK(ISC_R_NOMEMORY); dz->cleanup = cleanup; dz->zone = NULL; diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index a45945b003..4778964e01 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -3403,8 +3403,6 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, dns_acl_t *new_acl = NULL; listener = isc_mem_get(server->mctx, sizeof(*listener)); - if (listener == NULL) - return (ISC_R_NOMEMORY); listener->httpdmgr = NULL; listener->address = *addr; diff --git a/bin/named/tkeyconf.c b/bin/named/tkeyconf.c index 41546c58ad..1a54703a6e 100644 --- a/bin/named/tkeyconf.c +++ b/bin/named/tkeyconf.c @@ -84,10 +84,6 @@ named_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx, name = dns_fixedname_initname(&fname); RETERR(dns_name_fromtext(name, &b, dns_rootname, 0, NULL)); tctx->domain = isc_mem_get(mctx, sizeof(dns_name_t)); - if (tctx->domain == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } dns_name_init(tctx->domain, NULL); RETERR(dns_name_dup(name, mctx, tctx->domain)); } diff --git a/bin/named/tsigconf.c b/bin/named/tsigconf.c index 633482237c..cffd6d3788 100644 --- a/bin/named/tsigconf.c +++ b/bin/named/tsigconf.c @@ -97,10 +97,6 @@ add_initial_keys(const cfg_obj_t *list, dns_tsig_keyring_t *ring, secretstr = cfg_obj_asstring(secretobj); secretalloc = secretlen = strlen(secretstr) * 3 / 4; secret = isc_mem_get(mctx, secretlen); - if (secret == NULL) { - ret = ISC_R_NOMEMORY; - goto failure; - } isc_buffer_init(&secretbuf, secret, secretlen); ret = isc_base64_decodestring(secretstr, &secretbuf); if (ret != ISC_R_SUCCESS) diff --git a/bin/named/unix/dlz_dlopen_driver.c b/bin/named/unix/dlz_dlopen_driver.c index ab8a5c9493..0f0119e0a3 100644 --- a/bin/named/unix/dlz_dlopen_driver.c +++ b/bin/named/unix/dlz_dlopen_driver.c @@ -230,10 +230,6 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[], return (result); cd = isc_mem_get(mctx, sizeof(*cd)); - if (cd == NULL) { - isc_mem_destroy(&mctx); - return (ISC_R_NOMEMORY); - } memset(cd, 0, sizeof(*cd)); cd->mctx = mctx; diff --git a/bin/named/win32/dlz_dlopen_driver.c b/bin/named/win32/dlz_dlopen_driver.c index 6cd900fd3b..2316b355a3 100644 --- a/bin/named/win32/dlz_dlopen_driver.c +++ b/bin/named/win32/dlz_dlopen_driver.c @@ -227,10 +227,6 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[], isc_mem_create(0, 0, &mctx); cd = isc_mem_get(mctx, sizeof(*cd)); - if (cd == NULL) { - isc_mem_destroy(&mctx); - return (ISC_R_NOMEMORY); - } memset(cd, 0, sizeof(*cd)); cd->mctx = mctx; diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index 8f1da7ca8b..1fbd3003cb 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -287,10 +287,6 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone, types = NULL; else { types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t)); - if (types == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } } i = 0; @@ -433,8 +429,6 @@ configure_staticstub_serveraddrs(const cfg_obj_t *zconfig, dns_zone_t *zone, } rdata = isc_mem_get(mctx, sizeof(*rdata) + region.length); - if (rdata == NULL) - return (ISC_R_NOMEMORY); region.base = (unsigned char *)(rdata + 1); memmove(region.base, &na.type, region.length); dns_rdata_init(rdata); @@ -455,13 +449,6 @@ configure_staticstub_serveraddrs(const cfg_obj_t *zconfig, dns_zone_t *zone, /* Add to the list an apex NS with the ns name being the origin name */ dns_name_toregion(dns_zone_getorigin(zone), &sregion); rdata = isc_mem_get(mctx, sizeof(*rdata) + sregion.length); - if (rdata == NULL) { - /* - * Already allocated data will be freed in the caller, so - * we can simply return here. - */ - return (ISC_R_NOMEMORY); - } region.length = sregion.length; region.base = (unsigned char *)(rdata + 1); memmove(region.base, sregion.base, region.length); @@ -523,8 +510,6 @@ configure_staticstub_servernames(const cfg_obj_t *zconfig, dns_zone_t *zone, dns_name_toregion(nsname, &sregion); rdata = isc_mem_get(mctx, sizeof(*rdata) + sregion.length); - if (rdata == NULL) - return (ISC_R_NOMEMORY); region.length = sregion.length; region.base = (unsigned char *)(rdata + 1); memmove(region.base, sregion.base, region.length); @@ -718,8 +703,6 @@ strtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp, /* We have reached the end of the string. */ *argcp = n; *argvp = isc_mem_get(mctx, n * sizeof(char *)); - if (*argvp == NULL) - return (ISC_R_NOMEMORY); } else { char *p = s; while (*p != ' ' && *p != '\t' && *p != '\0') @@ -1098,8 +1081,6 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig, RETERR(dns_zone_setfile(raw, filename, masterformat, masterstyle)); signedname = isc_mem_get(mctx, signedlen); - if (signedname == NULL) - return (ISC_R_NOMEMORY); (void)snprintf(signedname, signedlen, "%s" SIGNED, filename); result = dns_zone_setfile(zone, signedname, diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 926723fb9b..49b79a9290 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -824,9 +824,8 @@ setup_system(void) { default_servers = !local_only; ns_total = ns_alloc = (have_ipv4 ? 1 : 0) + (have_ipv6 ? 1 : 0); - servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t)); - if (servers == NULL) - fatal("out of memory"); + servers = isc_mem_get(gmctx, + ns_alloc * sizeof(isc_sockaddr_t)); if (have_ipv6) { memset(&in6, 0, sizeof(in6)); @@ -869,9 +868,8 @@ setup_system(void) { } ns_alloc = ns_total; - servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t)); - if (servers == NULL) - fatal("out of memory"); + servers = isc_mem_get(gmctx, + ns_alloc * sizeof(isc_sockaddr_t)); i = 0; for (sa = ISC_LIST_HEAD(*nslist); @@ -1497,8 +1495,6 @@ evaluate_server(char *cmdline) { ns_alloc = MAX_SERVERADDRS; ns_inuse = 0; servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t)); - if (servers == NULL) - fatal("out of memory"); memset(servers, 0, ns_alloc * sizeof(isc_sockaddr_t)); ns_total = get_addresses(server, (in_port_t)port, servers, ns_alloc); @@ -1541,15 +1537,13 @@ evaluate_local(char *cmdline) { if (have_ipv6 && inet_pton(AF_INET6, local, &in6) == 1) { if (localaddr6 == NULL) - localaddr6 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t)); - if (localaddr6 == NULL) - fatal("out of memory"); + localaddr6 = isc_mem_get(gmctx, + sizeof(isc_sockaddr_t)); isc_sockaddr_fromin6(localaddr6, &in6, (in_port_t)port); } else if (have_ipv4 && inet_pton(AF_INET, local, &in4) == 1) { if (localaddr4 == NULL) - localaddr4 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t)); - if (localaddr4 == NULL) - fatal("out of memory"); + localaddr4 = isc_mem_get(gmctx, + sizeof(isc_sockaddr_t)); isc_sockaddr_fromin(localaddr4, &in4, (in_port_t)port); } else { fprintf(stderr, "invalid address %s", local); @@ -2520,8 +2514,6 @@ recvsoa(isc_task_t *task, isc_event_t *event) { ddebug("Destroying request [%p]", request); dns_request_destroy(&request); reqinfo = isc_mem_get(gmctx, sizeof(nsu_requestinfo_t)); - if (reqinfo == NULL) - fatal("out of memory"); reqinfo->msg = soaquery; reqinfo->addr = addr; dns_message_renderreset(soaquery); @@ -2659,8 +2651,6 @@ recvsoa(isc_task_t *task, isc_event_t *event) { master_alloc = MAX_SERVERADDRS; size = master_alloc * sizeof(isc_sockaddr_t); master_servers = isc_mem_get(gmctx, size); - if (master_servers == NULL) - fatal("out of memory"); memset(master_servers, 0, size); master_total = get_addresses(serverstr, dnsport, @@ -2724,8 +2714,6 @@ sendrequest(isc_sockaddr_t *destaddr, dns_message_t *msg, isc_sockaddr_t *srcaddr; reqinfo = isc_mem_get(gmctx, sizeof(nsu_requestinfo_t)); - if (reqinfo == NULL) - fatal("out of memory"); reqinfo->msg = msg; reqinfo->addr = destaddr; @@ -2835,8 +2823,6 @@ start_gssrequest(dns_name_t *master) { dns_name_format(master, namestr, sizeof(namestr)); if (kserver == NULL) { kserver = isc_mem_get(gmctx, sizeof(isc_sockaddr_t)); - if (kserver == NULL) - fatal("out of memory"); } memmove(kserver, &master_servers[master_inuse], @@ -2920,8 +2906,6 @@ send_gssrequest(isc_sockaddr_t *destaddr, dns_message_t *msg, debug("send_gssrequest"); reqinfo = isc_mem_get(gmctx, sizeof(nsu_gssinfo_t)); - if (reqinfo == NULL) - fatal("out of memory"); reqinfo->msg = msg; reqinfo->addr = destaddr; reqinfo->context = context; diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 4c174364ed..6f9c9b307c 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -968,8 +968,6 @@ main(int argc, char **argv) { argslen += strlen(argv[i]) + 1; args = isc_mem_get(rndc_mctx, argslen); - if (args == NULL) - DO("isc_mem_get", ISC_R_NOMEMORY); p = args; for (i = 0; i < argc; i++) { diff --git a/bin/tests/optional/db_test.c b/bin/tests/optional/db_test.c index d45c26734f..b30e01ec54 100644 --- a/bin/tests/optional/db_test.c +++ b/bin/tests/optional/db_test.c @@ -231,8 +231,6 @@ load(const char *filename, const char *origintext, bool cache) { unsigned int i; dbi = isc_mem_get(mctx, sizeof(*dbi)); - if (dbi == NULL) - return (ISC_R_NOMEMORY); dbi->db = NULL; dbi->version = NULL; diff --git a/bin/tests/optional/rbt_test.c b/bin/tests/optional/rbt_test.c index dc1ece8291..17c5ae0386 100644 --- a/bin/tests/optional/rbt_test.c +++ b/bin/tests/optional/rbt_test.c @@ -55,10 +55,6 @@ create_name(char *s) { * name structure. */ name = isc_mem_get(mctx, sizeof(*name) + DNSNAMELEN); - if (name == NULL) { - printf("out of memory!\n"); - return (NULL); - } dns_name_init(name, NULL); isc_buffer_init(&target, name + 1, DNSNAMELEN); diff --git a/bin/tests/optional/sock_test.c b/bin/tests/optional/sock_test.c index fa319b4cc8..96b9602292 100644 --- a/bin/tests/optional/sock_test.c +++ b/bin/tests/optional/sock_test.c @@ -104,11 +104,10 @@ my_recv(isc_task_t *task, isc_event_t *event) { snprintf(buf, sizeof(buf), "\r\nReceived: %.*s\r\n\r\n", (int)dev->n, (char *)region.base); region.base = isc_mem_get(mctx, strlen(buf) + 1); - if (region.base != NULL) { + { region.length = strlen(buf) + 1; strlcpy((char *)region.base, buf, region.length); - } else - region.length = 0; + } isc_socket_send(sock, ®ion, task, my_send, event->ev_arg); } else { region = dev->region; @@ -177,11 +176,9 @@ my_connect(isc_task_t *task, isc_event_t *event) { "GET / HTTP/1.1\r\nHost: www.flame.org\r\n" "Connection: Close\r\n\r\n"); region.base = isc_mem_get(mctx, strlen(buf) + 1); - if (region.base != NULL) { + { region.length = strlen(buf) + 1; strlcpy((char *)region.base, buf, region.length); - } else { - region.length = 0; } isc_socket_send(sock, ®ion, task, my_http_get, event->ev_arg); diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index 237b4d1a36..7e3570fdd9 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -80,10 +80,6 @@ printmessage(dns_message_t *msg) { do { buf = isc_mem_get(mctx, len); - if (buf == NULL) { - result = ISC_R_NOMEMORY; - break; - } isc_buffer_init(&b, buf, len); result = dns_message_totext(msg, &dns_master_style_debug, diff --git a/contrib/dlz/drivers/dlz_bdb_driver.c b/contrib/dlz/drivers/dlz_bdb_driver.c index 13ea5c97c3..bde080ab16 100644 --- a/contrib/dlz/drivers/dlz_bdb_driver.c +++ b/contrib/dlz/drivers/dlz_bdb_driver.c @@ -617,13 +617,6 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate and zero memory for driver structure */ db = isc_mem_get(named_g_mctx, sizeof(bdb_instance_t)); - if (db == NULL) { - isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, - DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, - "Could not allocate memory for " - "database instance object."); - return (ISC_R_NOMEMORY); - } memset(db, 0, sizeof(bdb_instance_t)); /* attach to the memory context */ diff --git a/contrib/dlz/drivers/dlz_bdbhpt_driver.c b/contrib/dlz/drivers/dlz_bdbhpt_driver.c index 90b8fcc5f7..1f20015860 100644 --- a/contrib/dlz/drivers/dlz_bdbhpt_driver.c +++ b/contrib/dlz/drivers/dlz_bdbhpt_driver.c @@ -707,13 +707,6 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate and zero memory for driver structure */ db = isc_mem_get(named_g_mctx, sizeof(bdbhpt_instance_t)); - if (db == NULL) { - isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, - DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, - "Could not allocate memory for " - "database instance object."); - return (ISC_R_NOMEMORY); - } memset(db, 0, sizeof(bdbhpt_instance_t)); /* attach to the memory context */ diff --git a/contrib/dlz/drivers/dlz_filesystem_driver.c b/contrib/dlz/drivers/dlz_filesystem_driver.c index c8bb079e5d..cec74d73df 100644 --- a/contrib/dlz/drivers/dlz_filesystem_driver.c +++ b/contrib/dlz/drivers/dlz_filesystem_driver.c @@ -486,11 +486,8 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, * dir list */ if (dir_list != NULL) { - direntry = - isc_mem_get(named_g_mctx, - sizeof(dir_entry_t)); - if (direntry == NULL) - return (ISC_R_NOMEMORY); + direntry = isc_mem_get(named_g_mctx, + sizeof(dir_entry_t)); strcpy(direntry->dirpath, tmp); ISC_LINK_INIT(direntry, link); ISC_LIST_APPEND(*dir_list, direntry, @@ -645,10 +642,6 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata, /* allocate memory for list */ dir_list = isc_mem_get(named_g_mctx, sizeof(dlist_t)); - if (dir_list == NULL) { - result = ISC_R_NOTFOUND; - goto complete_allnds; - } /* initialize list */ ISC_LIST_INIT(*dir_list); @@ -905,8 +898,6 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for our config data */ cd = isc_mem_get(named_g_mctx, sizeof(config_data_t)); - if (cd == NULL) - goto no_mem; /* zero the memory */ memset(cd, 0, sizeof(config_data_t)); diff --git a/contrib/dlz/drivers/dlz_ldap_driver.c b/contrib/dlz/drivers/dlz_ldap_driver.c index 13a4f44b34..e8e5566f2a 100644 --- a/contrib/dlz/drivers/dlz_ldap_driver.c +++ b/contrib/dlz/drivers/dlz_ldap_driver.c @@ -1014,8 +1014,6 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for LDAP instance */ ldap_inst = isc_mem_get(named_g_mctx, sizeof(ldap_instance_t)); - if (ldap_inst == NULL) - return (ISC_R_NOMEMORY); memset(ldap_inst, 0, sizeof(ldap_instance_t)); /* store info needed to automatically re-connect. */ @@ -1039,10 +1037,6 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for database connection list */ ldap_inst->db = isc_mem_get(named_g_mctx, sizeof(db_list_t)); - if (ldap_inst->db == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } /* initialize DB connection list */ ISC_LIST_INIT(*(ldap_inst->db)); diff --git a/contrib/dlz/drivers/dlz_odbc_driver.c b/contrib/dlz/drivers/dlz_odbc_driver.c index 24e2109686..5946805425 100644 --- a/contrib/dlz/drivers/dlz_odbc_driver.c +++ b/contrib/dlz/drivers/dlz_odbc_driver.c @@ -1219,8 +1219,6 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for odbc instance */ odbc_inst = isc_mem_get(named_g_mctx, sizeof(odbc_instance_t)); - if (odbc_inst == NULL) - return (ISC_R_NOMEMORY); memset(odbc_inst, 0, sizeof(odbc_instance_t)); /* parse connection string and get paramters. */ @@ -1271,10 +1269,6 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for database connection list */ odbc_inst->db = isc_mem_get(named_g_mctx, sizeof(db_list_t)); - if (odbc_inst->db == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } /* initialize DB connection list */ diff --git a/contrib/dlz/drivers/dlz_postgres_driver.c b/contrib/dlz/drivers/dlz_postgres_driver.c index d53c470605..734a53c79c 100644 --- a/contrib/dlz/drivers/dlz_postgres_driver.c +++ b/contrib/dlz/drivers/dlz_postgres_driver.c @@ -1087,8 +1087,6 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[], /* allocate memory for database connection list */ dblist = isc_mem_get(named_g_mctx, sizeof(db_list_t)); - if (dblist == NULL) - return (ISC_R_NOMEMORY); /* initialize DB connection list */ ISC_LIST_INIT(*dblist); diff --git a/contrib/dlz/drivers/sdlz_helper.c b/contrib/dlz/drivers/sdlz_helper.c index 3b068f0813..6f17d07540 100644 --- a/contrib/dlz/drivers/sdlz_helper.c +++ b/contrib/dlz/drivers/sdlz_helper.c @@ -125,9 +125,6 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, /* allocate memory for query list */ tql = isc_mem_get(mctx, sizeof(query_list_t)); - /* couldn't allocate memory. Problem!! */ - if (tql == NULL) - return (ISC_R_NOMEMORY); /* initialize the query segment list */ ISC_LIST_INIT(*tql); @@ -153,10 +150,6 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, /* allocate memory for tseg */ tseg = isc_mem_get(mctx, sizeof(query_segment_t)); - if (tseg == NULL) { /* no memory, clean everything up. */ - result = ISC_R_NOMEMORY; - goto cleanup; - } tseg->sql = NULL; tseg->direct = false; /* initialize the query segment link */ @@ -340,13 +333,6 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str, /* allocate and zero memory for driver structure */ db = isc_mem_get(mctx, sizeof(dbinstance_t)); - if (db == NULL) { - isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, - DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, - "Could not allocate memory for " - "database instance object."); - return (ISC_R_NOMEMORY); - } memset(db, 0, sizeof(dbinstance_t)); db->dbconn = NULL; db->client = NULL; diff --git a/doc/dev/dev.md b/doc/dev/dev.md index b9c37aa7a3..de3177fe18 100644 --- a/doc/dev/dev.md +++ b/doc/dev/dev.md @@ -529,8 +529,6 @@ memory context is freed before all references have been cleaned up. REQUIRE(foop != NULL && *foop == NULL); foo = isc_mem_get(mctx, sizeof(isc_foo_t)) - if (foo == NULL) - return (ISC_R_NOMEMORY); /* Attach to memory context */ isc_mem_attach(mctx, &foo->mctx); @@ -615,8 +613,6 @@ When creating an instance of this structure, initialize the link: REQUIRE(foop != NULL && *foop == NULL); foo = isc_mem_get(mctx, sizeof(isc_foo_t)); - if (foo == NULL) - return (ISC_R_NOMEMORY); ISC_LINK_INIT(foo, link); diff --git a/lib/bind9/check.c b/lib/bind9/check.c index abb0692ebe..9d0ef32774 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -1619,8 +1619,6 @@ validate_masters(const cfg_obj_t *obj, const cfg_obj_t *config, newsize = newlen * sizeof(*stack); oldsize = stackcount * sizeof(*stack); newstack = isc_mem_get(mctx, newsize); - if (newstack == NULL) - goto cleanup; if (stackcount != 0) { void *ptr; @@ -1638,7 +1636,6 @@ validate_masters(const cfg_obj_t *obj, const cfg_obj_t *config, element = stack[--pushed]; goto resume; } - cleanup: if (stack != NULL) { void *ptr; diff --git a/lib/dns/acl.c b/lib/dns/acl.c index 32ad193380..f7a8f87bd3 100644 --- a/lib/dns/acl.c +++ b/lib/dns/acl.c @@ -40,8 +40,6 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) { n = 1; acl = isc_mem_get(mctx, sizeof(*acl)); - if (acl == NULL) - return (ISC_R_NOMEMORY); acl->mctx = NULL; isc_mem_attach(mctx, &acl->mctx); @@ -68,18 +66,10 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) { acl->magic = DNS_ACL_MAGIC; acl->elements = isc_mem_get(mctx, n * sizeof(dns_aclelement_t)); - if (acl->elements == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } acl->alloc = n; memset(acl->elements, 0, n * sizeof(dns_aclelement_t)); *target = acl; return (ISC_R_SUCCESS); - - cleanup: - dns_acl_detach(&acl); - return (result); } /* @@ -277,8 +267,6 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) newmem = isc_mem_get(dest->mctx, newalloc * sizeof(dns_aclelement_t)); - if (newmem == NULL) - return (ISC_R_NOMEMORY); /* Zero. */ memset(newmem, 0, newalloc * sizeof(dns_aclelement_t)); diff --git a/lib/dns/adb.c b/lib/dns/adb.c index 246a49f593..89bec9675c 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -2525,8 +2525,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr, UNUSED(timermgr); adb = isc_mem_get(mem, sizeof(dns_adb_t)); - if (adb == NULL) - return (ISC_R_NOMEMORY); /* * Initialize things here that cannot fail, and especially things @@ -4488,8 +4486,7 @@ dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr, if (addr->entry->cookie == NULL && cookie != NULL && len != 0U) { addr->entry->cookie = isc_mem_get(adb->mctx, len); - if (addr->entry->cookie != NULL) - addr->entry->cookielen = (uint16_t)len; + addr->entry->cookielen = (uint16_t)len; } if (addr->entry->cookie != NULL) diff --git a/lib/dns/badcache.c b/lib/dns/badcache.c index 7fab82e6be..389981f849 100644 --- a/lib/dns/badcache.c +++ b/lib/dns/badcache.c @@ -61,25 +61,18 @@ badcache_resize(dns_badcache_t *bc, isc_time_t *now, bool grow); isc_result_t dns_badcache_init(isc_mem_t *mctx, unsigned int size, dns_badcache_t **bcp) { - isc_result_t result; dns_badcache_t *bc = NULL; REQUIRE(bcp != NULL && *bcp == NULL); REQUIRE(mctx != NULL); bc = isc_mem_get(mctx, sizeof(dns_badcache_t)); - if (bc == NULL) - return (ISC_R_NOMEMORY); memset(bc, 0, sizeof(dns_badcache_t)); isc_mem_attach(mctx, &bc->mctx); isc_mutex_init(&bc->lock); bc->table = isc_mem_get(bc->mctx, sizeof(*bc->table) * size); - if (bc->table == NULL) { - result = ISC_R_NOMEMORY; - goto destroy_lock; - } bc->size = bc->minsize = size; memset(bc->table, 0, bc->size * sizeof(dns_bcentry_t *)); @@ -90,11 +83,6 @@ dns_badcache_init(isc_mem_t *mctx, unsigned int size, dns_badcache_t **bcp) { *bcp = bc; return (ISC_R_SUCCESS); - - destroy_lock: - isc_mutex_destroy(&bc->lock); - isc_mem_putanddetach(&bc->mctx, bc, sizeof(dns_badcache_t)); - return (result); } void @@ -124,8 +112,6 @@ badcache_resize(dns_badcache_t *bc, isc_time_t *now, bool grow) { newsize = (bc->size - 1) / 2; newtable = isc_mem_get(bc->mctx, sizeof(dns_bcentry_t *) * newsize); - if (newtable == NULL) - return (ISC_R_NOMEMORY); memset(newtable, 0, sizeof(dns_bcentry_t *) * newsize); for (i = 0; bc->count > 0 && i < bc->size; i++) { @@ -197,8 +183,6 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, if (bad == NULL) { isc_buffer_t buffer; bad = isc_mem_get(bc->mctx, sizeof(*bad) + name->length); - if (bad == NULL) - goto cleanup; bad->type = type; bad->hashval = hashval; bad->expire = *expire; @@ -216,7 +200,6 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, } else bad->expire = *expire; - cleanup: UNLOCK(&bc->lock); } diff --git a/lib/dns/byaddr.c b/lib/dns/byaddr.c index e13ff4bdfe..c8fb2f9b16 100644 --- a/lib/dns/byaddr.c +++ b/lib/dns/byaddr.c @@ -127,10 +127,6 @@ copy_ptr_targets(dns_byaddr_t *byaddr, dns_rdataset_t *rdataset) { if (result != ISC_R_SUCCESS) return (result); name = isc_mem_get(byaddr->mctx, sizeof(*name)); - if (name == NULL) { - dns_rdata_freestruct(&ptr); - return (ISC_R_NOMEMORY); - } dns_name_init(name, NULL); result = dns_name_dup(&ptr.ptr, byaddr->mctx, name); dns_rdata_freestruct(&ptr); @@ -202,17 +198,11 @@ dns_byaddr_create(isc_mem_t *mctx, const isc_netaddr_t *address, isc_event_t *ievent; byaddr = isc_mem_get(mctx, sizeof(*byaddr)); - if (byaddr == NULL) - return (ISC_R_NOMEMORY); byaddr->mctx = NULL; isc_mem_attach(mctx, &byaddr->mctx); byaddr->options = options; byaddr->event = isc_mem_get(mctx, sizeof(*byaddr->event)); - if (byaddr->event == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_byaddr; - } ISC_EVENT_INIT(byaddr->event, sizeof(*byaddr->event), 0, NULL, DNS_EVENT_BYADDRDONE, action, arg, byaddr, bevent_destroy, mctx); @@ -254,7 +244,6 @@ dns_byaddr_create(isc_mem_t *mctx, const isc_netaddr_t *address, isc_task_detach(&byaddr->task); - cleanup_byaddr: isc_mem_putanddetach(&mctx, byaddr, sizeof(*byaddr)); return (result); diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 731b79a560..a7e714203a 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -196,8 +196,6 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, REQUIRE(cachename != NULL); cache = isc_mem_get(cmctx, sizeof(*cache)); - if (cache == NULL) - return (ISC_R_NOMEMORY); cache->mctx = cache->hmctx = NULL; isc_mem_attach(cmctx, &cache->mctx); @@ -246,10 +244,6 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, if (cache->db_argc != 0) { cache->db_argv = isc_mem_get(cmctx, cache->db_argc * sizeof(char *)); - if (cache->db_argv == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_dbtype; - } for (i = 0; i < cache->db_argc; i++) cache->db_argv[i] = NULL; @@ -317,7 +311,6 @@ cleanup_dbargv: if (cache->db_argv != NULL) isc_mem_put(cmctx, cache->db_argv, cache->db_argc * sizeof(char *)); -cleanup_dbtype: isc_mem_free(cmctx, cache->db_type); cleanup_filelock: isc_mutex_destroy(&cache->filelock); diff --git a/lib/dns/catz.c b/lib/dns/catz.c index d5ababe00b..11d1f08b86 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -206,8 +206,6 @@ dns_catz_entry_new(isc_mem_t *mctx, const dns_name_t *domain, REQUIRE(nentryp != NULL && *nentryp == NULL); nentry = isc_mem_get(mctx, sizeof(dns_catz_entry_t)); - if (nentry == NULL) - return (ISC_R_NOMEMORY); dns_name_init(&nentry->name, NULL); if (domain != NULL) { @@ -593,8 +591,6 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm, REQUIRE(zmm != NULL); new_zones = isc_mem_get(mctx, sizeof(*new_zones)); - if (new_zones == NULL) - return (ISC_R_NOMEMORY); memset(new_zones, 0, sizeof(*new_zones)); isc_mutex_init(&new_zones->lock); @@ -650,8 +646,6 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep, REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); new_zone = isc_mem_get(catzs->mctx, sizeof(*new_zone)); - if (new_zone == NULL) - return (ISC_R_NOMEMORY); memset(new_zone, 0, sizeof(*new_zone)); @@ -1130,8 +1124,6 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, /* rdatastr.length < DNS_NAME_MAXTEXT */ keyname = isc_mem_get(mctx, sizeof(dns_name_t)); - if (keyname == NULL) - return (ISC_R_NOMEMORY); dns_name_init(keyname, 0); memmove(keycbuf, rdatastr.data, rdatastr.length); keycbuf[rdatastr.length] = 0; @@ -1171,15 +1163,8 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, return (result); } - ipkl->labels[i] = isc_mem_get(mctx, sizeof(dns_name_t)); - if (ipkl->labels[i] == NULL) { - if (keyname != NULL) { - dns_name_free(keyname, mctx); - isc_mem_put(mctx, keyname, - sizeof(dns_name_t)); - } - return (ISC_R_NOMEMORY); - } + ipkl->labels[i] = isc_mem_get(mctx, + sizeof(dns_name_t)); dns_name_init(ipkl->labels[i], NULL); result = dns_name_dup(name, mctx, ipkl->labels[i]); if (result != ISC_R_SUCCESS) { diff --git a/lib/dns/client.c b/lib/dns/client.c index c7866dc7c5..2bd667e6f3 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -488,8 +488,6 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, REQUIRE(clientp != NULL && *clientp == NULL); client = isc_mem_get(mctx, sizeof(*client)); - if (client == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&client->lock); @@ -753,8 +751,6 @@ getrdataset(isc_mem_t *mctx, dns_rdataset_t **rdatasetp) { REQUIRE(rdatasetp != NULL && *rdatasetp == NULL); rdataset = isc_mem_get(mctx, sizeof(*rdataset)); - if (rdataset == NULL) - return (ISC_R_NOMEMORY); dns_rdataset_init(rdataset); @@ -1285,8 +1281,6 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name, actx = client->actx; resarg = isc_mem_get(client->mctx, sizeof(*resarg)); - if (resarg == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&resarg->lock); @@ -1688,8 +1682,6 @@ dns_client_request(dns_client_t *client, dns_message_t *qmessage, actx = client->actx; reqarg = isc_mem_get(client->mctx, sizeof(*reqarg)); - if (reqarg == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&reqarg->lock); @@ -2156,14 +2148,6 @@ resolveaddr_done(isc_task_t *task, isc_event_t *event) { sa = isc_mem_get(uctx->client->mctx, sizeof(*sa)); - if (sa == NULL) { - /* - * If we fail to get a sockaddr, - we simply move forward with the - * addresses we've got so far. - */ - goto done; - } dns_rdata_init(&rdata); switch (family) { @@ -2739,8 +2723,6 @@ dns_client_update(dns_client_t *client, dns_rdataclass_t rdclass, actx = client->actx; uarg = isc_mem_get(client->mctx, sizeof(*uarg)); - if (uarg == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&uarg->lock); @@ -2880,10 +2862,6 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, */ uctx = isc_mem_get(client->mctx, sizeof(*uctx)); - if (uctx == NULL) { - dns_view_detach(&view); - return (ISC_R_NOMEMORY); - } isc_mutex_init(&uctx->lock); @@ -2929,8 +2907,6 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, server != NULL; server = ISC_LIST_NEXT(server, link)) { sa = isc_mem_get(client->mctx, sizeof(*sa)); - if (sa == NULL) - goto fail; sa->type = server->type; sa->length = server->length; ISC_LINK_INIT(sa, link); @@ -3150,8 +3126,6 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, if (rdataset == NULL) { updaterec = isc_mem_get(mctx, size); - if (updaterec == NULL) - return (ISC_R_NOMEMORY); rdataset = &updaterec->rdataset; rdatalist = &updaterec->rdatalist; rdata = &updaterec->rdata; diff --git a/lib/dns/compress.c b/lib/dns/compress.c index db6244db67..94a43e14eb 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -408,8 +408,6 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, dns_name_toregion(name, &r); length = r.length; tmp = isc_mem_get(cctx->mctx, length); - if (tmp == NULL) - return; /* * Copy name data to 'tmp' and make 'r' use 'tmp'. */ @@ -442,8 +440,6 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, else { node = isc_mem_get(cctx->mctx, sizeof(dns_compressnode_t)); - if (node == NULL) - break; } node->count = cctx->count++; /* diff --git a/lib/dns/db.c b/lib/dns/db.c index 5665416788..89a22c1fb6 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -883,10 +883,6 @@ dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg, } imp = isc_mem_get(mctx, sizeof(dns_dbimplementation_t)); - if (imp == NULL) { - RWUNLOCK(&implock, isc_rwlocktype_write); - return (ISC_R_NOMEMORY); - } imp->name = name; imp->create = create; imp->mctx = NULL; @@ -1044,8 +1040,6 @@ dns_db_updatenotify_register(dns_db_t *db, REQUIRE(fn != NULL); listener = isc_mem_get(db->mctx, sizeof(dns_dbonupdatelistener_t)); - if (listener == NULL) - return (ISC_R_NOMEMORY); listener->onupdate = fn; listener->onupdate_arg = fn_arg; diff --git a/lib/dns/dbtable.c b/lib/dns/dbtable.c index 177830db92..db134e44e8 100644 --- a/lib/dns/dbtable.c +++ b/lib/dns/dbtable.c @@ -55,9 +55,7 @@ dns_dbtable_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, REQUIRE(mctx != NULL); REQUIRE(dbtablep != NULL && *dbtablep == NULL); - dbtable = (dns_dbtable_t *)isc_mem_get(mctx, sizeof(*dbtable)); - if (dbtable == NULL) - return (ISC_R_NOMEMORY); + dbtable = isc_mem_get(mctx, sizeof(*dbtable)); dbtable->rbt = NULL; result = dns_rbt_create(mctx, dbdetach, NULL, &dbtable->rbt); diff --git a/lib/dns/diff.c b/lib/dns/diff.c index ac03cdbb51..bca15aff89 100644 --- a/lib/dns/diff.c +++ b/lib/dns/diff.c @@ -547,8 +547,6 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) { if (length == 0) return (ISC_R_SUCCESS); v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *)); - if (v == NULL) - return (ISC_R_NOMEMORY); for (i = 0; i < length; i++) { p = ISC_LIST_HEAD(diff->tuples); v[i] = p; @@ -600,8 +598,6 @@ dns_diff_print(dns_diff_t *diff, FILE *file) { REQUIRE(DNS_DIFF_VALID(diff)); mem = isc_mem_get(diff->mctx, size); - if (mem == NULL) - return (ISC_R_NOMEMORY); for (t = ISC_LIST_HEAD(diff->tuples); t != NULL; t = ISC_LIST_NEXT(t, link)) @@ -630,10 +626,6 @@ dns_diff_print(dns_diff_t *diff, FILE *file) { isc_mem_put(diff->mctx, mem, size); size += 1024; mem = isc_mem_get(diff->mctx, size); - if (mem == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } goto again; } diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 7411dd5b27..a652ceb56b 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -1746,8 +1746,6 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) REQUIRE(mgrp != NULL && *mgrp == NULL); mgr = isc_mem_get(mctx, sizeof(dns_dispatchmgr_t)); - if (mgr == NULL) - return (ISC_R_NOMEMORY); mgr->mctx = NULL; isc_mem_attach(mctx, &mgr->mctx); @@ -1901,20 +1899,10 @@ dns_dispatchmgr_setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset, v4ports = NULL; if (nv4ports != 0) { v4ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv4ports); - if (v4ports == NULL) - return (ISC_R_NOMEMORY); } v6ports = NULL; if (nv6ports != 0) { v6ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv6ports); - if (v6ports == NULL) { - if (v4ports != NULL) { - isc_mem_put(mgr->mctx, v4ports, - sizeof(in_port_t) * - isc_portset_nports(v4portset)); - } - return (ISC_R_NOMEMORY); - } } p = 0; @@ -2237,26 +2225,14 @@ qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets, REQUIRE(qidp != NULL && *qidp == NULL); qid = isc_mem_get(mgr->mctx, sizeof(*qid)); - if (qid == NULL) - return (ISC_R_NOMEMORY); qid->qid_table = isc_mem_get(mgr->mctx, buckets * sizeof(dns_displist_t)); - if (qid->qid_table == NULL) { - isc_mem_put(mgr->mctx, qid, sizeof(*qid)); - return (ISC_R_NOMEMORY); - } qid->sock_table = NULL; if (needsocktable) { - qid->sock_table = isc_mem_get(mgr->mctx, buckets * - sizeof(dispsocketlist_t)); - if (qid->sock_table == NULL) { - isc_mem_put(mgr->mctx, qid->qid_table, - buckets * sizeof(dns_displist_t)); - isc_mem_put(mgr->mctx, qid, sizeof(*qid)); - return (ISC_R_NOMEMORY); - } + qid->sock_table = isc_mem_get(mgr->mctx, + buckets * sizeof(dispsocketlist_t)); } isc_mutex_init(&qid->lock); @@ -2886,11 +2862,7 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr, } disp->port_table = isc_mem_get(mgr->mctx, - sizeof(disp->port_table[0]) * - DNS_DISPATCH_PORTTABLESIZE); - if (disp->port_table == NULL) { - goto deallocate_dispatch; - } + sizeof(disp->port_table[0]) * DNS_DISPATCH_PORTTABLESIZE); for (i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++) { ISC_LIST_INIT(disp->port_table[i]); } @@ -3641,17 +3613,11 @@ dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr, mgr = source->mgr; dset = isc_mem_get(mctx, sizeof(dns_dispatchset_t)); - if (dset == NULL) - return (ISC_R_NOMEMORY); memset(dset, 0, sizeof(*dset)); isc_mutex_init(&dset->lock); dset->dispatches = isc_mem_get(mctx, sizeof(dns_dispatch_t *) * n); - if (dset->dispatches == NULL) { - result = ISC_R_NOMEMORY; - goto fail_lock; - } isc_mem_attach(mctx, &dset->mctx); dset->ndisp = n; @@ -3687,7 +3653,6 @@ dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr, if (dset->mctx == mctx) isc_mem_detach(&dset->mctx); - fail_lock: isc_mutex_destroy(&dset->lock); isc_mem_put(mctx, dset, sizeof(dns_dispatchset_t)); return (result); diff --git a/lib/dns/dlz.c b/lib/dns/dlz.c index b475e36dfe..ba575ba70c 100644 --- a/lib/dns/dlz.c +++ b/lib/dns/dlz.c @@ -198,10 +198,6 @@ dns_dlzcreate(isc_mem_t *mctx, const char *dlzname, const char *drivername, /* Allocate memory to hold the DLZ database driver */ db = isc_mem_get(mctx, sizeof(dns_dlzdb_t)); - if (db == NULL) { - RWUNLOCK(&dlz_implock, isc_rwlocktype_read); - return (ISC_R_NOMEMORY); - } /* Make sure memory region is set to all 0's */ memset(db, 0, sizeof(dns_dlzdb_t)); @@ -324,10 +320,6 @@ dns_dlzregister(const char *drivername, const dns_dlzmethods_t *methods, * we cannot. */ dlz_imp = isc_mem_get(mctx, sizeof(dns_dlzimplementation_t)); - if (dlz_imp == NULL) { - RWUNLOCK(&dlz_implock, isc_rwlocktype_write); - return (ISC_R_NOMEMORY); - } /* Make sure memory region is set to all 0's */ memset(dlz_imp, 0, sizeof(dns_dlzimplementation_t)); diff --git a/lib/dns/dns64.c b/lib/dns/dns64.c index f69f3cdbd0..0e5c18b677 100644 --- a/lib/dns/dns64.c +++ b/lib/dns/dns64.c @@ -74,8 +74,6 @@ dns_dns64_create(isc_mem_t *mctx, const isc_netaddr_t *prefix, } dns64 = isc_mem_get(mctx, sizeof(dns_dns64_t)); - if (dns64 == NULL) - return (ISC_R_NOMEMORY); memset(dns64->bits, 0, sizeof(dns64->bits)); memmove(dns64->bits, prefix->type.in6.s6_addr, prefixlen / 8); if (suffix != NULL) diff --git a/lib/dns/dnsrps.c b/lib/dns/dnsrps.c index d9368140e1..2e33a0d19e 100644 --- a/lib/dns/dnsrps.c +++ b/lib/dns/dnsrps.c @@ -251,10 +251,6 @@ dns_dnsrps_rewrite_init(librpz_emsg_t *emsg, dns_rpz_st_t *st, rpsdb_t *rpsdb; rpsdb = isc_mem_get(mctx, sizeof(*rpsdb)); - if (rpsdb == NULL) { - strlcpy(emsg->c, "no memory", sizeof(emsg->c)); - return (ISC_R_NOMEMORY); - } memset(rpsdb, 0, sizeof(*rpsdb)); if (!librpz->rsp_create(emsg, &rpsdb->rsp, NULL, @@ -628,8 +624,6 @@ rpsdb_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(node == &rpsdb->origin_node || node == &rpsdb->data_node); rpsdb_iter = isc_mem_get(rpsdb->common.mctx, sizeof(*rpsdb_iter)); - if (rpsdb_iter == NULL) - return (ISC_R_NOMEMORY); memset(rpsdb_iter, 0, sizeof(*rpsdb_iter)); rpsdb_iter->common.magic = DNS_RDATASETITER_MAGIC; diff --git a/lib/dns/dnssec.c b/lib/dns/dnssec.c index b51f411dac..b99803489d 100644 --- a/lib/dns/dnssec.c +++ b/lib/dns/dnssec.c @@ -103,8 +103,6 @@ rdataset_to_sortedarray(dns_rdataset_t *set, isc_mem_t *mctx, n = dns_rdataset_count(set); data = isc_mem_get(mctx, n * sizeof(dns_rdata_t)); - if (data == NULL) - return (ISC_R_NOMEMORY); dns_rdataset_init(&rdataset); dns_rdataset_clone(set, &rdataset); @@ -257,8 +255,6 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, * they're not used in digest_sig(). */ sig.signature = isc_mem_get(mctx, sig.siglen); - if (sig.signature == NULL) - return (ISC_R_NOMEMORY); ret = isc_buffer_allocate(mctx, &databuf, sigsize + 256 + 18); if (ret != ISC_R_SUCCESS) @@ -960,11 +956,7 @@ dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) { RETERR(dst_key_sigsize(key, &sigsize)); sig.siglen = sigsize; - sig.signature = (unsigned char *) isc_mem_get(mctx, sig.siglen); - if (sig.signature == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } + sig.signature = isc_mem_get(mctx, sig.siglen); isc_buffer_init(&sigbuf, sig.signature, sig.siglen); RETERR(dst_context_sign(ctx, &sigbuf)); @@ -1220,8 +1212,6 @@ dns_dnsseckey_create(isc_mem_t *mctx, dst_key_t **dstkey, REQUIRE(dkp != NULL && *dkp == NULL); dk = isc_mem_get(mctx, sizeof(dns_dnsseckey_t)); - if (dk == NULL) - return (ISC_R_NOMEMORY); dk->key = *dstkey; *dstkey = NULL; diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index 37920a3f38..491ee62a16 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -1005,8 +1005,6 @@ dns_dt_open(const char *filename, dns_dtmode_t mode, isc_mem_t *mctx, REQUIRE(handlep != NULL && *handlep == NULL); handle = isc_mem_get(mctx, sizeof(*handle)); - if (handle == NULL) - CHECK(ISC_R_NOMEMORY); handle->mode = mode; handle->mctx = NULL; @@ -1107,8 +1105,6 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) { REQUIRE(destp != NULL && *destp == NULL); d = isc_mem_get(mctx, sizeof(*d)); - if (d == NULL) - return (ISC_R_NOMEMORY); memset(d, 0, sizeof(*d)); isc_mem_attach(mctx, &d->mctx); diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index 0cd9e8752b..1d1f258e54 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -239,8 +239,6 @@ dst_context_create(dst_key_t *key, isc_mem_t *mctx, return (DST_R_NULLKEY); dctx = isc_mem_get(mctx, sizeof(dst_context_t)); - if (dctx == NULL) - return (ISC_R_NOMEMORY); memset(dctx, 0, sizeof(*dctx)); dst_key_attach(key, &dctx->key); isc_mem_attach(mctx, &dctx->mctx); @@ -508,8 +506,6 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, if (dirname != NULL) newfilenamelen += strlen(dirname) + 1; newfilename = isc_mem_get(mctx, newfilenamelen); - if (newfilename == NULL) - return (ISC_R_NOMEMORY); result = addsuffix(newfilename, newfilenamelen, dirname, filename, ".key"); INSIST(result == ISC_R_SUCCESS); @@ -552,8 +548,6 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, if (dirname != NULL) newfilenamelen += strlen(dirname) + 1; newfilename = isc_mem_get(mctx, newfilenamelen); - if (newfilename == NULL) - RETERR(ISC_R_NOMEMORY); result = addsuffix(newfilename, newfilenamelen, dirname, filename, ".private"); INSIST(result == ISC_R_SUCCESS); @@ -1275,17 +1269,11 @@ get_key_struct(const dns_name_t *name, unsigned int alg, isc_result_t result; int i; - key = (dst_key_t *) isc_mem_get(mctx, sizeof(dst_key_t)); - if (key == NULL) - return (NULL); + key = isc_mem_get(mctx, sizeof(dst_key_t)); memset(key, 0, sizeof(dst_key_t)); key->key_name = isc_mem_get(mctx, sizeof(dns_name_t)); - if (key->key_name == NULL) { - isc_mem_put(mctx, key, sizeof(dst_key_t)); - return (NULL); - } dns_name_init(key->key_name, NULL); result = dns_name_dup(name, mctx, key->key_name); diff --git a/lib/dns/dst_parse.c b/lib/dns/dst_parse.c index 0dab7af8e3..4b83617a21 100644 --- a/lib/dns/dst_parse.c +++ b/lib/dns/dst_parse.c @@ -541,9 +541,7 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, priv->elements[n].tag = tag; - data = (unsigned char *) isc_mem_get(mctx, MAXFIELDSIZE); - if (data == NULL) - goto fail; + data = isc_mem_get(mctx, MAXFIELDSIZE); isc_buffer_init(&b, data, MAXFIELDSIZE); ret = isc_base64_tobuffer(lex, &b, -1); diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index d89798a0a8..7d80dc1f6d 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -161,8 +161,6 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, (void **)&destroy_func)); imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t)); - if (imp == NULL) - CHECK(ISC_R_NOMEMORY); imp->mctx = NULL; isc_mem_attach(mctx, &imp->mctx); @@ -277,8 +275,6 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, (void **)&destroy_func)); imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t)); - if (imp == NULL) - CHECK(ISC_R_NOMEMORY); imp->mctx = NULL; isc_mem_attach(mctx, &imp->mctx); @@ -419,8 +415,6 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, REQUIRE(dctxp != NULL && *dctxp == NULL); dctx = isc_mem_get(mctx, sizeof(*dctx)); - if (dctx == NULL) - return (ISC_R_NOMEMORY); memset(dctx, 0, sizeof(*dctx)); if (view != NULL) diff --git a/lib/dns/ecdb.c b/lib/dns/ecdb.c index fc349e82c6..126091138c 100644 --- a/lib/dns/ecdb.c +++ b/lib/dns/ecdb.c @@ -343,8 +343,6 @@ findnode(dns_db_t *db, const dns_name_t *name, bool create, mctx = ecdb->common.mctx; node = isc_mem_get(mctx, sizeof(*node)); - if (node == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&node->lock); @@ -511,8 +509,6 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, mctx = ecdb->common.mctx; iterator = isc_mem_get(mctx, sizeof(ecdb_rdatasetiter_t)); - if (iterator == NULL) - return (ISC_R_NOMEMORY); iterator->common.magic = DNS_RDATASETITER_MAGIC; iterator->common.methods = &rdatasetiter_methods; @@ -596,8 +592,6 @@ dns_ecdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, UNUSED(driverarg); ecdb = isc_mem_get(mctx, sizeof(*ecdb)); - if (ecdb == NULL) - return (ISC_R_NOMEMORY); ecdb->common.attributes = DNS_DBATTR_CACHE; ecdb->common.rdclass = rdclass; diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 66fc295a7b..712602d297 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -44,8 +44,6 @@ dns_fwdtable_create(isc_mem_t *mctx, dns_fwdtable_t **fwdtablep) { REQUIRE(fwdtablep != NULL && *fwdtablep == NULL); fwdtable = isc_mem_get(mctx, sizeof(dns_fwdtable_t)); - if (fwdtable == NULL) - return (ISC_R_NOMEMORY); fwdtable->table = NULL; result = dns_rbt_create(mctx, auto_detach, fwdtable, &fwdtable->table); @@ -83,8 +81,6 @@ dns_fwdtable_addfwd(dns_fwdtable_t *fwdtable, const dns_name_t *name, REQUIRE(VALID_FWDTABLE(fwdtable)); forwarders = isc_mem_get(fwdtable->mctx, sizeof(dns_forwarders_t)); - if (forwarders == NULL) - return (ISC_R_NOMEMORY); ISC_LIST_INIT(forwarders->fwdrs); for (fwd = ISC_LIST_HEAD(*fwdrs); @@ -92,10 +88,6 @@ dns_fwdtable_addfwd(dns_fwdtable_t *fwdtable, const dns_name_t *name, fwd = ISC_LIST_NEXT(fwd, link)) { nfwd = isc_mem_get(fwdtable->mctx, sizeof(dns_forwarder_t)); - if (nfwd == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } *nfwd = *fwd; ISC_LINK_INIT(nfwd, link); ISC_LIST_APPEND(forwarders->fwdrs, nfwd, link); @@ -133,8 +125,6 @@ dns_fwdtable_add(dns_fwdtable_t *fwdtable, const dns_name_t *name, REQUIRE(VALID_FWDTABLE(fwdtable)); forwarders = isc_mem_get(fwdtable->mctx, sizeof(dns_forwarders_t)); - if (forwarders == NULL) - return (ISC_R_NOMEMORY); ISC_LIST_INIT(forwarders->fwdrs); for (sa = ISC_LIST_HEAD(*addrs); @@ -142,10 +132,6 @@ dns_fwdtable_add(dns_fwdtable_t *fwdtable, const dns_name_t *name, sa = ISC_LIST_NEXT(sa, link)) { fwd = isc_mem_get(fwdtable->mctx, sizeof(dns_forwarder_t)); - if (fwd == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } fwd->addr = *sa; fwd->dscp = -1; ISC_LINK_INIT(fwd, link); diff --git a/lib/dns/geoip2.c b/lib/dns/geoip2.c index 80cb6169f7..c2cd08a804 100644 --- a/lib/dns/geoip2.c +++ b/lib/dns/geoip2.c @@ -145,8 +145,7 @@ set_state(const MMDB_s *db, const isc_netaddr_t *addr, state = (geoip_state_t *) isc_thread_key_getspecific(state_key); if (state == NULL) { - state = (geoip_state_t *) isc_mem_get(state_mctx, - sizeof(geoip_state_t)); + state = isc_mem_get(state_mctx, sizeof(geoip_state_t)); memset(state, 0, sizeof(*state)); result = isc_thread_key_setspecific(state_key, state); diff --git a/lib/dns/gssapi_link.c b/lib/dns/gssapi_link.c index ed9c0a4c15..8cbf5771ae 100644 --- a/lib/dns/gssapi_link.c +++ b/lib/dns/gssapi_link.c @@ -59,8 +59,6 @@ gssapi_create_signverify_ctx(dst_key_t *key, dst_context_t *dctx) { UNUSED(key); ctx = isc_mem_get(dctx->mctx, sizeof(dst_gssapi_signverifyctx_t)); - if (ctx == NULL) - return (ISC_R_NOMEMORY); ctx->buffer = NULL; result = isc_buffer_allocate(dctx->mctx, &ctx->buffer, INITIAL_BUFFER_SIZE); @@ -322,10 +320,6 @@ gssapi_dump(dst_key_t *key, isc_mem_t *mctx, char **buffer, int *length) { return (ISC_R_FAILURE); len = ((gssbuffer.length + 2)/3) * 4; buf = isc_mem_get(mctx, len); - if (buf == NULL) { - gss_release_buffer(&minor, &gssbuffer); - return (ISC_R_NOMEMORY); - } isc_buffer_init(&b, buf, (unsigned int)len); GBUFFER_TO_REGION(gssbuffer, r); result = isc_base64_totext(&r, 0, "", &b); diff --git a/lib/dns/hmac_link.c b/lib/dns/hmac_link.c index 6fb04ed23d..cf916ddfa1 100644 --- a/lib/dns/hmac_link.c +++ b/lib/dns/hmac_link.c @@ -348,9 +348,6 @@ hmac_fromdns(isc_md_type_t type, dst_key_t *key, isc_buffer_t *data) { } hkey = isc_mem_get(key->mctx, sizeof(dst_hmac_key_t)); - if (hkey == NULL) { - return (ISC_R_NOMEMORY); - } memset(hkey->key, 0, sizeof(hkey->key)); diff --git a/lib/dns/ipkeylist.c b/lib/dns/ipkeylist.c index 9a008e9f7d..55d5ae0c6e 100644 --- a/lib/dns/ipkeylist.c +++ b/lib/dns/ipkeylist.c @@ -103,10 +103,6 @@ dns_ipkeylist_copy(isc_mem_t *mctx, const dns_ipkeylist_t *src, if (src->keys[i] != NULL) { dst->keys[i] = isc_mem_get(mctx, sizeof(dns_name_t)); - if (dst->keys[i] == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_keys; - } dns_name_init(dst->keys[i], NULL); result = dns_name_dup(src->keys[i], mctx, dst->keys[i]); @@ -122,11 +118,7 @@ dns_ipkeylist_copy(isc_mem_t *mctx, const dns_ipkeylist_t *src, for (i = 0; i < src->count; i++) { if (src->labels[i] != NULL) { dst->labels[i] = isc_mem_get(mctx, - sizeof(dns_name_t)); - if (dst->labels[i] == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_labels; - } + sizeof(dns_name_t)); dns_name_init(dst->labels[i], NULL); result = dns_name_dup(src->labels[i], mctx, dst->labels[i]); @@ -177,17 +169,9 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) { return (ISC_R_SUCCESS); addrs = isc_mem_get(mctx, n * sizeof(isc_sockaddr_t)); - if (addrs == NULL) - goto nomemory; dscps = isc_mem_get(mctx, n * sizeof(isc_dscp_t)); - if (dscps == NULL) - goto nomemory; keys = isc_mem_get(mctx, n * sizeof(dns_name_t *)); - if (keys == NULL) - goto nomemory; labels = isc_mem_get(mctx, n * sizeof(dns_name_t *)); - if (labels == NULL) - goto nomemory; if (ipkl->addrs != NULL) { memmove(addrs, ipkl->addrs, @@ -232,15 +216,10 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) { ipkl->allocated = n; return (ISC_R_SUCCESS); -nomemory: - if (addrs != NULL) - isc_mem_put(mctx, addrs, n * sizeof(isc_sockaddr_t)); - if (dscps != NULL) - isc_mem_put(mctx, dscps, n * sizeof(isc_dscp_t)); - if (keys != NULL) - isc_mem_put(mctx, keys, n * sizeof(dns_name_t *)); - if (labels != NULL) - isc_mem_put(mctx, labels, n * sizeof(dns_name_t *)); + isc_mem_put(mctx, addrs, n * sizeof(isc_sockaddr_t)); + isc_mem_put(mctx, dscps, n * sizeof(isc_dscp_t)); + isc_mem_put(mctx, keys, n * sizeof(dns_name_t *)); + isc_mem_put(mctx, labels, n * sizeof(dns_name_t *)); return (ISC_R_NOMEMORY); } diff --git a/lib/dns/iptable.c b/lib/dns/iptable.c index d1a20fe1c8..bc10e871fd 100644 --- a/lib/dns/iptable.c +++ b/lib/dns/iptable.c @@ -29,8 +29,6 @@ dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) { dns_iptable_t *tab; tab = isc_mem_get(mctx, sizeof(*tab)); - if (tab == NULL) - return (ISC_R_NOMEMORY); tab->mctx = NULL; isc_mem_attach(mctx, &tab->mctx); isc_refcount_init(&tab->refcount, 1); diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 00ec3d7727..1912f2a2fd 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -514,11 +514,6 @@ journal_file_create(isc_mem_t *mctx, const char *filename) { index_size * sizeof(journal_rawpos_t); mem = isc_mem_get(mctx, size); - if (mem == NULL) { - (void)isc_stdio_close(fp); - (void)isc_file_remove(filename); - return (ISC_R_NOMEMORY); - } memset(mem, 0, size); memmove(mem, &rawheader, sizeof(rawheader)); @@ -557,8 +552,6 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, INSIST(journalp != NULL && *journalp == NULL); j = isc_mem_get(mctx, sizeof(*j)); - if (j == NULL) - return (ISC_R_NOMEMORY); j->mctx = NULL; isc_mem_attach(mctx, &j->mctx); @@ -624,15 +617,11 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, rawbytes = j->header.index_size * sizeof(journal_rawpos_t); j->rawindex = isc_mem_get(mctx, rawbytes); - if (j->rawindex == NULL) - FAIL(ISC_R_NOMEMORY); CHECK(journal_read(j, j->rawindex, rawbytes)); - j->index = isc_mem_get(mctx, j->header.index_size * - sizeof(journal_pos_t)); - if (j->index == NULL) - FAIL(ISC_R_NOMEMORY); + j->index = isc_mem_get(mctx, + j->header.index_size * sizeof(journal_pos_t)); p = j->rawindex; for (i = 0; i < j->header.index_size; i++) { @@ -1047,8 +1036,6 @@ dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff) { } mem = isc_mem_get(j->mctx, size); - if (mem == NULL) - return (ISC_R_NOMEMORY); isc_buffer_init(&buffer, mem, size); @@ -2232,10 +2219,6 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, if (copy_length < size) size = copy_length; buf = isc_mem_get(mctx, size); - if (buf == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } CHECK(journal_seek(j1, best_guess.offset)); CHECK(journal_seek(j2, indexend)); diff --git a/lib/dns/keytable.c b/lib/dns/keytable.c index 9a72d8f94e..bd7b18068a 100644 --- a/lib/dns/keytable.c +++ b/lib/dns/keytable.c @@ -72,9 +72,6 @@ dns_keytable_create(isc_mem_t *mctx, dns_keytable_t **keytablep) { REQUIRE(keytablep != NULL && *keytablep == NULL); keytable = isc_mem_get(mctx, sizeof(*keytable)); - if (keytable == NULL) { - return (ISC_R_NOMEMORY); - } keytable->table = NULL; result = dns_rbt_create(mctx, free_keynode, mctx, &keytable->table); @@ -778,8 +775,6 @@ dns_keynode_create(isc_mem_t *mctx, dns_keynode_t **target) { REQUIRE(target != NULL && *target == NULL); knode = isc_mem_get(mctx, sizeof(dns_keynode_t)); - if (knode == NULL) - return (ISC_R_NOMEMORY); knode->magic = KEYNODE_MAGIC; knode->managed = false; diff --git a/lib/dns/lookup.c b/lib/dns/lookup.c index 0b40ff1116..47196c38f5 100644 --- a/lib/dns/lookup.c +++ b/lib/dns/lookup.c @@ -102,10 +102,6 @@ build_event(dns_lookup_t *lookup) { isc_result_t result; name = isc_mem_get(lookup->mctx, sizeof(dns_name_t)); - if (name == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } dns_name_init(name, NULL); result = dns_name_dup(dns_fixedname_name(&lookup->name), lookup->mctx, name); @@ -114,10 +110,6 @@ build_event(dns_lookup_t *lookup) { if (dns_rdataset_isassociated(&lookup->rdataset)) { rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t)); - if (rdataset == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } dns_rdataset_init(rdataset); dns_rdataset_clone(&lookup->rdataset, rdataset); } @@ -125,10 +117,6 @@ build_event(dns_lookup_t *lookup) { if (dns_rdataset_isassociated(&lookup->sigrdataset)) { sigrdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t)); - if (sigrdataset == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } dns_rdataset_init(sigrdataset); dns_rdataset_clone(&lookup->sigrdataset, sigrdataset); } @@ -383,8 +371,6 @@ dns_lookup_create(isc_mem_t *mctx, const dns_name_t *name, dns_rdatatype_t type, isc_event_t *ievent; lookup = isc_mem_get(mctx, sizeof(*lookup)); - if (lookup == NULL) - return (ISC_R_NOMEMORY); lookup->mctx = NULL; isc_mem_attach(mctx, &lookup->mctx); lookup->options = options; diff --git a/lib/dns/master.c b/lib/dns/master.c index 3a38873c95..73ffb31580 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -469,8 +469,6 @@ incctx_create(isc_mem_t *mctx, dns_name_t *origin, dns_incctx_t **ictxp) { int i; ictx = isc_mem_get(mctx, sizeof(*ictx)); - if (ictx == NULL) - return (ISC_R_NOMEMORY); for (i = 0; i < NBUFS; i++) { dns_fixedname_init(&ictx->fixed[i]); @@ -523,8 +521,6 @@ loadctx_create(dns_masterformat_t format, isc_mem_t *mctx, (task != NULL && done != NULL)); lctx = isc_mem_get(mctx, sizeof(*lctx)); - if (lctx == NULL) - return (ISC_R_NOMEMORY); lctx->inc = NULL; result = incctx_create(mctx, origin, &lctx->inc); @@ -1082,10 +1078,6 @@ load_text(dns_loadctx_t *lctx) { * the maximum individual RR data size. */ target_mem = isc_mem_get(mctx, target_size); - if (target_mem == NULL) { - result = ISC_R_NOMEMORY; - goto log_and_cleanup; - } isc_buffer_init(&target, target_mem, target_size); target_save = target; @@ -2331,10 +2323,6 @@ load_raw(dns_loadctx_t *lctx) { * the maximum individual RR data size. */ target_mem = isc_mem_get(mctx, target_size); - if (target_mem == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } isc_buffer_init(&target, target_mem, target_size); name = dns_fixedname_initname(&fixed); diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index 4177adff75..46fcb49f88 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -914,8 +914,6 @@ dump_rdataset(isc_mem_t *mctx, const dns_name_t *name, newlength = buffer->length * 2; newmem = isc_mem_get(mctx, newlength); - if (newmem == NULL) - return (ISC_R_NOMEMORY); isc_mem_put(mctx, buffer->base, buffer->length); isc_buffer_init(buffer, newmem, newlength); } @@ -1158,8 +1156,6 @@ dump_rdataset_raw(isc_mem_t *mctx, const dns_name_t *name, newlength = buffer->length * 2; newmem = isc_mem_get(mctx, newlength); - if (newmem == NULL) - return (ISC_R_NOMEMORY); isc_mem_put(mctx, buffer->base, buffer->length); isc_buffer_init(buffer, newmem, newlength); goto restart; @@ -1456,8 +1452,6 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, unsigned int options; dctx = isc_mem_get(mctx, sizeof(*dctx)); - if (dctx == NULL) - return (ISC_R_NOMEMORY); dctx->mctx = NULL; dctx->f = f; @@ -1557,8 +1551,6 @@ writeheader(dns_dumpctx_t *dctx) { uint32_t rawversion, now32; bufmem = isc_mem_get(dctx->mctx, initial_buffer_length); - if (bufmem == NULL) - return (ISC_R_NOMEMORY); isc_buffer_init(&buffer, bufmem, initial_buffer_length); @@ -1632,8 +1624,6 @@ dumptostreaminc(dns_dumpctx_t *dctx) { isc_time_t start; bufmem = isc_mem_get(dctx->mctx, initial_buffer_length); - if (bufmem == NULL) - return (ISC_R_NOMEMORY); isc_buffer_init(&buffer, bufmem, initial_buffer_length); @@ -1953,8 +1943,6 @@ dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db, isc_stdtime_get(&now); bufmem = isc_mem_get(mctx, initial_buffer_length); - if (bufmem == NULL) - return (ISC_R_NOMEMORY); isc_buffer_init(&buffer, bufmem, initial_buffer_length); @@ -2031,8 +2019,6 @@ dns_master_stylecreate(dns_master_style_t **stylep, REQUIRE(stylep != NULL && *stylep == NULL); style = isc_mem_get(mctx, sizeof(*style)); - if (style == NULL) - return (ISC_R_NOMEMORY); style->flags = flags; style->ttl_column = ttl_column; diff --git a/lib/dns/message.c b/lib/dns/message.c index 24580444d8..a3f9a5187d 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -189,8 +189,6 @@ msgblock_allocate(isc_mem_t *mctx, unsigned int sizeof_type, length = sizeof(dns_msgblock_t) + (sizeof_type * count); block = isc_mem_get(mctx, length); - if (block == NULL) - return (NULL); block->count = count; block->remaining = count; @@ -713,8 +711,6 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) || intent == DNS_MESSAGE_INTENTRENDER); m = isc_mem_get(mctx, sizeof(dns_message_t)); - if (m == NULL) - return (ISC_R_NOMEMORY); /* * No allocations until further notice. Just initialize all lists @@ -1768,8 +1764,6 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, else { msg->saved.length = isc_buffer_usedlength(&origsource); msg->saved.base = isc_mem_get(msg->mctx, msg->saved.length); - if (msg->saved.base == NULL) - return (ISC_R_NOMEMORY); memmove(msg->saved.base, isc_buffer_base(&origsource), msg->saved.length); msg->free_saved = 1; @@ -4302,8 +4296,6 @@ logfmtpacket(dns_message_t *message, const char *description, do { buf = isc_mem_get(mctx, len); - if (buf == NULL) - break; isc_buffer_init(&buffer, buf, len); result = dns_message_totext(message, style, 0, &buffer); if (result == ISC_R_NOSPACE) { diff --git a/lib/dns/name.c b/lib/dns/name.c index 2c3ce4a8e8..bd463d7afc 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -2177,8 +2177,6 @@ dns_name_dup(const dns_name_t *source, isc_mem_t *mctx, MAKE_EMPTY(target); target->ndata = isc_mem_get(mctx, source->length); - if (target->ndata == NULL) - return (ISC_R_NOMEMORY); memmove(target->ndata, source->ndata, source->length); @@ -2219,8 +2217,6 @@ dns_name_dupwithoffsets(const dns_name_t *source, isc_mem_t *mctx, MAKE_EMPTY(target); target->ndata = isc_mem_get(mctx, source->length + source->labels); - if (target->ndata == NULL) - return (ISC_R_NOMEMORY); memmove(target->ndata, source->ndata, source->length); @@ -2353,8 +2349,6 @@ dns_name_settotextfilter(dns_name_totextfilter_t proc) { } mem = isc_mem_get(thread_key_mctx, sizeof(*mem)); - if (mem == NULL) - return (ISC_R_NOMEMORY); *mem = proc; if (isc_thread_key_setspecific(totext_filter_proc_key, mem) != 0) { isc_mem_put(thread_key_mctx, mem, sizeof(*mem)); diff --git a/lib/dns/nta.c b/lib/dns/nta.c index c495c3cff4..6b44857d9e 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -110,8 +110,6 @@ dns_ntatable_create(dns_view_t *view, REQUIRE(ntatablep != NULL && *ntatablep == NULL); ntatable = isc_mem_get(view->mctx, sizeof(*ntatable)); - if (ntatable == NULL) - return (ISC_R_NOMEMORY); ntatable->task = NULL; result = isc_task_create(taskmgr, 0, &ntatable->task); @@ -301,8 +299,6 @@ nta_create(dns_ntatable_t *ntatable, const dns_name_t *name, view = ntatable->view; nta = isc_mem_get(view->mctx, sizeof(dns_nta_t)); - if (nta == NULL) - return (ISC_R_NOMEMORY); nta->ntatable = ntatable; nta->expiry = 0; diff --git a/lib/dns/openssldh_link.c b/lib/dns/openssldh_link.c index b30a134954..04cff0b1ee 100644 --- a/lib/dns/openssldh_link.c +++ b/lib/dns/openssldh_link.c @@ -588,10 +588,6 @@ openssldh_tofile(const dst_key_t *key, const char *directory) { memset(bufs, 0, sizeof(bufs)); for (i = 0; i < 4; i++) { bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(p)); - if (bufs[i] == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } } i = 0; @@ -622,7 +618,7 @@ openssldh_tofile(const dst_key_t *key, const char *directory) { priv.nelements = i; result = dst__privstruct_writefile(key, &priv, directory); - fail: + for (i = 0; i < 4; i++) { if (bufs[i] == NULL) break; diff --git a/lib/dns/opensslecdsa_link.c b/lib/dns/opensslecdsa_link.c index 0f2823d60f..895f16da45 100644 --- a/lib/dns/opensslecdsa_link.c +++ b/lib/dns/opensslecdsa_link.c @@ -488,8 +488,6 @@ opensslecdsa_tofile(const dst_key_t *key, const char *directory) { DST_RET (ISC_R_FAILURE); buf = isc_mem_get(key->mctx, BN_num_bytes(privkey)); - if (buf == NULL) - DST_RET (ISC_R_NOMEMORY); priv.elements[0].tag = TAG_ECDSA_PRIVATEKEY; priv.elements[0].length = BN_num_bytes(privkey); diff --git a/lib/dns/openssleddsa_link.c b/lib/dns/openssleddsa_link.c index 0a48db5b60..8357bee058 100644 --- a/lib/dns/openssleddsa_link.c +++ b/lib/dns/openssleddsa_link.c @@ -625,8 +625,6 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) { if (key->key_alg == DST_ALG_ED25519) { len = DNS_KEY_ED25519SIZE; buf = isc_mem_get(key->mctx, len); - if (buf == NULL) - return (ISC_R_NOMEMORY); priv.elements[0].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[0].length = len; ret = priv_ed25519_from_ossl(pkey, buf); @@ -638,8 +636,6 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) { } else { len = DNS_KEY_ED448SIZE; buf = isc_mem_get(key->mctx, len); - if (buf == NULL) - return (ISC_R_NOMEMORY); priv.elements[0].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[0].length = len; ret = priv_ed448_from_ossl(pkey, buf); diff --git a/lib/dns/opensslrsa_link.c b/lib/dns/opensslrsa_link.c index 1d4a0c1a10..4b557e0f87 100644 --- a/lib/dns/opensslrsa_link.c +++ b/lib/dns/opensslrsa_link.c @@ -702,10 +702,6 @@ opensslrsa_tofile(const dst_key_t *key, const char *directory) { for (i = 0; i < 8; i++) { bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(n)); - if (bufs[i] == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } } i = 0; diff --git a/lib/dns/order.c b/lib/dns/order.c index c531bf9b56..3b5c796230 100644 --- a/lib/dns/order.c +++ b/lib/dns/order.c @@ -51,8 +51,6 @@ dns_order_create(isc_mem_t *mctx, dns_order_t **orderp) { REQUIRE(orderp != NULL && *orderp == NULL); order = isc_mem_get(mctx, sizeof(*order)); - if (order == NULL) - return (ISC_R_NOMEMORY); ISC_LIST_INIT(order->ents); @@ -79,8 +77,6 @@ dns_order_add(dns_order_t *order, const dns_name_t *name, mode == DNS_RDATASETATTR_CYCLIC); ent = isc_mem_get(order->mctx, sizeof(*ent)); - if (ent == NULL) - return (ISC_R_NOMEMORY); dns_fixedname_init(&ent->name); RUNTIME_CHECK(dns_name_copy(name, dns_fixedname_name(&ent->name), NULL) diff --git a/lib/dns/peer.c b/lib/dns/peer.c index 992dada93b..04edb59170 100644 --- a/lib/dns/peer.c +++ b/lib/dns/peer.c @@ -59,8 +59,6 @@ dns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) { REQUIRE(list != NULL); l = isc_mem_get(mem, sizeof(*l)); - if (l == NULL) - return (ISC_R_NOMEMORY); ISC_LIST_INIT(l->elements); l->mem = mem; @@ -223,8 +221,6 @@ dns_peer_newprefix(isc_mem_t *mem, const isc_netaddr_t *addr, REQUIRE(peerptr != NULL); peer = isc_mem_get(mem, sizeof(*peer)); - if (peer == NULL) - return (ISC_R_NOMEMORY); peer->magic = DNS_PEER_MAGIC; peer->address = *addr; @@ -653,8 +649,6 @@ dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) { return (result); name = isc_mem_get(peer->mem, sizeof(dns_name_t)); - if (name == NULL) - return (ISC_R_NOMEMORY); dns_name_init(name, NULL); result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name); @@ -683,9 +677,7 @@ dns_peer_settransfersource(dns_peer_t *peer, } if (transfer_source != NULL) { peer->transfer_source = isc_mem_get(peer->mem, - sizeof(*peer->transfer_source)); - if (peer->transfer_source == NULL) - return (ISC_R_NOMEMORY); + sizeof(*peer->transfer_source)); *peer->transfer_source = *transfer_source; } @@ -716,9 +708,7 @@ dns_peer_setnotifysource(dns_peer_t *peer, } if (notify_source != NULL) { peer->notify_source = isc_mem_get(peer->mem, - sizeof(*peer->notify_source)); - if (peer->notify_source == NULL) - return (ISC_R_NOMEMORY); + sizeof(*peer->notify_source)); *peer->notify_source = *notify_source; } @@ -747,9 +737,7 @@ dns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) { } if (query_source != NULL) { peer->query_source = isc_mem_get(peer->mem, - sizeof(*peer->query_source)); - if (peer->query_source == NULL) - return (ISC_R_NOMEMORY); + sizeof(*peer->query_source)); *peer->query_source = *query_source; } diff --git a/lib/dns/pkcs11ecdsa_link.c b/lib/dns/pkcs11ecdsa_link.c index a8f6e1a158..1608008c19 100644 --- a/lib/dns/pkcs11ecdsa_link.c +++ b/lib/dns/pkcs11ecdsa_link.c @@ -85,10 +85,7 @@ pkcs11ecdsa_createctx(dst_key_t *key, dst_context_t *dctx) { else mech.mechanism = CKM_SHA384; - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); if (ec->ontoken && (dctx->use == DO_SIGN)) slotid = ec->slot; @@ -210,8 +207,6 @@ pkcs11ecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -220,8 +215,6 @@ pkcs11ecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -317,8 +310,6 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) { INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -327,8 +318,6 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -425,18 +414,14 @@ pkcs11ecdsa_compare(const dst_key_t *key1, const dst_key_t *key2) { #define SETCURVE() \ if (key->key_alg == DST_ALG_ECDSA256) { \ - attr->pValue = isc_mem_get(key->mctx, \ - sizeof(pk11_ecc_prime256v1)); \ - if (attr->pValue == NULL) \ - DST_RET(ISC_R_NOMEMORY); \ + attr->pValue = isc_mem_get(key->mctx, sizeof(pk11_ecc_prime256v1)); \ + \ memmove(attr->pValue, \ pk11_ecc_prime256v1, sizeof(pk11_ecc_prime256v1)); \ attr->ulValueLen = sizeof(pk11_ecc_prime256v1); \ } else { \ - attr->pValue = isc_mem_get(key->mctx, \ - sizeof(pk11_ecc_secp384r1)); \ - if (attr->pValue == NULL) \ - DST_RET(ISC_R_NOMEMORY); \ + attr->pValue = isc_mem_get(key->mctx, sizeof(pk11_ecc_secp384r1)); \ + \ memmove(attr->pValue, \ pk11_ecc_secp384r1, sizeof(pk11_ecc_secp384r1)); \ attr->ulValueLen = sizeof(pk11_ecc_secp384r1); \ @@ -487,23 +472,16 @@ pkcs11ecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { UNUSED(unused); UNUSED(callback); - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, false, NULL, pk11_get_best_token(OP_ECDSA)); if (ret != ISC_R_SUCCESS) goto err; - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - DST_RET(ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); key->keydata.pkey = ec; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 3); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 3); memset(ec->repr, 0, sizeof(*attr) * 3); ec->attrcnt = 3; @@ -533,8 +511,6 @@ pkcs11ecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { (pk11_ctx->session, pub, attr, 1), DST_R_CRYPTOFAILURE); attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr->pValue, 0, attr->ulValueLen); PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, pub, attr, 1), @@ -545,8 +521,6 @@ pkcs11ecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { (pk11_ctx->session, priv, attr, 1), DST_R_CRYPTOFAILURE); attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr->pValue, 0, attr->ulValueLen); PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, priv, attr, 1), @@ -675,30 +649,22 @@ pkcs11ecdsa_fromdns(dst_key_t *key, isc_buffer_t *data) { if (r.length != len) return (DST_R_INVALIDPUBLICKEY); - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - return (ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - goto nomemory; + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; attr->type = CKA_EC_PARAMS; if (key->key_alg == DST_ALG_ECDSA256) { - attr->pValue = - isc_mem_get(key->mctx, sizeof(pk11_ecc_prime256v1)); - if (attr->pValue == NULL) - goto nomemory; + attr->pValue = isc_mem_get(key->mctx, + sizeof(pk11_ecc_prime256v1)); memmove(attr->pValue, pk11_ecc_prime256v1, sizeof(pk11_ecc_prime256v1)); attr->ulValueLen = sizeof(pk11_ecc_prime256v1); } else { - attr->pValue = - isc_mem_get(key->mctx, sizeof(pk11_ecc_secp384r1)); - if (attr->pValue == NULL) - goto nomemory; + attr->pValue = isc_mem_get(key->mctx, + sizeof(pk11_ecc_secp384r1)); memmove(attr->pValue, pk11_ecc_secp384r1, sizeof(pk11_ecc_secp384r1)); attr->ulValueLen = sizeof(pk11_ecc_secp384r1); @@ -707,8 +673,6 @@ pkcs11ecdsa_fromdns(dst_key_t *key, isc_buffer_t *data) { attr++; attr->type = CKA_EC_POINT; attr->pValue = isc_mem_get(key->mctx, len + 3); - if (attr->pValue == NULL) - goto nomemory; ((CK_BYTE_PTR) attr->pValue)[0] = TAG_OCTECT_STRING; ((CK_BYTE_PTR) attr->pValue)[1] = len + 1; ((CK_BYTE_PTR) attr->pValue)[2] = UNCOMPRESSED; @@ -762,8 +726,6 @@ pkcs11ecdsa_tofile(const dst_key_t *key, const char *directory) { attr = pk11_attribute_bytype(ec, CKA_VALUE); if (attr != NULL) { buf = isc_mem_get(key->mctx, attr->ulValueLen); - if (buf == NULL) - return (ISC_R_NOMEMORY); priv.elements[i].tag = TAG_ECDSA_PRIVATEKEY; priv.elements[i].length = (unsigned short) attr->ulValueLen; memmove(buf, attr->pValue, attr->ulValueLen); @@ -826,9 +788,7 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, ec->object = CK_INVALID_HANDLE; ec->ontoken = true; ec->reqlogon = true; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - return (ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(ec->repr, 0, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; @@ -837,8 +797,6 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, pubattr = pk11_attribute_bytype(pubec, CKA_EC_PARAMS); INSIST(pubattr != NULL); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; attr++; @@ -847,8 +805,6 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, pubattr = pk11_attribute_bytype(pubec, CKA_EC_POINT); INSIST(pubattr != NULL); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; @@ -856,10 +812,7 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, ec->reqlogon, NULL, ec->slot); if (ret != ISC_R_SUCCESS) @@ -957,9 +910,7 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { break; } } - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - DST_RET(ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); key->keydata.pkey = ec; @@ -973,9 +924,7 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { return (ret); } - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 3); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 3); memset(ec->repr, 0, sizeof(*attr) * 3); ec->attrcnt = 3; @@ -984,8 +933,6 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { pattr = pk11_attribute_bytype(pub->keydata.pkey, CKA_EC_PARAMS); INSIST(pattr != NULL); attr->pValue = isc_mem_get(key->mctx, pattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pattr->pValue, pattr->ulValueLen); attr->ulValueLen = pattr->ulValueLen; @@ -994,16 +941,12 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { pattr = pk11_attribute_bytype(pub->keydata.pkey, CKA_EC_POINT); INSIST(pattr != NULL); attr->pValue = isc_mem_get(key->mctx, pattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pattr->pValue, pattr->ulValueLen); attr->ulValueLen = pattr->ulValueLen; attr++; attr->type = CKA_VALUE; attr->pValue = isc_mem_get(key->mctx, priv.elements[0].length); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, priv.elements[0].data, priv.elements[0].length); attr->ulValueLen = priv.elements[0].length; @@ -1047,18 +990,14 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, UNUSED(pin); - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - return (ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); ec->object = CK_INVALID_HANDLE; ec->ontoken = true; ec->reqlogon = true; key->keydata.pkey = ec; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(ec->repr, 0, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; @@ -1069,10 +1008,7 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, ec->reqlogon, NULL, ec->slot); if (ret != ISC_R_SUCCESS) @@ -1105,8 +1041,6 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, DST_R_CRYPTOFAILURE); for (i = 0; i <= 1; i++) { attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen); - if (attr[i].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr[i].pValue, 0, attr[i].ulValueLen); } PK11_RET(pkcs_C_GetAttributeValue, diff --git a/lib/dns/pkcs11eddsa_link.c b/lib/dns/pkcs11eddsa_link.c index a14a4cba20..36c3daedad 100644 --- a/lib/dns/pkcs11eddsa_link.c +++ b/lib/dns/pkcs11eddsa_link.c @@ -158,10 +158,7 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { else siglen = DNS_SIG_ED448SIZE; - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); if (ec->ontoken && (dctx->use == DO_SIGN)) slotid = ec->slot; @@ -190,8 +187,6 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -200,8 +195,6 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -284,10 +277,7 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) { key->key_alg == DST_ALG_ED448); REQUIRE(ec != NULL); - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); if (ec->ontoken && (dctx->use == DO_SIGN)) slotid = ec->slot; @@ -306,8 +296,6 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) { INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -316,8 +304,6 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) { /* keyTemplate[6].type is CKA_VALUE */ keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -417,18 +403,14 @@ pkcs11eddsa_compare(const dst_key_t *key1, const dst_key_t *key2) { #define SETCURVE() \ if (key->key_alg == DST_ALG_ED25519) { \ - attr->pValue = isc_mem_get(key->mctx, \ - sizeof(pk11_ecc_ed25519)); \ - if (attr->pValue == NULL) \ - DST_RET(ISC_R_NOMEMORY); \ + attr->pValue = isc_mem_get(key->mctx, sizeof(pk11_ecc_ed25519)); \ + \ memmove(attr->pValue, \ pk11_ecc_ed25519, sizeof(pk11_ecc_ed25519)); \ attr->ulValueLen = sizeof(pk11_ecc_ed25519); \ } else { \ - attr->pValue = isc_mem_get(key->mctx, \ - sizeof(pk11_ecc_ed448)); \ - if (attr->pValue == NULL) \ - DST_RET(ISC_R_NOMEMORY); \ + attr->pValue = isc_mem_get(key->mctx, sizeof(pk11_ecc_ed448)); \ + \ memmove(attr->pValue, \ pk11_ecc_ed448, sizeof(pk11_ecc_ed448)); \ attr->ulValueLen = sizeof(pk11_ecc_ed448); \ @@ -479,23 +461,16 @@ pkcs11eddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { UNUSED(unused); UNUSED(callback); - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, false, NULL, pk11_get_best_token(OP_EC)); if (ret != ISC_R_SUCCESS) goto err; - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - DST_RET(ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); key->keydata.pkey = ec; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 3); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 3); memset(ec->repr, 0, sizeof(*attr) * 3); ec->attrcnt = 3; @@ -525,8 +500,6 @@ pkcs11eddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { (pk11_ctx->session, pub, attr, 1), DST_R_CRYPTOFAILURE); attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr->pValue, 0, attr->ulValueLen); PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, pub, attr, 1), @@ -538,8 +511,6 @@ pkcs11eddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) { (pk11_ctx->session, priv, attr, 1), DST_R_CRYPTOFAILURE); attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr->pValue, 0, attr->ulValueLen); PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, priv, attr, 1), @@ -664,30 +635,21 @@ pkcs11eddsa_fromdns(dst_key_t *key, isc_buffer_t *data) { if (r.length != len) return (DST_R_INVALIDPUBLICKEY); - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - return (ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - goto nomemory; + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; attr->type = CKA_EC_PARAMS; if (key->key_alg == DST_ALG_ED25519) { - attr->pValue = - isc_mem_get(key->mctx, sizeof(pk11_ecc_ed25519)); - if (attr->pValue == NULL) - goto nomemory; + attr->pValue = isc_mem_get(key->mctx, + sizeof(pk11_ecc_ed25519)); memmove(attr->pValue, pk11_ecc_ed25519, sizeof(pk11_ecc_ed25519)); attr->ulValueLen = sizeof(pk11_ecc_ed25519); } else { - attr->pValue = - isc_mem_get(key->mctx, sizeof(pk11_ecc_ed448)); - if (attr->pValue == NULL) - goto nomemory; + attr->pValue = isc_mem_get(key->mctx, sizeof(pk11_ecc_ed448)); memmove(attr->pValue, pk11_ecc_ed448, sizeof(pk11_ecc_ed448)); attr->ulValueLen = sizeof(pk11_ecc_ed448); @@ -696,8 +658,6 @@ pkcs11eddsa_fromdns(dst_key_t *key, isc_buffer_t *data) { attr++; attr->type = CKA_EC_POINT; attr->pValue = isc_mem_get(key->mctx, len); - if (attr->pValue == NULL) - goto nomemory; memmove((CK_BYTE_PTR) attr->pValue, r.base, len); attr->ulValueLen = len; @@ -748,8 +708,6 @@ pkcs11eddsa_tofile(const dst_key_t *key, const char *directory) { attr = pk11_attribute_bytype(ec, CKA_VALUE); if (attr != NULL) { buf = isc_mem_get(key->mctx, attr->ulValueLen); - if (buf == NULL) - return (ISC_R_NOMEMORY); priv.elements[i].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[i].length = (unsigned short) attr->ulValueLen; memmove(buf, attr->pValue, attr->ulValueLen); @@ -812,9 +770,7 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, ec->object = CK_INVALID_HANDLE; ec->ontoken = true; ec->reqlogon = true; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - return (ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(ec->repr, 0, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; @@ -822,8 +778,6 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, attr->type = CKA_EC_PARAMS; pubattr = pk11_attribute_bytype(pubec, CKA_EC_PARAMS); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; attr++; @@ -831,8 +785,6 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, attr->type = CKA_EC_POINT; pubattr = pk11_attribute_bytype(pubec, CKA_EC_POINT); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; @@ -840,10 +792,7 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, ec->slot); if (ret != ISC_R_SUCCESS) @@ -941,9 +890,7 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { break; } } - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - DST_RET(ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); key->keydata.pkey = ec; @@ -957,9 +904,7 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { return (ret); } - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 3); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 3); memset(ec->repr, 0, sizeof(*attr) * 3); ec->attrcnt = 3; @@ -968,8 +913,6 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { pattr = pk11_attribute_bytype(pub->keydata.pkey, CKA_EC_PARAMS); INSIST(pattr != NULL); attr->pValue = isc_mem_get(key->mctx, pattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pattr->pValue, pattr->ulValueLen); attr->ulValueLen = pattr->ulValueLen; @@ -978,16 +921,12 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { pattr = pk11_attribute_bytype(pub->keydata.pkey, CKA_EC_POINT); INSIST(pattr != NULL); attr->pValue = isc_mem_get(key->mctx, pattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pattr->pValue, pattr->ulValueLen); attr->ulValueLen = pattr->ulValueLen; attr++; attr->type = CKA_VALUE; attr->pValue = isc_mem_get(key->mctx, priv.elements[0].length); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, priv.elements[0].data, priv.elements[0].length); attr->ulValueLen = priv.elements[0].length; @@ -1031,18 +970,14 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, UNUSED(pin); - ec = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*ec)); - if (ec == NULL) - return (ISC_R_NOMEMORY); + ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); ec->object = CK_INVALID_HANDLE; ec->ontoken = true; ec->reqlogon = true; key->keydata.pkey = ec; - ec->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (ec->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + ec->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(ec->repr, 0, sizeof(*attr) * 2); ec->attrcnt = 2; attr = ec->repr; @@ -1053,10 +988,7 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, ec->slot); if (ret != ISC_R_SUCCESS) @@ -1089,8 +1021,6 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, DST_R_CRYPTOFAILURE); for (i = 0; i <= 1; i++) { attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen); - if (attr[i].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr[i].pValue, 0, attr[i].ulValueLen); } PK11_RET(pkcs_C_GetAttributeValue, diff --git a/lib/dns/pkcs11rsa_link.c b/lib/dns/pkcs11rsa_link.c index 06f3a6c87d..3848c72a83 100644 --- a/lib/dns/pkcs11rsa_link.c +++ b/lib/dns/pkcs11rsa_link.c @@ -113,10 +113,7 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { rsa = key->keydata.pkey; - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); if (rsa->ontoken) slotid = rsa->slot; @@ -141,8 +138,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -151,8 +146,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[7].type == attr->type); keyTemplate[7].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[7].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[7].pValue, attr->pValue, attr->ulValueLen); keyTemplate[7].ulValueLen = attr->ulValueLen; @@ -161,8 +154,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[8].type == attr->type); keyTemplate[8].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[8].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[8].pValue, attr->pValue, attr->ulValueLen); keyTemplate[8].ulValueLen = attr->ulValueLen; @@ -171,8 +162,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[9].type == attr->type); keyTemplate[9].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[9].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[9].pValue, attr->pValue, attr->ulValueLen); keyTemplate[9].ulValueLen = attr->ulValueLen; @@ -180,9 +169,7 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { case CKA_PRIME_2: INSIST(keyTemplate[10].type == attr->type); keyTemplate[10].pValue = isc_mem_get(dctx->mctx, - attr->ulValueLen); - if (keyTemplate[10].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); + attr->ulValueLen); memmove(keyTemplate[10].pValue, attr->pValue, attr->ulValueLen); keyTemplate[10].ulValueLen = attr->ulValueLen; @@ -191,8 +178,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[11].type == attr->type); keyTemplate[11].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[11].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[11].pValue, attr->pValue, attr->ulValueLen); keyTemplate[11].ulValueLen = attr->ulValueLen; @@ -201,8 +186,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[12].type == attr->type); keyTemplate[12].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[12].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[12].pValue, attr->pValue, attr->ulValueLen); keyTemplate[12].ulValueLen = attr->ulValueLen; @@ -211,8 +194,6 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) { INSIST(keyTemplate[13].type == attr->type); keyTemplate[13].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[13].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[13].pValue, attr->pValue, attr->ulValueLen); keyTemplate[13].ulValueLen = attr->ulValueLen; @@ -337,10 +318,7 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, rsa = key->keydata.pkey; - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, pk11_get_best_token(OP_RSA)); @@ -355,8 +333,6 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -365,8 +341,6 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -614,10 +588,7 @@ pkcs11rsa_createctx(dst_key_t *key, dst_context_t *dctx) { ISC_UNREACHABLE(); } - pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); if (rsa->ontoken) slotid = rsa->slot; @@ -789,8 +760,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -799,8 +768,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[7].type == attr->type); keyTemplate[7].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[7].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[7].pValue, attr->pValue, attr->ulValueLen); keyTemplate[7].ulValueLen = attr->ulValueLen; @@ -809,8 +776,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[8].type == attr->type); keyTemplate[8].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[8].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[8].pValue, attr->pValue, attr->ulValueLen); keyTemplate[8].ulValueLen = attr->ulValueLen; @@ -819,8 +784,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[9].type == attr->type); keyTemplate[9].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[9].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[9].pValue, attr->pValue, attr->ulValueLen); keyTemplate[9].ulValueLen = attr->ulValueLen; @@ -828,9 +791,7 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { case CKA_PRIME_2: INSIST(keyTemplate[10].type == attr->type); keyTemplate[10].pValue = isc_mem_get(dctx->mctx, - attr->ulValueLen); - if (keyTemplate[10].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); + attr->ulValueLen); memmove(keyTemplate[10].pValue, attr->pValue, attr->ulValueLen); keyTemplate[10].ulValueLen = attr->ulValueLen; @@ -839,8 +800,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[11].type == attr->type); keyTemplate[11].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[11].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[11].pValue, attr->pValue, attr->ulValueLen); keyTemplate[11].ulValueLen = attr->ulValueLen; @@ -849,8 +808,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[12].type == attr->type); keyTemplate[12].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[12].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[12].pValue, attr->pValue, attr->ulValueLen); keyTemplate[12].ulValueLen = attr->ulValueLen; @@ -859,8 +816,6 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) { INSIST(keyTemplate[13].type == attr->type); keyTemplate[13].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[13].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[13].pValue, attr->pValue, attr->ulValueLen); keyTemplate[13].ulValueLen = attr->ulValueLen; @@ -989,8 +944,6 @@ pkcs11rsa_verify(dst_context_t *dctx, const isc_region_t *sig) { INSIST(keyTemplate[5].type == attr->type); keyTemplate[5].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[5].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[5].pValue, attr->pValue, attr->ulValueLen); keyTemplate[5].ulValueLen = attr->ulValueLen; @@ -999,8 +952,6 @@ pkcs11rsa_verify(dst_context_t *dctx, const isc_region_t *sig) { INSIST(keyTemplate[6].type == attr->type); keyTemplate[6].pValue = isc_mem_get(dctx->mctx, attr->ulValueLen); - if (keyTemplate[6].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(keyTemplate[6].pValue, attr->pValue, attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; @@ -1165,10 +1116,7 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) { ISC_UNREACHABLE(); } - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - return (ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, false, NULL, pk11_get_best_token(OP_RSA)); if (ret != ISC_R_SUCCESS) @@ -1198,14 +1146,10 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) { &pub, &priv), DST_R_CRYPTOFAILURE); - rsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*rsa)); - if (rsa == NULL) - DST_RET(ISC_R_NOMEMORY); + rsa = isc_mem_get(key->mctx, sizeof(*rsa)); memset(rsa, 0, sizeof(*rsa)); key->keydata.pkey = rsa; - rsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 8); - if (rsa->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + rsa->repr = isc_mem_get(key->mctx, sizeof(*attr) * 8); memset(rsa->repr, 0, sizeof(*attr) * 8); rsa->attrcnt = 8; @@ -1224,8 +1168,6 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) { DST_R_CRYPTOFAILURE); for (i = 0; i <= 1; i++) { attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen); - if (attr[i].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr[i].pValue, 0, attr[i].ulValueLen); } PK11_RET(pkcs_C_GetAttributeValue, @@ -1238,8 +1180,6 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) { DST_R_CRYPTOFAILURE); for (i = 0; i <= 5; i++) { attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen); - if (attr[i].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr[i].pValue, 0, attr[i].ulValueLen); } PK11_RET(pkcs_C_GetAttributeValue, @@ -1390,9 +1330,7 @@ pkcs11rsa_fromdns(dst_key_t *key, isc_buffer_t *data) { return (ISC_R_SUCCESS); length = r.length; - rsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*rsa)); - if (rsa == NULL) - return (ISC_R_NOMEMORY); + rsa = isc_mem_get(key->mctx, sizeof(*rsa)); memset(rsa, 0, sizeof(*rsa)); @@ -1425,22 +1363,16 @@ pkcs11rsa_fromdns(dst_key_t *key, isc_buffer_t *data) { isc_buffer_forward(data, length); - rsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (rsa->repr == NULL) - goto nomemory; + rsa->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(rsa->repr, 0, sizeof(*attr) * 2); rsa->attrcnt = 2; attr = rsa->repr; attr[0].type = CKA_MODULUS; attr[0].pValue = isc_mem_get(key->mctx, mod_bytes); - if (attr[0].pValue == NULL) - goto nomemory; memmove(attr[0].pValue, modulus, mod_bytes); attr[0].ulValueLen = (CK_ULONG) mod_bytes; attr[1].type = CKA_PUBLIC_EXPONENT; attr[1].pValue = isc_mem_get(key->mctx, e_bytes); - if (attr[1].pValue == NULL) - goto nomemory; memmove(attr[1].pValue, exponent, e_bytes); attr[1].ulValueLen = (CK_ULONG) e_bytes; @@ -1534,10 +1466,6 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) { for (i = 0; i < 10; i++) { bufs[i] = isc_mem_get(key->mctx, modulus->ulValueLen); - if (bufs[i] == NULL) { - result = ISC_R_NOMEMORY; - goto fail; - } memset(bufs[i], 0, modulus->ulValueLen); } @@ -1662,9 +1590,7 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, rsa->object = CK_INVALID_HANDLE; rsa->ontoken = true; rsa->reqlogon = true; - rsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (rsa->repr == NULL) - return (ISC_R_NOMEMORY); + rsa->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(rsa->repr, 0, sizeof(*attr) * 2); rsa->attrcnt = 2; attr = rsa->repr; @@ -1673,8 +1599,6 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, pubattr = pk11_attribute_bytype(pubrsa, CKA_MODULUS); INSIST(pubattr != NULL); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; attr++; @@ -1683,8 +1607,6 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, pubattr = pk11_attribute_bytype(pubrsa, CKA_PUBLIC_EXPONENT); INSIST(pubattr != NULL); attr->pValue = isc_mem_get(key->mctx, pubattr->ulValueLen); - if (attr->pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(attr->pValue, pubattr->pValue, pubattr->ulValueLen); attr->ulValueLen = pubattr->ulValueLen; @@ -1692,10 +1614,7 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, rsa->slot); if (ret != ISC_R_SUCCESS) @@ -1858,9 +1777,7 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { break; } } - rsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*rsa)); - if (rsa == NULL) - DST_RET(ISC_R_NOMEMORY); + rsa = isc_mem_get(key->mctx, sizeof(*rsa)); memset(rsa, 0, sizeof(*rsa)); key->keydata.pkey = rsa; @@ -1874,9 +1791,7 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { return (ret); } - rsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 8); - if (rsa->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + rsa->repr = isc_mem_get(key->mctx, sizeof(*attr) * 8); memset(rsa->repr, 0, sizeof(*attr) * 8); rsa->attrcnt = 8; attr = rsa->repr; @@ -1899,8 +1814,6 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) { continue; default: bn = isc_mem_get(key->mctx, priv.elements[i].length); - if (bn == NULL) - DST_RET(ISC_R_NOMEMORY); memmove(bn, priv.elements[i].data, priv.elements[i].length); } @@ -2010,18 +1923,14 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, UNUSED(pin); - rsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*rsa)); - if (rsa == NULL) - return (ISC_R_NOMEMORY); + rsa = isc_mem_get(key->mctx, sizeof(*rsa)); memset(rsa, 0, sizeof(*rsa)); rsa->object = CK_INVALID_HANDLE; rsa->ontoken = true; rsa->reqlogon = true; key->keydata.pkey = rsa; - rsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 2); - if (rsa->repr == NULL) - DST_RET(ISC_R_NOMEMORY); + rsa->repr = isc_mem_get(key->mctx, sizeof(*attr) * 2); memset(rsa->repr, 0, sizeof(*attr) * 2); rsa->attrcnt = 2; attr = rsa->repr; @@ -2032,10 +1941,7 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, if (ret != ISC_R_SUCCESS) goto err; - pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx, - sizeof(*pk11_ctx)); - if (pk11_ctx == NULL) - DST_RET(ISC_R_NOMEMORY); + pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, rsa->slot); if (ret != ISC_R_SUCCESS) @@ -2068,8 +1974,6 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, DST_R_CRYPTOFAILURE); for (i = 0; i <= 1; i++) { attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen); - if (attr[i].pValue == NULL) - DST_RET(ISC_R_NOMEMORY); memset(attr[i].pValue, 0, attr[i].ulValueLen); } PK11_RET(pkcs_C_GetAttributeValue, diff --git a/lib/dns/portlist.c b/lib/dns/portlist.c index 314a1628f6..319828c7a8 100644 --- a/lib/dns/portlist.c +++ b/lib/dns/portlist.c @@ -70,8 +70,6 @@ dns_portlist_create(isc_mem_t *mctx, dns_portlist_t **portlistp) { REQUIRE(portlistp != NULL && *portlistp == NULL); portlist = isc_mem_get(mctx, sizeof(*portlist)); - if (portlist == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&portlist->lock); isc_refcount_init(&portlist->refcount, 1); portlist->list = NULL; @@ -142,10 +140,6 @@ dns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) { unsigned int allocated; allocated = portlist->allocated + DNS_PL_ALLOCATE; el = isc_mem_get(portlist->mctx, sizeof(*el) * allocated); - if (el == NULL) { - result = ISC_R_NOMEMORY; - goto unlock; - } if (portlist->list != NULL) { memmove(el, portlist->list, portlist->allocated * sizeof(*el)); diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index 76707dcbd6..e806c01bb5 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -955,9 +955,7 @@ dns_rbt_create(isc_mem_t *mctx, dns_rbtdeleter_t deleter, REQUIRE(rbtp != NULL && *rbtp == NULL); REQUIRE(deleter == NULL ? deleter_arg == NULL : 1); - rbt = (dns_rbt_t *)isc_mem_get(mctx, sizeof(*rbt)); - if (rbt == NULL) - return (ISC_R_NOMEMORY); + rbt = isc_mem_get(mctx, sizeof(*rbt)); rbt->mctx = NULL; isc_mem_attach(mctx, &rbt->mctx); @@ -2188,9 +2186,7 @@ create_node(isc_mem_t *mctx, const dns_name_t *name, dns_rbtnode_t **nodep) { * Allocate space for the node structure, the name, and the offsets. */ nodelen = sizeof(dns_rbtnode_t) + region.length + labels + 1; - node = (dns_rbtnode_t *)isc_mem_get(mctx, nodelen); - if (node == NULL) - return (ISC_R_NOMEMORY); + node = isc_mem_get(mctx, nodelen); memset(node, 0, nodelen); node->is_root = 0; @@ -2278,9 +2274,6 @@ inithash(dns_rbt_t *rbt) { bytes = (unsigned int)rbt->hashsize * sizeof(dns_rbtnode_t *); rbt->hashtable = isc_mem_get(rbt->mctx, bytes); - if (rbt->hashtable == NULL) - return (ISC_R_NOMEMORY); - memset(rbt->hashtable, 0, bytes); return (ISC_R_SUCCESS); @@ -2306,11 +2299,6 @@ rehash(dns_rbt_t *rbt, unsigned int newcount) { } while (newcount >= (rbt->hashsize * 3)); rbt->hashtable = isc_mem_get(rbt->mctx, rbt->hashsize * sizeof(dns_rbtnode_t *)); - if (rbt->hashtable == NULL) { - rbt->hashtable = oldtable; - rbt->hashsize = oldsize; - return; - } for (i = 0; i < rbt->hashsize; i++) rbt->hashtable[i] = NULL; diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 0e5c9d8dbe..b32d380a01 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -1224,8 +1224,6 @@ allocate_version(isc_mem_t *mctx, rbtdb_serial_t serial, size_t i; version = isc_mem_get(mctx, sizeof(*version)); - if (version == NULL) - return (NULL); version->serial = serial; isc_refcount_init(&version->references, references); @@ -1239,15 +1237,8 @@ allocate_version(isc_mem_t *mctx, rbtdb_serial_t serial, version->glue_table_size = RBTDB_GLUE_TABLE_INIT_SIZE; version->glue_table_nodecount = 0U; - version->glue_table = (rbtdb_glue_table_node_t **) - isc_mem_get(mctx, (version->glue_table_size * - sizeof(*version->glue_table))); - if (version->glue_table == NULL) { - isc_rwlock_destroy(&version->glue_rwlock); - isc_refcount_destroy(&version->references); - isc_mem_put(mctx, version, sizeof(*version)); - return (NULL); - } + version->glue_table = isc_mem_get(mctx, + (version->glue_table_size * sizeof(*version->glue_table))); version->writer = writer; version->commit_ok = false; @@ -1434,8 +1425,6 @@ new_rdataset(dns_rbtdb_t *rbtdb, isc_mem_t *mctx) { rdatasetheader_t *h; h = isc_mem_get(mctx, sizeof(*h)); - if (h == NULL) - return (NULL); #if TRACE_HEADER if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) @@ -5389,8 +5378,6 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) REQUIRE(VALID_RBTDB(rbtdb)); rbtdbiter = isc_mem_get(rbtdb->common.mctx, sizeof(*rbtdbiter)); - if (rbtdbiter == NULL) - return (ISC_R_NOMEMORY); rbtdbiter->common.methods = &dbiterator_methods; rbtdbiter->common.db = NULL; @@ -5615,8 +5602,6 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(VALID_RBTDB(rbtdb)); iterator = isc_mem_get(rbtdb->common.mctx, sizeof(*iterator)); - if (iterator == NULL) - return (ISC_R_NOMEMORY); if ((db->attributes & DNS_DBATTR_CACHE) == 0) { now = 0; @@ -6343,10 +6328,6 @@ addnoqname(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader, RUNTIME_CHECK(result == ISC_R_SUCCESS); noqname = isc_mem_get(mctx, sizeof(*noqname)); - if (noqname == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_name_init(&noqname->name, NULL); noqname->neg = NULL; noqname->negsig = NULL; @@ -6394,10 +6375,6 @@ addclosest(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader, RUNTIME_CHECK(result == ISC_R_SUCCESS); closest = isc_mem_get(mctx, sizeof(*closest)); - if (closest == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_name_init(&closest->name, NULL); closest->neg = NULL; closest->negsig = NULL; @@ -7270,8 +7247,6 @@ beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { REQUIRE(VALID_RBTDB(rbtdb)); loadctx = isc_mem_get(rbtdb->common.mctx, sizeof(*loadctx)); - if (loadctx == NULL) - return (ISC_R_NOMEMORY); loadctx->rbtdb = rbtdb; if (IS_CACHE(rbtdb)) @@ -8087,8 +8062,6 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, UNUSED(driverarg); rbtdb = isc_mem_get(mctx, sizeof(*rbtdb)); - if (rbtdb == NULL) - return (ISC_R_NOMEMORY); /* * If argv[0] exists, it points to a memory context to use for heap @@ -8136,12 +8109,8 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, goto cleanup_tree_lock; } INSIST(rbtdb->node_lock_count < (1 << DNS_RBT_LOCKLENGTH)); - rbtdb->node_locks = isc_mem_get(mctx, rbtdb->node_lock_count * - sizeof(rbtdb_nodelock_t)); - if (rbtdb->node_locks == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_tree_lock; - } + rbtdb->node_locks = isc_mem_get(mctx, + rbtdb->node_lock_count * sizeof(rbtdb_nodelock_t)); rbtdb->cachestats = NULL; rbtdb->gluecachestats = NULL; @@ -8151,12 +8120,8 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, result = dns_rdatasetstats_create(mctx, &rbtdb->rrsetstats); if (result != ISC_R_SUCCESS) goto cleanup_node_locks; - rbtdb->rdatasets = isc_mem_get(mctx, rbtdb->node_lock_count * - sizeof(rdatasetheaderlist_t)); - if (rbtdb->rdatasets == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_rrsetstats; - } + rbtdb->rdatasets = isc_mem_get(mctx, + rbtdb->node_lock_count * sizeof(rdatasetheaderlist_t)); for (i = 0; i < (int)rbtdb->node_lock_count; i++) ISC_LIST_INIT(rbtdb->rdatasets[i]); } else @@ -8165,12 +8130,8 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, /* * Create the heaps. */ - rbtdb->heaps = isc_mem_get(hmctx, rbtdb->node_lock_count * - sizeof(isc_heap_t *)); - if (rbtdb->heaps == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_rdatasets; - } + rbtdb->heaps = isc_mem_get(hmctx, + rbtdb->node_lock_count * sizeof(isc_heap_t *)); for (i = 0; i < (int)rbtdb->node_lock_count; i++) rbtdb->heaps[i] = NULL; sooner = IS_CACHE(rbtdb) ? ttl_sooner : resign_sooner; @@ -8184,12 +8145,8 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, /* * Create deadnode lists. */ - rbtdb->deadnodes = isc_mem_get(mctx, rbtdb->node_lock_count * - sizeof(rbtnodelist_t)); - if (rbtdb->deadnodes == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_heaps; - } + rbtdb->deadnodes = isc_mem_get(mctx, + rbtdb->node_lock_count * sizeof(rbtnodelist_t)); for (i = 0; i < (int)rbtdb->node_lock_count; i++) ISC_LIST_INIT(rbtdb->deadnodes[i]); @@ -8376,11 +8333,9 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, rbtdb->node_lock_count * sizeof(isc_heap_t *)); } - cleanup_rdatasets: if (rbtdb->rdatasets != NULL) isc_mem_put(mctx, rbtdb->rdatasets, rbtdb->node_lock_count * sizeof(rdatasetheaderlist_t)); - cleanup_rrsetstats: if (rbtdb->rrsetstats != NULL) dns_stats_detach(&rbtdb->rrsetstats); @@ -9633,10 +9588,8 @@ rehash_gluetable(rbtdb_version_t *version) { } while (version->glue_table_nodecount >= (version->glue_table_size * 3U)); - version->glue_table = (rbtdb_glue_table_node_t **) - isc_mem_get(version->rbtdb->common.mctx, - (version->glue_table_size * - sizeof(*version->glue_table))); + version->glue_table = isc_mem_get(version->rbtdb->common.mctx, + (version->glue_table_size * sizeof(*version->glue_table))); if (ISC_UNLIKELY(version->glue_table == NULL)) { version->glue_table = oldtable; version->glue_table_size = oldsize; @@ -9711,10 +9664,6 @@ glue_nsdname_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype) { &rdataset_a, &sigrdataset_a); if (result == DNS_R_GLUE) { glue = isc_mem_get(ctx->rbtdb->common.mctx, sizeof(*glue)); - if (glue == NULL) { - result = ISC_R_NOMEMORY; - goto out; - } gluename = dns_fixedname_initname(&glue->fixedname); dns_name_copy(name_a, gluename, NULL); @@ -9739,10 +9688,6 @@ glue_nsdname_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype) { if (glue == NULL) { glue = isc_mem_get(ctx->rbtdb->common.mctx, sizeof(*glue)); - if (glue == NULL) { - result = ISC_R_NOMEMORY; - goto out; - } gluename = dns_fixedname_initname(&glue->fixedname); dns_name_copy(name_aaaa, gluename, NULL); @@ -9770,7 +9715,6 @@ glue_nsdname_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype) { result = ISC_R_SUCCESS; -out: if (dns_rdataset_isassociated(&rdataset_a)) rdataset_disassociate(&rdataset_a); if (dns_rdataset_isassociated(&sigrdataset_a)) @@ -10004,10 +9948,6 @@ no_glue: (void)dns_rdataset_additionaldata(rdataset, glue_nsdname_cb, &ctx); cur = isc_mem_get(rbtdb->common.mctx, sizeof(*cur)); - if (cur == NULL) { - result = ISC_R_NOMEMORY; - goto out; - } /* * XXXMUKS: it looks like the dns_dbversion is not destroyed @@ -10040,17 +9980,12 @@ no_glue: rbtversion->glue_table[idx] = cur; rbtversion->glue_table_nodecount++; - result = ISC_R_SUCCESS; - - out: RWUNLOCK(&rbtversion->glue_rwlock, isc_rwlocktype_write); - if (result == ISC_R_SUCCESS) { - restarted = true; - goto restart; - } + restarted = true; + goto restart; - return (result); + /* UNREACHABLE */ } /*% diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c index ed217261a7..b9894806b9 100644 --- a/lib/dns/rdataslab.c +++ b/lib/dns/rdataslab.c @@ -148,8 +148,6 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, if (rdataset->type != 0) return (ISC_R_FAILURE); rawbuf = isc_mem_get(mctx, buflen); - if (rawbuf == NULL) - return (ISC_R_NOMEMORY); region->base = rawbuf; region->length = buflen; rawbuf += reservelen; @@ -166,8 +164,6 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, */ nalloc = nitems; x = isc_mem_get(mctx, nalloc * sizeof(struct xrdata)); - if (x == NULL) - return (ISC_R_NOMEMORY); /* * Save all of the rdata members into an array. @@ -268,19 +264,10 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, * data. */ rawbuf = isc_mem_get(mctx, buflen); - if (rawbuf == NULL) { - result = ISC_R_NOMEMORY; - goto free_rdatas; - } #if DNS_RDATASET_FIXED /* Allocate temporary offset table. */ offsettable = isc_mem_get(mctx, nalloc * sizeof(unsigned int)); - if (offsettable == NULL) { - isc_mem_put(mctx, rawbuf, buflen); - result = ISC_R_NOMEMORY; - goto free_rdatas; - } memset(offsettable, 0, nalloc * sizeof(unsigned int)); #endif @@ -580,8 +567,6 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, * Copy the reserved area from the new slab. */ tstart = isc_mem_get(mctx, tlength); - if (tstart == NULL) - return (ISC_R_NOMEMORY); memmove(tstart, nslab, reservelen); tcurrent = tstart + reservelen; #if DNS_RDATASET_FIXED @@ -602,10 +587,6 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, offsettable = isc_mem_get(mctx, (ocount + oncount) * sizeof(unsigned int)); - if (offsettable == NULL) { - isc_mem_put(mctx, tstart, tlength); - return (ISC_R_NOMEMORY); - } memset(offsettable, 0, (ocount + oncount) * sizeof(unsigned int)); #endif @@ -819,18 +800,12 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, * Copy the reserved area from the mslab. */ tstart = isc_mem_get(mctx, tlength); - if (tstart == NULL) - return (ISC_R_NOMEMORY); memmove(tstart, mslab, reservelen); tcurrent = tstart + reservelen; #if DNS_RDATASET_FIXED offsetbase = tcurrent; offsettable = isc_mem_get(mctx, mcount * sizeof(unsigned int)); - if (offsettable == NULL) { - isc_mem_put(mctx, tstart, tlength); - return (ISC_R_NOMEMORY); - } memset(offsettable, 0, mcount * sizeof(unsigned int)); #endif diff --git a/lib/dns/request.c b/lib/dns/request.c index 5467379ec8..729bd248a7 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -160,8 +160,6 @@ dns_requestmgr_create(isc_mem_t *mctx, } requestmgr = isc_mem_get(mctx, sizeof(*requestmgr)); - if (requestmgr == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&requestmgr->lock); @@ -451,8 +449,6 @@ new_request(isc_mem_t *mctx, dns_request_t **requestp) dns_request_t *request; request = isc_mem_get(mctx, sizeof(*request)); - if (request == NULL) - return (ISC_R_NOMEMORY); /* * Zero structure. diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 939df18ea3..3beaccf663 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -856,8 +856,6 @@ valcreate(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, dns_name_t *name, isc_result_t result; valarg = isc_mem_get(fctx->mctx, sizeof(*valarg)); - if (valarg == NULL) - return (ISC_R_NOMEMORY); valarg->fctx = fctx; valarg->addrinfo = addrinfo; @@ -1514,16 +1512,13 @@ fcount_incr(fetchctx_t *fctx, bool force) { if (counter == NULL) { counter = isc_mem_get(dbucket->mctx, sizeof(fctxcount_t)); - if (counter == NULL) - result = ISC_R_NOMEMORY; - else { + { ISC_LINK_INIT(counter, link); counter->count = 1; counter->logged = 0; counter->allowed = 1; counter->dropped = 0; - counter->domain = - dns_fixedname_initname(&counter->fdname); + counter->domain = dns_fixedname_initname(&counter->fdname); dns_name_copy(&fctx->domain, counter->domain, NULL); ISC_LIST_APPEND(dbucket->list, counter, link); } @@ -1950,10 +1945,6 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, dns_message_reset(fctx->rmessage, DNS_MESSAGE_INTENTPARSE); query = isc_mem_get(fctx->mctx, sizeof(*query)); - if (query == NULL) { - result = ISC_R_NOMEMORY; - goto stop_idle_timer; - } query->mctx = fctx->mctx; query->options = options; query->attributes = 0; @@ -2165,7 +2156,6 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_mem_put(fctx->mctx, query, sizeof(*query)); } - stop_idle_timer: RUNTIME_CHECK(fctx_stopidletimer(fctx) == ISC_R_SUCCESS); return (result); @@ -2197,8 +2187,6 @@ add_bad_edns(fetchctx_t *fctx, isc_sockaddr_t *address) { return; sa = isc_mem_get(fctx->mctx, sizeof(*sa)); - if (sa == NULL) - return; *sa = *address; ISC_LIST_INITANDAPPEND(fctx->bad_edns, sa, link); @@ -2229,8 +2217,6 @@ add_triededns(fetchctx_t *fctx, isc_sockaddr_t *address) { } tried = isc_mem_get(fctx->mctx, sizeof(*tried)); - if (tried == NULL) - return; tried->addr = *address; tried->count = 1; @@ -2262,8 +2248,6 @@ add_triededns512(fetchctx_t *fctx, isc_sockaddr_t *address) { } tried = isc_mem_get(fctx->mctx, sizeof(*tried)); - if (tried == NULL) - return; tried->addr = *address; tried->count = 1; @@ -3218,8 +3202,6 @@ add_bad(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_result_t reason, FCTXTRACE("add_bad"); sa = isc_mem_get(fctx->mctx, sizeof(*sa)); - if (sa == NULL) - return; *sa = *address; ISC_LIST_INITANDAPPEND(fctx->bad, sa, link); @@ -4713,8 +4695,6 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type, mctx = res->buckets[bucketnum].mctx; fctx = isc_mem_get(mctx, sizeof(*fctx)); - if (fctx == NULL) - return (ISC_R_NOMEMORY); fctx->qc = NULL; if (qc != NULL) { @@ -7251,11 +7231,7 @@ log_nsid(isc_buffer_t *opt, size_t nsid_len, resquery_t *query, /* Allocate buffer for storing hex version of the NSID */ buflen = (uint16_t)nsid_len * 2 + 1; buf = isc_mem_get(mctx, buflen); - if (buf == NULL) - goto cleanup; pbuf = isc_mem_get(mctx, nsid_len + 1); - if (pbuf == NULL) - goto cleanup; /* Convert to hex */ p = buf; @@ -7281,7 +7257,7 @@ log_nsid(isc_buffer_t *opt, size_t nsid_len, resquery_t *query, isc_log_write(dns_lctx, DNS_LOGCATEGORY_NSID, DNS_LOGMODULE_RESOLVER, level, "received NSID %s (\"%s\") from %s", buf, pbuf, addrbuf); - cleanup: + if (pbuf != NULL) isc_mem_put(mctx, pbuf, nsid_len + 1); if (buf != NULL) @@ -9948,8 +9924,6 @@ dns_resolver_create(dns_view_t *view, REQUIRE(dispatchv4 != NULL || dispatchv6 != NULL); res = isc_mem_get(view->mctx, sizeof(*res)); - if (res == NULL) - return (ISC_R_NOMEMORY); RTRACE("create"); res->mctx = view->mctx; res->rdclass = view->rdclass; @@ -9988,12 +9962,7 @@ dns_resolver_create(dns_view_t *view, isc_stats_set(view->resstats, ntasks, dns_resstatscounter_buckets); res->activebuckets = ntasks; - res->buckets = isc_mem_get(view->mctx, - ntasks * sizeof(fctxbucket_t)); - if (res->buckets == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_badcache; - } + res->buckets = isc_mem_get(view->mctx, ntasks * sizeof(fctxbucket_t)); for (i = 0; i < ntasks; i++) { isc_mutex_init(&res->buckets[i].lock); @@ -10030,10 +9999,6 @@ dns_resolver_create(dns_view_t *view, res->dbuckets = isc_mem_get(view->mctx, RES_DOMAIN_BUCKETS * sizeof(zonebucket_t)); - if (res->dbuckets == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_buckets; - } for (i = 0; i < RES_DOMAIN_BUCKETS; i++) { ISC_LIST_INIT(res->dbuckets[i].list); res->dbuckets[i].mctx = NULL; @@ -10142,7 +10107,6 @@ dns_resolver_create(dns_view_t *view, isc_mem_put(view->mctx, res->buckets, res->nbuckets * sizeof(fctxbucket_t)); - cleanup_badcache: dns_badcache_destroy(&res->badcache); cleanup_res: @@ -10235,14 +10199,6 @@ dns_resolver_prime(dns_resolver_t *res) { */ RTRACE("priming"); rdataset = isc_mem_get(res->mctx, sizeof(*rdataset)); - if (rdataset == NULL) { - LOCK(&res->lock); - INSIST(res->priming); - INSIST(res->primefetch == NULL); - res->priming = false; - UNLOCK(&res->lock); - return; - } dns_rdataset_init(rdataset); LOCK(&res->primelock); result = dns_resolver_createfetch(res, dns_rootname, @@ -10561,8 +10517,6 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, * XXXRTH use a mempool? */ fetch = isc_mem_get(res->mctx, sizeof(*fetch)); - if (fetch == NULL) - return (ISC_R_NOMEMORY); fetch->mctx = NULL; isc_mem_attach(res->mctx, &fetch->mctx); @@ -10853,8 +10807,6 @@ dns_resolver_addalternate(dns_resolver_t *resolver, const isc_sockaddr_t *alt, REQUIRE((alt == NULL) ^ (name == NULL)); a = isc_mem_get(resolver->mctx, sizeof(*a)); - if (a == NULL) - return (ISC_R_NOMEMORY); if (alt != NULL) { a->isaddress = true; a->_u.addr = *alt; @@ -10997,10 +10949,6 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, * into it if one exists. */ tmp = isc_mem_get(resolver->mctx, len); - if (tmp == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } memset(tmp, 0, len); if (algorithms != NULL) memmove(tmp, algorithms, *algorithms); @@ -11133,10 +11081,6 @@ dns_resolver_disable_ds_digest(dns_resolver_t *resolver, * into it if one exists. */ tmp = isc_mem_get(resolver->mctx, len); - if (tmp == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } memset(tmp, 0, len); if (digests != NULL) memmove(tmp, digests, *digests); diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index dc319dde44..d47a8bd0fd 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -637,8 +637,6 @@ new_node(dns_rpz_zones_t *rpzs, int i, words, wlen; node = isc_mem_get(rpzs->mctx, sizeof(*node)); - if (node == NULL) - return (NULL); memset(node, 0, sizeof(*node)); if (child != NULL) @@ -1361,8 +1359,6 @@ add_nm(dns_rpz_zones_t *rpzs, dns_name_t *trig_name, nm_data = nmnode->data; if (nm_data == NULL) { nm_data = isc_mem_get(rpzs->mctx, sizeof(*nm_data)); - if (nm_data == NULL) - return (ISC_R_NOMEMORY); *nm_data = *new_data; nmnode->data = nm_data; return (ISC_R_SUCCESS); @@ -1440,8 +1436,6 @@ dns_rpz_new_zones(dns_rpz_zones_t **rpzsp, char *rps_cstr, REQUIRE(rpzsp != NULL && *rpzsp == NULL); zones = isc_mem_get(mctx, sizeof(*zones)); - if (zones == NULL) - return (ISC_R_NOMEMORY); memset(zones, 0, sizeof(*zones)); result = isc_rwlock_init(&zones->search_lock, 0, 0); @@ -1508,9 +1502,6 @@ dns_rpz_new_zone(dns_rpz_zones_t *rpzs, dns_rpz_zone_t **rpzp) { } zone = isc_mem_get(rpzs->mctx, sizeof(*zone)); - if (zone == NULL) { - return (ISC_R_NOMEMORY); - } memset(zone, 0, sizeof(*zone)); isc_refcount_init(&zone->refs, 1); diff --git a/lib/dns/rrl.c b/lib/dns/rrl.c index cae027060b..b1b5ac037a 100644 --- a/lib/dns/rrl.c +++ b/lib/dns/rrl.c @@ -228,13 +228,6 @@ expand_entries(dns_rrl_t *rrl, int newsize) { bsize = sizeof(dns_rrl_block_t) + (newsize-1)*sizeof(dns_rrl_entry_t); b = isc_mem_get(rrl->mctx, bsize); - if (b == NULL) { - isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, - DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_FAIL, - "isc_mem_get(%d) failed for RRL entries", - bsize); - return (ISC_R_NOMEMORY); - } memset(b, 0, bsize); b->size = bsize; @@ -299,14 +292,6 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) { hsize = sizeof(dns_rrl_hash_t) + (new_bins-1)*sizeof(hash->bins[0]); hash = isc_mem_get(rrl->mctx, hsize); - if (hash == NULL) { - isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, - DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_FAIL, - "isc_mem_get(%d) failed for" - " RRL hash table", - hsize); - return (ISC_R_NOMEMORY); - } memset(hash, 0, hsize); hash->length = new_bins; rrl->hash_gen ^= 1; @@ -889,19 +874,11 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, ISC_LIST_UNLINK(rrl->qname_free, qbuf, link); } else if (rrl->num_qnames < DNS_RRL_QNAMES) { qbuf = isc_mem_get(rrl->mctx, sizeof(*qbuf)); - if (qbuf != NULL) { + { memset(qbuf, 0, sizeof(*qbuf)); ISC_LINK_INIT(qbuf, link); qbuf->index = rrl->num_qnames; rrl->qnames[rrl->num_qnames++] = qbuf; - } else { - isc_log_write(dns_lctx, - DNS_LOGCATEGORY_RRL, - DNS_LOGMODULE_REQUEST, - DNS_RRL_LOG_FAIL, - "isc_mem_get(%d)" - " failed for RRL qname", - (int)sizeof(*qbuf)); } } if (qbuf != NULL) { @@ -1290,8 +1267,6 @@ dns_rrl_init(dns_rrl_t **rrlp, dns_view_t *view, int min_entries) { *rrlp = NULL; rrl = isc_mem_get(view->mctx, sizeof(*rrl)); - if (rrl == NULL) - return (ISC_R_NOMEMORY); memset(rrl, 0, sizeof(*rrl)); isc_mem_attach(view->mctx, &rrl->mctx); isc_mutex_init(&rrl->lock); diff --git a/lib/dns/sdb.c b/lib/dns/sdb.c index 4325819e98..d233c6f69a 100644 --- a/lib/dns/sdb.c +++ b/lib/dns/sdb.c @@ -218,8 +218,6 @@ dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods, DNS_SDBFLAG_DNS64)) == 0); imp = isc_mem_get(mctx, sizeof(dns_sdbimplementation_t)); - if (imp == NULL) - return (ISC_R_NOMEMORY); imp->methods = methods; imp->driverdata = driverdata; imp->flags = flags; @@ -293,8 +291,6 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval, if (rdatalist == NULL) { rdatalist = isc_mem_get(mctx, sizeof(dns_rdatalist_t)); - if (rdatalist == NULL) - return (ISC_R_NOMEMORY); dns_rdatalist_init(rdatalist); rdatalist->rdclass = lookup->sdb->common.rdclass; rdatalist->type = typeval; @@ -305,8 +301,6 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval, return (DNS_R_BADTTL); rdata = isc_mem_get(mctx, sizeof(dns_rdata_t)); - if (rdata == NULL) - return (ISC_R_NOMEMORY); result = isc_buffer_allocate(mctx, &rdatabuf, rdlen); if (result != ISC_R_SUCCESS) @@ -379,10 +373,6 @@ dns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl, if (size >= 65535) size = 65535; p = isc_mem_get(mctx, size); - if (p == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } isc_buffer_init(&rb, p, size); result = dns_rdata_fromtext(NULL, lookup->sdb->common.rdclass, @@ -456,10 +446,6 @@ getnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) { if (result != ISC_R_SUCCESS) return (result); sdbnode->name = isc_mem_get(mctx, sizeof(dns_name_t)); - if (sdbnode->name == NULL) { - destroynode(sdbnode); - return (ISC_R_NOMEMORY); - } dns_name_init(sdbnode->name, NULL); result = dns_name_dup(newname, mctx, sdbnode->name); if (result != ISC_R_SUCCESS) { @@ -643,8 +629,6 @@ createnode(dns_sdb_t *sdb, dns_sdbnode_t **nodep) { dns_sdbnode_t *node; node = isc_mem_get(sdb->common.mctx, sizeof(dns_sdbnode_t)); - if (node == NULL) - return (ISC_R_NOMEMORY); node->sdb = NULL; attach((dns_db_t *)sdb, (dns_db_t **)&node->sdb); @@ -1052,8 +1036,6 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) return (ISC_R_NOTIMPLEMENTED); sdbiter = isc_mem_get(sdb->common.mctx, sizeof(sdb_dbiterator_t)); - if (sdbiter == NULL) - return (ISC_R_NOMEMORY); sdbiter->common.methods = &dbiterator_methods; sdbiter->common.db = NULL; @@ -1128,8 +1110,6 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, UNUSED(now); iterator = isc_mem_get(db->mctx, sizeof(sdb_rdatasetiter_t)); - if (iterator == NULL) - return (ISC_R_NOMEMORY); iterator->common.magic = DNS_RDATASETITER_MAGIC; iterator->common.methods = &rdatasetiter_methods; @@ -1291,8 +1271,6 @@ dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, return (ISC_R_NOTIMPLEMENTED); sdb = isc_mem_get(mctx, sizeof(dns_sdb_t)); - if (sdb == NULL) - return (ISC_R_NOMEMORY); memset(sdb, 0, sizeof(dns_sdb_t)); dns_name_init(&sdb->common.origin, NULL); diff --git a/lib/dns/sdlz.c b/lib/dns/sdlz.c index b0658b39df..8586426148 100644 --- a/lib/dns/sdlz.c +++ b/lib/dns/sdlz.c @@ -455,8 +455,6 @@ createnode(dns_sdlz_db_t *sdlz, dns_sdlznode_t **nodep) { dns_sdlznode_t *node; node = isc_mem_get(sdlz->common.mctx, sizeof(dns_sdlznode_t)); - if (node == NULL) - return (ISC_R_NOMEMORY); node->sdlz = NULL; attach((dns_db_t *)sdlz, (dns_db_t **)&node->sdlz); @@ -781,8 +779,6 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) isc_buffer_putuint8(&b, 0); sdlziter = isc_mem_get(sdlz->common.mctx, sizeof(sdlz_dbiterator_t)); - if (sdlziter == NULL) - return (ISC_R_NOMEMORY); sdlziter->common.methods = &dbiterator_methods; sdlziter->common.db = NULL; @@ -1050,8 +1046,6 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, UNUSED(now); iterator = isc_mem_get(db->mctx, sizeof(sdlz_rdatasetiter_t)); - if (iterator == NULL) - return (ISC_R_NOMEMORY); iterator->common.magic = DNS_RDATASETITER_MAGIC; iterator->common.methods = &rdatasetiter_methods; @@ -1506,8 +1500,6 @@ dns_sdlzcreateDBP(isc_mem_t *mctx, void *driverarg, void *dbdata, /* allocate and zero memory for driver structure */ sdlzdb = isc_mem_get(mctx, sizeof(dns_sdlz_db_t)); - if (sdlzdb == NULL) - return (ISC_R_NOMEMORY); memset(sdlzdb, 0, sizeof(dns_sdlz_db_t)); /* initialize and set origin */ @@ -1845,8 +1837,6 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, if (rdatalist == NULL) { rdatalist = isc_mem_get(mctx, sizeof(dns_rdatalist_t)); - if (rdatalist == NULL) - return (ISC_R_NOMEMORY); dns_rdatalist_init(rdatalist); rdatalist->rdclass = lookup->sdlz->common.rdclass; rdatalist->type = typeval; @@ -1865,8 +1855,6 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, } rdata = isc_mem_get(mctx, sizeof(dns_rdata_t)); - if (rdata == NULL) - return (ISC_R_NOMEMORY); dns_rdata_init(rdata); if ((lookup->sdlz->dlzimp->flags & DNS_SDLZFLAG_RELATIVERDATA) != 0) @@ -2030,8 +2018,6 @@ dns_sdlzregister(const char *drivername, const dns_sdlzmethods_t *methods, * we cannot. */ imp = isc_mem_get(mctx, sizeof(dns_sdlzimplementation_t)); - if (imp == NULL) - return (ISC_R_NOMEMORY); /* Make sure memory region is set to all 0's */ memset(imp, 0, sizeof(dns_sdlzimplementation_t)); diff --git a/lib/dns/ssu.c b/lib/dns/ssu.c index 0e93a657dc..4cfcd5deb9 100644 --- a/lib/dns/ssu.c +++ b/lib/dns/ssu.c @@ -148,8 +148,6 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant, mctx = table->mctx; rule = isc_mem_get(mctx, sizeof(dns_ssurule_t)); - if (rule == NULL) - return (ISC_R_NOMEMORY); rule->identity = NULL; rule->name = NULL; @@ -158,20 +156,12 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant, rule->grant = grant; rule->identity = isc_mem_get(mctx, sizeof(dns_name_t)); - if (rule->identity == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } dns_name_init(rule->identity, NULL); result = dns_name_dup(identity, mctx, rule->identity); if (result != ISC_R_SUCCESS) goto failure; rule->name = isc_mem_get(mctx, sizeof(dns_name_t)); - if (rule->name == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } dns_name_init(rule->name, NULL); result = dns_name_dup(name, mctx, rule->name); if (result != ISC_R_SUCCESS) @@ -183,10 +173,6 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant, if (ntypes > 0) { rule->types = isc_mem_get(mctx, ntypes * sizeof(dns_rdatatype_t)); - if (rule->types == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } memmove(rule->types, types, ntypes * sizeof(dns_rdatatype_t)); } else rule->types = NULL; @@ -619,10 +605,6 @@ dns_ssutable_createdlz(isc_mem_t *mctx, dns_ssutable_t **tablep, table->dlzdatabase = dlzdatabase; rule = isc_mem_get(table->mctx, sizeof(dns_ssurule_t)); - if (rule == NULL) { - dns_ssutable_detach(&table); - return (ISC_R_NOMEMORY); - } rule->identity = NULL; rule->name = NULL; diff --git a/lib/dns/stats.c b/lib/dns/stats.c index f57e6552b7..9909b1e848 100644 --- a/lib/dns/stats.c +++ b/lib/dns/stats.c @@ -127,8 +127,6 @@ create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters, isc_result_t result; stats = isc_mem_get(mctx, sizeof(*stats)); - if (stats == NULL) - return (ISC_R_NOMEMORY); stats->counters = NULL; isc_refcount_init(&stats->references, 1); diff --git a/lib/dns/tests/tsig_test.c b/lib/dns/tests/tsig_test.c index 6b9519d2f5..0092a9be51 100644 --- a/lib/dns/tests/tsig_test.c +++ b/lib/dns/tests/tsig_test.c @@ -135,10 +135,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) { CHECK(dst_context_adddata(tsigctx, &r)); CHECK(dst_key_sigsize(key->key, &sigsize)); - tsig.signature = (unsigned char *) isc_mem_get(dt_mctx, sigsize); - if (tsig.signature == NULL) { - CHECK(ISC_R_NOMEMORY); - } + tsig.signature = isc_mem_get(dt_mctx, sigsize); isc_buffer_init(&sigbuf, tsig.signature, sigsize); CHECK(dst_context_sign(tsigctx, &sigbuf)); tsig.siglen = isc_buffer_usedlength(&sigbuf); diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index 3026e6aab8..02f57fd0e8 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -79,8 +79,6 @@ dumpmessage(dns_message_t *msg) { for (;;) { output = isc_mem_get(msg->mctx, len); - if (output == NULL) - return; isc_buffer_init(&outbuf, output, len); result = dns_message_totext(msg, &dns_master_style_debug, @@ -114,8 +112,6 @@ dns_tkeyctx_create(isc_mem_t *mctx, dns_tkeyctx_t **tctxp) REQUIRE(tctxp != NULL && *tctxp == NULL); tctx = isc_mem_get(mctx, sizeof(dns_tkeyctx_t)); - if (tctx == NULL) - return (ISC_R_NOMEMORY); tctx->mctx = NULL; isc_mem_attach(mctx, &tctx->mctx); tctx->dhkey = NULL; @@ -456,8 +452,6 @@ process_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name, isc_buffer_init(&secret, secretdata, sizeof(secretdata)); randomdata = isc_mem_get(tkeyout->mctx, TKEY_RANDOM_AMOUNT); - if (randomdata == NULL) - goto failure; isc_nonce_buf(randomdata, TKEY_RANDOM_AMOUNT); @@ -601,20 +595,12 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, if (outtoken) { tkeyout->key = isc_mem_get(tkeyout->mctx, isc_buffer_usedlength(outtoken)); - if (tkeyout->key == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } tkeyout->keylen = isc_buffer_usedlength(outtoken); memmove(tkeyout->key, isc_buffer_base(outtoken), isc_buffer_usedlength(outtoken)); isc_buffer_free(&outtoken); } else { tkeyout->key = isc_mem_get(tkeyout->mctx, tkeyin->keylen); - if (tkeyout->key == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } tkeyout->keylen = tkeyin->keylen; memmove(tkeyout->key, tkeyin->key, tkeyin->keylen); } diff --git a/lib/dns/tsec.c b/lib/dns/tsec.c index 8545431e79..2b59ac33e7 100644 --- a/lib/dns/tsec.c +++ b/lib/dns/tsec.c @@ -50,8 +50,6 @@ dns_tsec_create(isc_mem_t *mctx, dns_tsectype_t type, dst_key_t *key, REQUIRE(tsecp != NULL && *tsecp == NULL); tsec = isc_mem_get(mctx, sizeof(*tsec)); - if (tsec == NULL) - return (ISC_R_NOMEMORY); tsec->type = type; tsec->mctx = mctx; diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 8e41bd963a..9c7fcb4b03 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -263,9 +263,7 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, REQUIRE(mctx != NULL); REQUIRE(key != NULL || ring != NULL); - tkey = (dns_tsigkey_t *) isc_mem_get(mctx, sizeof(dns_tsigkey_t)); - if (tkey == NULL) - return (ISC_R_NOMEMORY); + tkey = isc_mem_get(mctx, sizeof(dns_tsigkey_t)); dns_name_init(&tkey->name, NULL); ret = dns_name_dup(name, mctx, &tkey->name); @@ -292,10 +290,6 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, goto cleanup_name; } tmpname = isc_mem_get(mctx, sizeof(dns_name_t)); - if (tmpname == NULL) { - ret = ISC_R_NOMEMORY; - goto cleanup_name; - } dns_name_init(tmpname, NULL); ret = dns_name_dup(algorithm, mctx, tmpname); if (ret != ISC_R_SUCCESS) { @@ -308,10 +302,6 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, if (creator != NULL) { tkey->creator = isc_mem_get(mctx, sizeof(dns_name_t)); - if (tkey->creator == NULL) { - ret = ISC_R_NOMEMORY; - goto cleanup_algorithm; - } dns_name_init(tkey->creator, NULL); ret = dns_name_dup(creator, mctx, tkey->creator); if (ret != ISC_R_SUCCESS) { @@ -955,11 +945,7 @@ dns_tsig_sign(dns_message_t *msg) { ret = dst_key_sigsize(key->key, &sigsize); if (ret != ISC_R_SUCCESS) goto cleanup_context; - tsig.signature = (unsigned char *) isc_mem_get(mctx, sigsize); - if (tsig.signature == NULL) { - ret = ISC_R_NOMEMORY; - goto cleanup_context; - } + tsig.signature = isc_mem_get(mctx, sigsize); isc_buffer_init(&sigbuf, tsig.signature, sigsize); ret = dst_context_sign(ctx, &sigbuf); @@ -1775,8 +1761,6 @@ dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ringp) { REQUIRE(*ringp == NULL); ring = isc_mem_get(mctx, sizeof(dns_tsig_keyring_t)); - if (ring == NULL) - return (ISC_R_NOMEMORY); result = isc_rwlock_init(&ring->lock, 0, 0); if (result != ISC_R_SUCCESS) { diff --git a/lib/dns/update.c b/lib/dns/update.c index e95cc0f84d..48aa23b30d 100644 --- a/lib/dns/update.c +++ b/lib/dns/update.c @@ -1417,8 +1417,6 @@ dns_update_signaturesinc(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, state = &mystate; } else { state = isc_mem_get(diff->mctx, sizeof(*state)); - if (state == NULL) - return (ISC_R_NOMEMORY); } dns_diff_init(diff->mctx, &state->diffnames); diff --git a/lib/dns/validator.c b/lib/dns/validator.c index e5597cd1a1..34b2524310 100644 --- a/lib/dns/validator.c +++ b/lib/dns/validator.c @@ -1591,8 +1591,6 @@ validate(dns_validator_t *val, bool resume) { if (val->siginfo == NULL) { val->siginfo = isc_mem_get(val->view->mctx, sizeof(*val->siginfo)); - if (val->siginfo == NULL) - return (ISC_R_NOMEMORY); } result = dns_rdata_tostruct(&rdata, val->siginfo, NULL); if (result != ISC_R_SUCCESS) @@ -3735,8 +3733,6 @@ dns_validator_create(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type, REQUIRE(validatorp != NULL && *validatorp == NULL); val = isc_mem_get(view->mctx, sizeof(*val)); - if (val == NULL) - return (ISC_R_NOMEMORY); val->view = NULL; dns_view_weakattach(view, &val->view); diff --git a/lib/dns/view.c b/lib/dns/view.c index 1a85855774..36ec7301fb 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -91,8 +91,6 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, REQUIRE(viewp != NULL && *viewp == NULL); view = isc_mem_get(mctx, sizeof(*view)); - if (view == NULL) - return (ISC_R_NOMEMORY); view->nta_file = NULL; view->mctx = NULL; @@ -1687,10 +1685,7 @@ dns_view_adddelegationonly(dns_view_t *view, const dns_name_t *name) { if (view->delonly == NULL) { view->delonly = isc_mem_get(view->mctx, - sizeof(dns_namelist_t) * - DNS_VIEW_DELONLYHASH); - if (view->delonly == NULL) - return (ISC_R_NOMEMORY); + sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH); for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) ISC_LIST_INIT(view->delonly[hash]); } @@ -1701,8 +1696,6 @@ dns_view_adddelegationonly(dns_view_t *view, const dns_name_t *name) { if (item != NULL) return (ISC_R_SUCCESS); item = isc_mem_get(view->mctx, sizeof(*item)); - if (item == NULL) - return (ISC_R_NOMEMORY); dns_name_init(item, NULL); result = dns_name_dup(name, view->mctx, item); if (result == ISC_R_SUCCESS) @@ -1722,10 +1715,7 @@ dns_view_excludedelegationonly(dns_view_t *view, const dns_name_t *name) { if (view->rootexclude == NULL) { view->rootexclude = isc_mem_get(view->mctx, - sizeof(dns_namelist_t) * - DNS_VIEW_DELONLYHASH); - if (view->rootexclude == NULL) - return (ISC_R_NOMEMORY); + sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH); for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) ISC_LIST_INIT(view->rootexclude[hash]); } @@ -1736,8 +1726,6 @@ dns_view_excludedelegationonly(dns_view_t *view, const dns_name_t *name) { if (item != NULL) return (ISC_R_SUCCESS); item = isc_mem_get(view->mctx, sizeof(*item)); - if (item == NULL) - return (ISC_R_NOMEMORY); dns_name_init(item, NULL); result = dns_name_dup(name, view->mctx, item); if (result == ISC_R_SUCCESS) diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 303a3c9f38..812618dc86 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -797,8 +797,6 @@ xfrin_create(isc_mem_t *mctx, isc_result_t result; xfr = isc_mem_get(mctx, sizeof(*xfr)); - if (xfr == NULL) - return (ISC_R_NOMEMORY); xfr->mctx = NULL; isc_mem_attach(mctx, &xfr->mctx); xfr->refcount = 0; diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 25c8fcfa2a..85ff3afbbd 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -895,9 +895,6 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) { TIME_NOW(&now); zone = isc_mem_get(mctx, sizeof(*zone)); - if (zone == NULL) { - return (ISC_R_NOMEMORY); - } zone->mctx = NULL; isc_mem_attach(mctx, &zone->mctx); @@ -1458,9 +1455,6 @@ dns_zone_setdbtype(dns_zone_t *zone, /* Set up a new database argument list. */ argv = isc_mem_get(zone->mctx, dbargc * sizeof(*argv)); - if (argv == NULL) { - goto nomem; - } for (i = 0; i < dbargc; i++) { argv[i] = NULL; } @@ -2242,9 +2236,7 @@ dns_zone_asyncload(dns_zone_t *zone, bool newonly, return (ISC_R_ALREADYRUNNING); } - asl = isc_mem_get(zone->mctx, sizeof (*asl)); - if (asl == NULL) - CHECK(ISC_R_NOMEMORY); + asl = isc_mem_get(zone->mctx, sizeof(*asl)); asl->zone = NULL; asl->flags = newonly ? DNS_ZONELOADFLAG_NOSTAT : 0; @@ -2370,8 +2362,6 @@ zone_registerinclude(const char *filename, void *arg) { return; inc = isc_mem_get(zone->mctx, sizeof(dns_include_t)); - if (inc == NULL) - return; inc->name = isc_mem_strdup(zone->mctx, filename); if (inc->name == NULL) { isc_mem_put(zone->mctx, inc, sizeof(dns_include_t)); @@ -2536,8 +2526,6 @@ zone_startload(dns_db_t *db, dns_zone_t *zone, isc_time_t loadtime) { if (zone->zmgr != NULL && zone->db != NULL && zone->loadtask != NULL) { load = isc_mem_get(zone->mctx, sizeof(*load)); - if (load == NULL) - return (ISC_R_NOMEMORY); load->mctx = NULL; load->zone = NULL; @@ -3438,10 +3426,6 @@ zone_addnsec3chain(dns_zone_t *zone, dns_rdata_nsec3param_t *nsec3param) { * separate zone_nsec3chain() calls. */ nsec3chain = isc_mem_get(zone->mctx, sizeof *nsec3chain); - if (nsec3chain == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } nsec3chain->magic = 0; nsec3chain->done = false; @@ -5904,42 +5888,26 @@ set_addrkeylist(unsigned int count, REQUIRE(newnamesp != NULL && *newnamesp == NULL); newaddrs = isc_mem_get(mctx, count * sizeof(*newaddrs)); - if (newaddrs == NULL) - return (ISC_R_NOMEMORY); memmove(newaddrs, addrs, count * sizeof(*newaddrs)); if (dscp != NULL) { newdscp = isc_mem_get(mctx, count * sizeof(*newdscp)); - if (newdscp == NULL) { - isc_mem_put(mctx, newaddrs, count * sizeof(*newaddrs)); - return (ISC_R_NOMEMORY); - } memmove(newdscp, dscp, count * sizeof(*newdscp)); } else newdscp = NULL; if (names != NULL) { newnames = isc_mem_get(mctx, count * sizeof(*newnames)); - if (newnames == NULL) { - if (newdscp != NULL) - isc_mem_put(mctx, newdscp, - count * sizeof(*newdscp)); - isc_mem_put(mctx, newaddrs, count * sizeof(*newaddrs)); - return (ISC_R_NOMEMORY); - } for (i = 0; i < count; i++) newnames[i] = NULL; for (i = 0; i < count; i++) { if (names[i] != NULL) { newnames[i] = isc_mem_get(mctx, - sizeof(dns_name_t)); - if (newnames[i] == NULL) - goto allocfail; + sizeof(dns_name_t)); dns_name_init(newnames[i], NULL); result = dns_name_dup(names[i], mctx, newnames[i]); if (result != ISC_R_SUCCESS) { - allocfail: for (i = 0; i < count; i++) if (newnames[i] != NULL) dns_name_free( @@ -6113,11 +6081,7 @@ dns_zone_setmasterswithkeys(dns_zone_t *zone, * mastersok must contain count elements */ newok = isc_mem_get(zone->mctx, count * sizeof(*newok)); - if (newok == NULL) { - result = ISC_R_NOMEMORY; - isc_mem_put(zone->mctx, newaddrs, count * sizeof(*newaddrs)); - goto unlock; - }; + ; for (i = 0; i < count; i++) newok[i] = false; @@ -10286,10 +10250,6 @@ zone_refreshkeys(dns_zone_t *zone) { } kfetch = isc_mem_get(zone->mctx, sizeof(dns_keyfetch_t)); - if (kfetch == NULL) { - fetch_err = true; - goto failure; - } zone->refreshkeycount++; kfetch->zone = zone; @@ -11340,8 +11300,6 @@ notify_create(isc_mem_t *mctx, unsigned int flags, dns_notify_t **notifyp) { REQUIRE(notifyp != NULL && *notifyp == NULL); notify = isc_mem_get(mctx, sizeof(*notify)); - if (notify == NULL) - return (ISC_R_NOMEMORY); notify->mctx = NULL; isc_mem_attach(mctx, ¬ify->mctx); @@ -13060,8 +13018,6 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) { if (stub == NULL) { stub = isc_mem_get(zone->mctx, sizeof(*stub)); - if (stub == NULL) - goto cleanup; stub->magic = STUB_MAGIC; stub->mctx = zone->mctx; stub->zone = NULL; @@ -15070,8 +15026,6 @@ save_nsec3param(dns_zone_t *zone, nsec3paramlist_t *nsec3list) { DNS_LOGMODULE_ZONE, ISC_LOG_DEBUG(3), "looping through nsec3param data"); nsec3param = isc_mem_get(zone->mctx, sizeof(nsec3param_t)); - if (nsec3param == NULL) - CHECK(ISC_R_NOMEMORY); ISC_LINK_INIT(nsec3param, link); /* @@ -15143,8 +15097,6 @@ save_nsec3param(dns_zone_t *zone, nsec3paramlist_t *nsec3list) { } nsec3param = isc_mem_get(zone->mctx, sizeof(nsec3param_t)); - if (nsec3param == NULL) - CHECK(ISC_R_NOMEMORY); ISC_LINK_INIT(nsec3param, link); /* @@ -16451,8 +16403,6 @@ dns_zone_forwardupdate(dns_zone_t *zone, dns_message_t *msg, REQUIRE(callback != NULL); forward = isc_mem_get(zone->mctx, sizeof(*forward)); - if (forward == NULL) - return (ISC_R_NOMEMORY); forward->request = NULL; forward->zone = NULL; @@ -16532,8 +16482,6 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_result_t result; zmgr = isc_mem_get(mctx, sizeof(*zmgr)); - if (zmgr == NULL) - return (ISC_R_NOMEMORY); zmgr->mctx = NULL; zmgr->refs = 1; isc_mem_attach(mctx, &zmgr->mctx); @@ -17174,8 +17122,6 @@ zonemgr_getio(dns_zonemgr_t *zmgr, bool high, REQUIRE(iop != NULL && *iop == NULL); io = isc_mem_get(zmgr->mctx, sizeof(*io)); - if (io == NULL) - return (ISC_R_NOMEMORY); io->event = isc_event_allocate(zmgr->mctx, task, DNS_EVENT_IOREADY, action, arg, sizeof(*io->event)); @@ -17281,8 +17227,6 @@ zone_saveunique(dns_zone_t *zone, const char *path, const char *templat) { buflen = strlen(path) + strlen(templat) + 2; buf = isc_mem_get(zone->mctx, buflen); - if (buf == NULL) - return; result = isc_file_template(path, templat, buf, buflen); if (result != ISC_R_SUCCESS) @@ -17952,8 +17896,6 @@ zone_signwithkey(dns_zone_t *zone, dns_secalg_t algorithm, uint16_t keyid, dns_db_t *db = NULL; signing = isc_mem_get(zone->mctx, sizeof *signing); - if (signing == NULL) - return (ISC_R_NOMEMORY); signing->magic = 0; signing->db = NULL; diff --git a/lib/dns/zoneverify.c b/lib/dns/zoneverify.c index e3d1f5b242..29a06c4757 100644 --- a/lib/dns/zoneverify.c +++ b/lib/dns/zoneverify.c @@ -444,9 +444,6 @@ record_nsec3(const vctx_t *vctx, const unsigned char *rawhash, len = sizeof(*element) + nsec3->next_length * 2 + nsec3->salt_length; element = isc_mem_get(vctx->mctx, len); - if (element == NULL) { - return (ISC_R_NOMEMORY); - } memset(element, 0, len); element->hash = nsec3->hash; element->salt_length = nsec3->salt_length; diff --git a/lib/dns/zt.c b/lib/dns/zt.c index ab8bc818fc..8c63ed1de8 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -83,8 +83,6 @@ dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) { REQUIRE(ztp != NULL && *ztp == NULL); zt = isc_mem_get(mctx, sizeof(*zt)); - if (zt == NULL) - return (ISC_R_NOMEMORY); zt->table = NULL; result = dns_rbt_create(mctx, auto_detach, zt, &zt->table); @@ -295,9 +293,6 @@ dns_zt_asyncload(dns_zt_t *zt, bool newonly, REQUIRE(VALID_ZT(zt)); zt->loadparams = isc_mem_get(zt->mctx, sizeof(struct zt_load_params)); - if (zt->loadparams == NULL) { - return (ISC_R_NOMEMORY); - } zt->loadparams->dl = doneloading; zt->loadparams->newonly = newonly; diff --git a/lib/irs/context.c b/lib/irs/context.c index 8057fe3551..c9d4b7d4c3 100644 --- a/lib/irs/context.c +++ b/lib/irs/context.c @@ -217,10 +217,6 @@ irs_context_create(irs_context_t **contextp) { } context = isc_mem_get(mctx, sizeof(*context)); - if (context == NULL) { - ctxs_destroy(&mctx, &actx, &taskmgr, &socketmgr, &timermgr); - return (ISC_R_NOMEMORY); - } context->mctx = mctx; context->actx = actx; diff --git a/lib/irs/dnsconf.c b/lib/irs/dnsconf.c index c7c32d22db..3247f58366 100644 --- a/lib/irs/dnsconf.c +++ b/lib/irs/dnsconf.c @@ -130,10 +130,6 @@ configure_key(isc_mem_t *mctx, const cfg_obj_t *key, irs_dnsconf_t *conf, return (result); } keyname = isc_mem_get(mctx, sizeof(*keyname)); - if (keyname == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } dns_name_init(keyname, NULL); result = dns_name_dup(keyname_base, mctx, keyname); if (result != ISC_R_SUCCESS) { @@ -142,11 +138,6 @@ configure_key(isc_mem_t *mctx, const cfg_obj_t *key, irs_dnsconf_t *conf, /* Add the key data to the list */ keyent = isc_mem_get(mctx, sizeof(*keyent)); - if (keyent == NULL) { - dns_name_free(keyname, mctx); - result = ISC_R_NOMEMORY; - goto cleanup; - } keyent->keyname = keyname; keyent->keydatabuf = keydatabuf; @@ -245,8 +236,6 @@ irs_dnsconf_load(isc_mem_t *mctx, const char *filename, irs_dnsconf_t **confp) REQUIRE(confp != NULL && *confp == NULL); conf = isc_mem_get(mctx, sizeof(*conf)); - if (conf == NULL) - return (ISC_R_NOMEMORY); conf->mctx = mctx; ISC_LIST_INIT(conf->trusted_keylist); diff --git a/lib/irs/getaddrinfo.c b/lib/irs/getaddrinfo.c index 1f312050b3..fc115486f1 100644 --- a/lib/irs/getaddrinfo.c +++ b/lib/irs/getaddrinfo.c @@ -592,8 +592,6 @@ make_resstate(isc_mem_t *mctx, gai_statehead_t *head, const char *hostname, bool need_v6 = false; state = isc_mem_get(mctx, sizeof(*state)); - if (state == NULL) - return (ISC_R_NOMEMORY); /* Construct base domain name */ namelen = strlen(domain); @@ -626,10 +624,6 @@ make_resstate(isc_mem_t *mctx, gai_statehead_t *head, const char *hostname, state->trans4 = NULL; if (need_v4) { state->trans4 = isc_mem_get(mctx, sizeof(gai_restrans_t)); - if (state->trans4 == NULL) { - isc_mem_put(mctx, state, sizeof(*state)); - return (ISC_R_NOMEMORY); - } state->trans4->error = 0; state->trans4->xid = NULL; state->trans4->resstate = state; @@ -638,13 +632,6 @@ make_resstate(isc_mem_t *mctx, gai_statehead_t *head, const char *hostname, } if (need_v6) { state->trans6 = isc_mem_get(mctx, sizeof(gai_restrans_t)); - if (state->trans6 == NULL) { - if (state->trans4 != NULL) - isc_mem_put(mctx, state->trans4, - sizeof(*state->trans4)); - isc_mem_put(mctx, state, sizeof(*state)); - return (ISC_R_NOMEMORY); - } state->trans6->error = 0; state->trans6->xid = NULL; state->trans6->resstate = state; diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c index a186d14995..34981d88ea 100644 --- a/lib/irs/resconf.c +++ b/lib/irs/resconf.c @@ -229,10 +229,6 @@ add_server(isc_mem_t *mctx, const char *address_str, } address = isc_mem_get(mctx, sizeof(*address)); - if (address == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } if (res->ai_addrlen > sizeof(address->type)) { isc_mem_put(mctx, address, sizeof(*address)); result = ISC_R_RANGE; @@ -473,8 +469,6 @@ add_search(irs_resconf_t *conf, char *domain) { irs_resconf_search_t *entry; entry = isc_mem_get(conf->mctx, sizeof(*entry)); - if (entry == NULL) - return (ISC_R_NOMEMORY); entry->domain = domain; ISC_LINK_INIT(entry, link); @@ -500,8 +494,6 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) REQUIRE(confp != NULL && *confp == NULL); conf = isc_mem_get(mctx, sizeof(*conf)); - if (conf == NULL) - return (ISC_R_NOMEMORY); conf->mctx = mctx; ISC_LIST_INIT(conf->nameservers); diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 0a0ded25d6..219a5493ab 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -546,14 +546,8 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer, REQUIRE(*dynbuffer == NULL); dbuf = isc_mem_get(mctx, sizeof(isc_buffer_t)); - if (dbuf == NULL) - return (ISC_R_NOMEMORY); bdata = isc_mem_get(mctx, length); - if (bdata == NULL) { - isc_mem_put(mctx, dbuf, sizeof(isc_buffer_t)); - return (ISC_R_NOMEMORY); - } isc_buffer_init(dbuf, bdata, length); dbuf->mctx = mctx; @@ -600,10 +594,7 @@ isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) { * it doesn't remap pages, but does ordinary copy. So is * isc_mem_reallocate(), which has additional issues. */ - bdata = isc_mem_get((*dynbuffer)->mctx, (unsigned int) len); - if (bdata == NULL) { - return (ISC_R_NOMEMORY); - } + bdata = isc_mem_get((*dynbuffer)->mctx, (unsigned int)len); memmove(bdata, (*dynbuffer)->base, (*dynbuffer)->length); isc_mem_put((*dynbuffer)->mctx, (*dynbuffer)->base, diff --git a/lib/isc/commandline.c b/lib/isc/commandline.c index ccc0692a57..34172d2693 100644 --- a/lib/isc/commandline.c +++ b/lib/isc/commandline.c @@ -214,8 +214,6 @@ isc_commandline_strtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, /* We have reached the end of the string. */ *argcp = n; *argvp = isc_mem_get(mctx, n * sizeof(char *)); - if (*argvp == NULL) - return (ISC_R_NOMEMORY); } else { char *p = s; while (*p != ' ' && *p != '\t' && *p != '\0' && *p != '{') { diff --git a/lib/isc/counter.c b/lib/isc/counter.c index b5bbe46fd1..52abdae922 100644 --- a/lib/isc/counter.c +++ b/lib/isc/counter.c @@ -39,8 +39,6 @@ isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp) { REQUIRE(counterp != NULL && *counterp == NULL); counter = isc_mem_get(mctx, sizeof(*counter)); - if (counter == NULL) - return (ISC_R_NOMEMORY); counter->mctx = NULL; isc_mem_attach(mctx, &counter->mctx); diff --git a/lib/isc/event.c b/lib/isc/event.c index cacd9af13c..3df4283c88 100644 --- a/lib/isc/event.c +++ b/lib/isc/event.c @@ -39,8 +39,6 @@ isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, REQUIRE(action != NULL); event = isc_mem_get(mctx, size); - if (event == NULL) - return (NULL); ISC_EVENT_INIT(event, size, 0, NULL, type, action, arg, sender, destroy, mctx); @@ -59,8 +57,6 @@ isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, REQUIRE(action != NULL); event = isc_mem_get(mctx, size); - if (event == NULL) - return (NULL); /* * Removing the const attribute from "arg" is the best of two diff --git a/lib/isc/heap.c b/lib/isc/heap.c index 8aea4782de..52c08f7cf9 100644 --- a/lib/isc/heap.c +++ b/lib/isc/heap.c @@ -88,8 +88,6 @@ isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, REQUIRE(compare != NULL); heap = isc_mem_get(mctx, sizeof(*heap)); - if (heap == NULL) - return (ISC_R_NOMEMORY); heap->magic = HEAP_MAGIC; heap->size = 0; heap->mctx = NULL; @@ -134,8 +132,6 @@ resize(isc_heap_t *heap) { new_size = heap->size + heap->size_increment; new_array = isc_mem_get(heap->mctx, new_size * sizeof(void *)); - if (new_array == NULL) - return (false); if (heap->array != NULL) { memmove(new_array, heap->array, heap->size * sizeof(void *)); isc_mem_put(heap->mctx, heap->array, diff --git a/lib/isc/ht.c b/lib/isc/ht.c index 2275bab018..bad7e60fb5 100644 --- a/lib/isc/ht.c +++ b/lib/isc/ht.c @@ -58,9 +58,6 @@ isc_ht_init(isc_ht_t **htp, isc_mem_t *mctx, uint8_t bits) { REQUIRE(bits >= 1 && bits <= (sizeof(size_t)*8 - 1)); ht = isc_mem_get(mctx, sizeof(struct isc_ht)); - if (ht == NULL) { - return (ISC_R_NOMEMORY); - } ht->mctx = NULL; isc_mem_attach(mctx, &ht->mctx); @@ -69,11 +66,7 @@ isc_ht_init(isc_ht_t **htp, isc_mem_t *mctx, uint8_t bits) { ht->mask = ((size_t)1<count = 0; - ht->table = isc_mem_get(ht->mctx, ht->size * sizeof(isc_ht_node_t*)); - if (ht->table == NULL) { - isc_mem_putanddetach(&ht->mctx, ht, sizeof(struct isc_ht)); - return (ISC_R_NOMEMORY); - } + ht->table = isc_mem_get(ht->mctx, ht->size * sizeof(isc_ht_node_t *)); for (i = 0; i < ht->size; i++) { ht->table[i] = NULL; @@ -139,8 +132,6 @@ isc_ht_add(isc_ht_t *ht, const unsigned char *key, } node = isc_mem_get(ht->mctx, offsetof(isc_ht_node_t, key) + keysize); - if (node == NULL) - return (ISC_R_NOMEMORY); memmove(node->key, key, keysize); node->keysize = keysize; @@ -219,8 +210,6 @@ isc_ht_iter_create(isc_ht_t *ht, isc_ht_iter_t **itp) { REQUIRE(itp != NULL && *itp == NULL); it = isc_mem_get(ht->mctx, sizeof(isc_ht_iter_t)); - if (it == NULL) - return (ISC_R_NOMEMORY); it->ht = ht; it->i = 0; diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index a92bf69128..3642529c83 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -263,8 +263,6 @@ isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, REQUIRE(httpdmgrp != NULL && *httpdmgrp == NULL); httpdmgr = isc_mem_get(mctx, sizeof(isc_httpdmgr_t)); - if (httpdmgr == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&httpdmgr->lock); httpdmgr->mctx = NULL; @@ -635,12 +633,6 @@ isc_httpd_accept(isc_task_t *task, isc_event_t *ev) { } httpd = isc_mem_get(httpdmgr->mctx, sizeof(isc_httpd_t)); - if (httpd == NULL) { - /* XXXMLG log failure */ - NOTICE("accept failed to allocate memory, goto requeue"); - isc_socket_detach(&nev->newsocket); - goto requeue; - } httpd->mgr = httpdmgr; ISC_LINK_INIT(httpd, link); @@ -654,11 +646,6 @@ isc_httpd_accept(isc_task_t *task, isc_event_t *ev) { * Initialize the buffer for our headers. */ headerdata = isc_mem_get(httpdmgr->mctx, HTTP_SENDGROW); - if (headerdata == NULL) { - isc_mem_put(httpdmgr->mctx, httpd, sizeof(isc_httpd_t)); - isc_socket_detach(&nev->newsocket); - goto requeue; - } isc_buffer_init(&httpd->headerbuffer, headerdata, HTTP_SENDGROW); isc_buffer_initnull(&httpd->compbuffer); @@ -767,8 +754,6 @@ alloc_compspace(isc_httpd_t *httpd, unsigned int size) { } newspace = isc_mem_get(httpd->mgr->mctx, size); - if (newspace == NULL) - return (ISC_R_NOMEMORY); isc_buffer_reinit(&httpd->compbuffer, newspace, size); if (r.base != NULL) { @@ -1021,8 +1006,6 @@ grow_headerspace(isc_httpd_t *httpd) { return (ISC_R_NOSPACE); newspace = isc_mem_get(httpd->mgr->mctx, newlen); - if (newspace == NULL) - return (ISC_R_NOMEMORY); isc_buffer_reinit(&httpd->headerbuffer, newspace, newlen); @@ -1211,8 +1194,6 @@ isc_httpdmgr_addurl2(isc_httpdmgr_t *httpdmgr, const char *url, } item = isc_mem_get(httpdmgr->mctx, sizeof(isc_httpdurl_t)); - if (item == NULL) - return (ISC_R_NOMEMORY); item->url = isc_mem_strdup(httpdmgr->mctx, url); if (item->url == NULL) { diff --git a/lib/isc/lex.c b/lib/isc/lex.c index fbf0036ca8..b67ef72af6 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -67,8 +67,6 @@ grow_data(isc_lex_t *lex, size_t *remainingp, char **currp, char **prevp) { char *tmp; tmp = isc_mem_get(lex->mctx, lex->max_token * 2 + 1); - if (tmp == NULL) - return (ISC_R_NOMEMORY); memmove(tmp, lex->data, lex->max_token + 1); *currp = tmp + (*currp - lex->data); if (*prevp != NULL) @@ -93,13 +91,7 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) { max_token = 1; lex = isc_mem_get(mctx, sizeof(*lex)); - if (lex == NULL) - return (ISC_R_NOMEMORY); lex->data = isc_mem_get(mctx, max_token + 1); - if (lex->data == NULL) { - isc_mem_put(mctx, lex, sizeof(*lex)); - return (ISC_R_NOMEMORY); - } lex->mctx = mctx; lex->max_token = max_token; lex->comments = 0; @@ -192,8 +184,6 @@ new_source(isc_lex_t *lex, bool is_file, bool need_close, isc_result_t result; source = isc_mem_get(lex->mctx, sizeof(*source)); - if (source == NULL) - return (ISC_R_NOMEMORY); source->result = ISC_R_SUCCESS; source->is_file = is_file; source->need_close = need_close; diff --git a/lib/isc/log.c b/lib/isc/log.c index 69d5be5e58..be4bc36c29 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -323,7 +323,7 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) { lcfg = isc_mem_get(lctx->mctx, sizeof(*lcfg)); - if (lcfg != NULL) { + { lcfg->lctx = lctx; lcfg->channellists = NULL; lcfg->channellist_count = 0; @@ -331,19 +331,9 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) { lcfg->highest_level = level; lcfg->tag = NULL; lcfg->dynamic = false; - ISC_LIST_INIT(lcfg->channels); - - /* - * Normally the magic number is the last thing set in the - * structure, but isc_log_createchannel() needs a valid - * config. If the channel creation fails, the lcfg is not - * returned to the caller. - */ lcfg->magic = LCFG_MAGIC; - - } else - result = ISC_R_NOMEMORY; + } /* * Create the default channels: @@ -710,8 +700,6 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name, mctx = lcfg->lctx->mctx; channel = isc_mem_get(mctx, sizeof(*channel)); - if (channel == NULL) - return (ISC_R_NOMEMORY); channel->name = isc_mem_strdup(mctx, name); if (channel->name == NULL) { @@ -1004,8 +992,6 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, return (result); new_item = isc_mem_get(lctx->mctx, sizeof(*new_item)); - if (new_item == NULL) - return (ISC_R_NOMEMORY); new_item->channel = channel; new_item->module = module; @@ -1050,9 +1036,6 @@ sync_channellist(isc_logconfig_t *lcfg) { lists = isc_mem_get(lctx->mctx, bytes); - if (lists == NULL) - return (ISC_R_NOMEMORY); - memset(lists, 0, bytes); if (lcfg->channellist_count != 0) { @@ -1735,18 +1718,12 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, size = sizeof(isc_logmessage_t) + strlen(lctx->buffer) + 1; message = isc_mem_get(lctx->mctx, size); - if (message != NULL) { - /* - * Put the text immediately after - * the struct. The strcpy is safe. - */ + { message->text = (char *)(message + 1); size -= sizeof(isc_logmessage_t); strlcpy(message->text, lctx->buffer, size); - TIME_NOW(&message->time); - ISC_LINK_INIT(message, link); ISC_LIST_APPEND(lctx->messages, message, link); diff --git a/lib/isc/pk11.c b/lib/isc/pk11.c index 0d820901cb..6dfd51ffa2 100644 --- a/lib/isc/pk11.c +++ b/lib/isc/pk11.c @@ -801,21 +801,11 @@ push_attribute(pk11_object_t *obj, isc_mem_t *mctx, size_t len) { CK_BYTE cnt = obj->attrcnt; obj->repr = isc_mem_get(mctx, (cnt + 1) * sizeof(*attr)); - if (obj->repr == NULL) { - obj->repr = old; - return (NULL); - } memset(obj->repr, 0, (cnt + 1) * sizeof(*attr)); memmove(obj->repr, old, cnt * sizeof(*attr)); attr = obj->repr + cnt; attr->ulValueLen = (CK_ULONG) len; attr->pValue = isc_mem_get(mctx, len); - if (attr->pValue == NULL) { - memset(obj->repr, 0, (cnt + 1) * sizeof(*attr)); - isc_mem_put(mctx, obj->repr, (cnt + 1) * sizeof(*attr)); - obj->repr = old; - return (NULL); - } memset(attr->pValue, 0, len); if (old != NULL) { memset(old, 0, cnt * sizeof(*attr)); @@ -843,8 +833,6 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, /* get values to work on */ len = strlen(label) + 1; uri = isc_mem_get(mctx, len); - if (uri == NULL) - return (ISC_R_NOMEMORY); memmove(uri, label, len); /* get the URI scheme */ diff --git a/lib/isc/pool.c b/lib/isc/pool.c index 2660540ec8..88b27643c4 100644 --- a/lib/isc/pool.c +++ b/lib/isc/pool.c @@ -41,8 +41,6 @@ alloc_pool(isc_mem_t *mctx, unsigned int count, isc_pool_t **poolp) { isc_pool_t *pool; pool = isc_mem_get(mctx, sizeof(*pool)); - if (pool == NULL) - return (ISC_R_NOMEMORY); pool->count = count; pool->free = NULL; pool->init = NULL; @@ -50,10 +48,6 @@ alloc_pool(isc_mem_t *mctx, unsigned int count, isc_pool_t **poolp) { pool->mctx = NULL; isc_mem_attach(mctx, &pool->mctx); pool->pool = isc_mem_get(mctx, count * sizeof(void *)); - if (pool->pool == NULL) { - isc_mem_put(mctx, pool, sizeof(*pool)); - return (ISC_R_NOMEMORY); - } memset(pool->pool, 0, count * sizeof(void *)); *poolp = pool; diff --git a/lib/isc/portset.c b/lib/isc/portset.c index 55e6bfe8a2..5898b83148 100644 --- a/lib/isc/portset.c +++ b/lib/isc/portset.c @@ -61,8 +61,6 @@ isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp) { REQUIRE(portsetp != NULL && *portsetp == NULL); portset = isc_mem_get(mctx, sizeof(*portset)); - if (portset == NULL) - return (ISC_R_NOMEMORY); /* Make the set 'empty' by default */ memset(portset, 0, sizeof(*portset)); diff --git a/lib/isc/radix.c b/lib/isc/radix.c index 1153c1d9cf..f58f9a4540 100644 --- a/lib/isc/radix.c +++ b/lib/isc/radix.c @@ -52,8 +52,6 @@ _new_prefix(isc_mem_t *mctx, isc_prefix_t **target, int family, void *dest, return (ISC_R_NOTIMPLEMENTED); prefix = isc_mem_get(mctx, sizeof(isc_prefix_t)); - if (prefix == NULL) - return (ISC_R_NOMEMORY); if (family == AF_INET6) { prefix->bitlen = (bitlen >= 0) ? bitlen : 128; @@ -136,8 +134,6 @@ isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits) { REQUIRE(target != NULL && *target == NULL); radix = isc_mem_get(mctx, sizeof(isc_radix_tree_t)); - if (radix == NULL) - return (ISC_R_NOMEMORY); radix->mctx = NULL; isc_mem_attach(mctx, &radix->mctx); @@ -317,8 +313,6 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, if (radix->head == NULL) { node = isc_mem_get(radix->mctx, sizeof(isc_radix_node_t)); - if (node == NULL) - return (ISC_R_NOMEMORY); node->bit = bitlen; for (i = 0; i < RADIX_FAMILIES; i++) { node->node_num[i] = -1; @@ -492,15 +486,8 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, } new_node = isc_mem_get(radix->mctx, sizeof(isc_radix_node_t)); - if (new_node == NULL) - return (ISC_R_NOMEMORY); if (node->bit != differ_bit && bitlen != differ_bit) { glue = isc_mem_get(radix->mctx, sizeof(isc_radix_node_t)); - if (glue == NULL) { - isc_mem_put(radix->mctx, new_node, - sizeof(isc_radix_node_t)); - return (ISC_R_NOMEMORY); - } } new_node->bit = bitlen; new_node->prefix = NULL; diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 9eb1c1f8b5..5f2eab7891 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -60,8 +60,6 @@ isc_ratelimiter_create(isc_mem_t *mctx, isc_timermgr_t *timermgr, INSIST(ratelimiterp != NULL && *ratelimiterp == NULL); rl = isc_mem_get(mctx, sizeof(*rl)); - if (rl == NULL) - return ISC_R_NOMEMORY; rl->mctx = mctx; rl->refs = 1; rl->task = task; diff --git a/lib/isc/symtab.c b/lib/isc/symtab.c index 1573ff8273..021d94c18c 100644 --- a/lib/isc/symtab.c +++ b/lib/isc/symtab.c @@ -60,18 +60,11 @@ isc_symtab_create(isc_mem_t *mctx, unsigned int size, REQUIRE(symtabp != NULL && *symtabp == NULL); REQUIRE(size > 0); /* Should be prime. */ - symtab = (isc_symtab_t *)isc_mem_get(mctx, sizeof(*symtab)); - if (symtab == NULL) - return (ISC_R_NOMEMORY); + symtab = isc_mem_get(mctx, sizeof(*symtab)); symtab->mctx = NULL; isc_mem_attach(mctx, &symtab->mctx); - symtab->table = (eltlist_t *)isc_mem_get(mctx, - size * sizeof(eltlist_t)); - if (symtab->table == NULL) { - isc_mem_putanddetach(&symtab->mctx, symtab, sizeof(*symtab)); - return (ISC_R_NOMEMORY); - } + symtab->table = isc_mem_get(mctx, size * sizeof(eltlist_t)); for (i = 0; i < size; i++) INIT_LIST(symtab->table[i]); symtab->size = size; @@ -191,8 +184,6 @@ grow_table(isc_symtab_t *symtab) { INSIST(newsize > 0U && newmax > 0U); newtable = isc_mem_get(symtab->mctx, newsize * sizeof(eltlist_t)); - if (newtable == NULL) - return; for (i = 0; i < newsize; i++) INIT_LIST(newtable[i]); @@ -242,9 +233,7 @@ isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, elt->value, symtab->undefine_arg); } else { - elt = (elt_t *)isc_mem_get(symtab->mctx, sizeof(*elt)); - if (elt == NULL) - return (ISC_R_NOMEMORY); + elt = isc_mem_get(symtab->mctx, sizeof(*elt)); ISC_LINK_INIT(elt, link); symtab->count++; } diff --git a/lib/isc/task.c b/lib/isc/task.c index b97ba306b6..651b0934aa 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -272,8 +272,6 @@ isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum, REQUIRE(taskp != NULL && *taskp == NULL); task = isc_mem_get(manager->mctx, sizeof(*task)); - if (task == NULL) - return (ISC_R_NOMEMORY); XTRACE("isc_task_create"); task->manager = manager; @@ -1359,7 +1357,8 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, manager->default_quantum = default_quantum; INIT_LIST(manager->tasks); atomic_store(&manager->tasks_count, 0); - manager->queues = isc_mem_get(mctx, workers * sizeof(isc__taskqueue_t)); + manager->queues = isc_mem_get(mctx, + workers * sizeof(isc__taskqueue_t)); RUNTIME_CHECK(manager->queues != NULL); atomic_init(&manager->tasks_running, 0); diff --git a/lib/isc/taskpool.c b/lib/isc/taskpool.c index 88cc163f70..e5c09dea4a 100644 --- a/lib/isc/taskpool.c +++ b/lib/isc/taskpool.c @@ -43,8 +43,6 @@ alloc_pool(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks, unsigned int i; pool = isc_mem_get(mctx, sizeof(*pool)); - if (pool == NULL) - return (ISC_R_NOMEMORY); pool->mctx = NULL; isc_mem_attach(mctx, &pool->mctx); @@ -52,10 +50,6 @@ alloc_pool(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks, pool->quantum = quantum; pool->tmgr = tmgr; pool->tasks = isc_mem_get(mctx, ntasks * sizeof(isc_task_t *)); - if (pool->tasks == NULL) { - isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool)); - return (ISC_R_NOMEMORY); - } for (i = 0; i < ntasks; i++) pool->tasks[i] = NULL; diff --git a/lib/isc/timer.c b/lib/isc/timer.c index b5455688f2..ddd9ace486 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -281,8 +281,6 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type, timer = isc_mem_get(manager->mctx, sizeof(*timer)); - if (timer == NULL) - return (ISC_R_NOMEMORY); timer->manager = manager; isc_refcount_init(&timer->references, 1); @@ -681,8 +679,6 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) { REQUIRE(managerp != NULL && *managerp == NULL); manager = isc_mem_get(mctx, sizeof(*manager)); - if (manager == NULL) - return (ISC_R_NOMEMORY); manager->common.impmagic = TIMER_MANAGER_MAGIC; manager->common.magic = ISCAPI_TIMERMGR_MAGIC; diff --git a/lib/isc/unix/ifiter_getifaddrs.c b/lib/isc/unix/ifiter_getifaddrs.c index bf09ea4ba6..41a866d7f1 100644 --- a/lib/isc/unix/ifiter_getifaddrs.c +++ b/lib/isc/unix/ifiter_getifaddrs.c @@ -57,8 +57,6 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { REQUIRE(*iterp == NULL); iter = isc_mem_get(mctx, sizeof(*iter)); - if (iter == NULL) - return (ISC_R_NOMEMORY); iter->mctx = mctx; iter->buf = NULL; diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index d2b8b77156..1d02b987d1 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -3548,8 +3548,7 @@ setup_thread(isc__socketthread_t *thread) { thread->threadid < thread->manager->nthreads); thread->fds = isc_mem_get(thread->manager->mctx, - thread->manager->maxsocks * - sizeof(isc__socket_t *)); + thread->manager->maxsocks * sizeof(isc__socket_t *)); memset(thread->fds, 0, thread->manager->maxsocks * sizeof(isc_socket_t *)); @@ -3603,15 +3602,13 @@ setup_thread(isc__socketthread_t *thread) { #elif defined(USE_EPOLL) thread->nevents = ISC_SOCKET_MAXEVENTS; thread->epoll_events = isc_mem_get(thread->manager->mctx, - (thread->manager->maxsocks * - sizeof(uint32_t))); + (thread->manager->maxsocks * sizeof(uint32_t))); memset(thread->epoll_events, 0, thread->manager->maxsocks * sizeof(uint32_t)); thread->events = isc_mem_get(thread->manager->mctx, - sizeof(struct epoll_event) * - thread->nevents); + sizeof(struct epoll_event) * thread->nevents); thread->epoll_fd = epoll_create(thread->nevents); if (thread->epoll_fd == -1) { @@ -3642,8 +3639,7 @@ setup_thread(isc__socketthread_t *thread) { * it must have maxsocks entries (not nevents). */ thread->fdpollinfo = isc_mem_get(thread->manager->mctx, - sizeof(pollinfo_t) * - thread->manager->maxsocks); + sizeof(pollinfo_t) * thread->manager->maxsocks); memset(thread->fdpollinfo, 0, sizeof(pollinfo_t) * thread->manager->maxsocks); thread->devpoll_fd = open("/dev/poll", O_RDWR); @@ -3806,8 +3802,8 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, /* * Start up the select/poll thread. */ - manager->threads = isc_mem_get(mctx, sizeof(isc__socketthread_t) - * manager->nthreads); + manager->threads = isc_mem_get(mctx, + sizeof(isc__socketthread_t) * manager->nthreads); isc_mem_attach(mctx, &manager->mctx); for (i=0; i < manager->nthreads; i++) { diff --git a/lib/isc/win32/interfaceiter.c b/lib/isc/win32/interfaceiter.c index 000a5a84e0..10667faed7 100644 --- a/lib/isc/win32/interfaceiter.c +++ b/lib/isc/win32/interfaceiter.c @@ -112,8 +112,6 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { REQUIRE(*iterp == NULL); iter = isc_mem_get(mctx, sizeof(*iter)); - if (iter == NULL) - return (ISC_R_NOMEMORY); InitSockets(); @@ -155,10 +153,6 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { for (;;) { iter->buf4 = isc_mem_get(mctx, iter->buf4size); - if (iter->buf4 == NULL) { - result = ISC_R_NOMEMORY; - goto alloc_failure; - } if (WSAIoctl(iter->socket, SIO_GET_INTERFACE_LIST, 0, 0, iter->buf4, iter->buf4size, @@ -237,10 +231,6 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { for (;;) { iter->buf6 = isc_mem_get(mctx, iter->buf6size); - if (iter->buf6 == NULL) { - result = ISC_R_NOMEMORY; - goto ioctl_failure; - } if (WSAIoctl(iter->socket, SIO_ADDRESS_LIST_QUERY, 0, 0, iter->buf6, iter->buf6size, diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 096dfa6386..36d5c78a76 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -1318,9 +1318,6 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, sock = isc_mem_get(manager->mctx, sizeof(*sock)); - if (sock == NULL) - return (ISC_R_NOMEMORY); - sock->magic = 0; isc_refcount_init(&sock->references, 0); @@ -1353,10 +1350,6 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, sock->recvbuf.consume_position = sock->recvbuf.base; sock->recvbuf.remaining = 0; sock->recvbuf.base = isc_mem_get(manager->mctx, sock->recvbuf.len); // max buffer size - if (sock->recvbuf.base == NULL) { - result = ISC_R_NOMEMORY; - goto error; - } /* * Initialize the lock. @@ -2496,8 +2489,6 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, return (ISC_R_NOTIMPLEMENTED); manager = isc_mem_get(mctx, sizeof(*manager)); - if (manager == NULL) - return (ISC_R_NOMEMORY); InitSockets(); diff --git a/lib/isccfg/aclconf.c b/lib/isccfg/aclconf.c index e69f1e82a7..ac48e197f1 100644 --- a/lib/isccfg/aclconf.c +++ b/lib/isccfg/aclconf.c @@ -47,8 +47,6 @@ cfg_aclconfctx_create(isc_mem_t *mctx, cfg_aclconfctx_t **ret) { REQUIRE(ret != NULL && *ret == NULL); actx = isc_mem_get(mctx, sizeof(*actx)); - if (actx == NULL) - return (ISC_R_NOMEMORY); isc_refcount_init(&actx->references, 1); diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 4d6bbf4994..bf7e3a5bca 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -353,12 +353,8 @@ parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t *obj = NULL; CHECK(cfg_create_obj(pctx, &cfg_type_ustring, &obj)); obj->value.string.length = strlen("local"); - obj->value.string.base = isc_mem_get(pctx->mctx, - obj->value.string.length + 1); - if (obj->value.string.base == NULL) { - isc_mem_put(pctx->mctx, obj, sizeof(*obj)); - return (ISC_R_NOMEMORY); - } + obj->value.string.base = isc_mem_get(pctx->mctx, + obj->value.string.length + 1); memmove(obj->value.string.base, "local", 5); obj->value.string.base[5] = '\0'; *ret = obj; diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index 2d95ffaf15..453e18cd5d 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -257,10 +257,6 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) { CHECK(cfg_create_obj(pctx, type, &obj)); obj->value.tuple = isc_mem_get(pctx->mctx, nfields * sizeof(cfg_obj_t *)); - if (obj->value.tuple == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } for (f = fields, i = 0; f->name != NULL; f++, i++) obj->value.tuple[i] = NULL; *ret = obj; @@ -454,8 +450,6 @@ cfg_parser_create(isc_mem_t *mctx, isc_log_t *lctx, cfg_parser_t **ret) { REQUIRE(ret != NULL && *ret == NULL); pctx = isc_mem_get(mctx, sizeof(*pctx)); - if (pctx == NULL) - return (ISC_R_NOMEMORY); pctx->mctx = NULL; isc_mem_attach(mctx, &pctx->mctx); @@ -1649,8 +1643,6 @@ create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) { cfg_listelt_t *elt; elt = isc_mem_get(pctx->mctx, sizeof(*elt)); - if (elt == NULL) - return (ISC_R_NOMEMORY); elt->obj = NULL; ISC_LINK_INIT(elt, link); *eltp = elt; @@ -2490,10 +2482,6 @@ parse_token(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) { isc_lex_getlasttokentext(pctx->lexer, &pctx->token, &r); obj->value.string.base = isc_mem_get(pctx->mctx, r.length + 1); - if (obj->value.string.base == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup; - } obj->value.string.length = r.length; memmove(obj->value.string.base, r.base, r.length); obj->value.string.base[r.length] = '\0'; @@ -3356,8 +3344,6 @@ cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) { REQUIRE(ret != NULL && *ret == NULL); obj = isc_mem_get(pctx->mctx, sizeof(cfg_obj_t)); - if (obj == NULL) - return (ISC_R_NOMEMORY); obj->type = type; obj->file = current_file(pctx); diff --git a/lib/ns/client.c b/lib/ns/client.c index cb79448108..4cad159a48 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -1026,10 +1026,6 @@ client_allocsendbuf(ns_client_t *client, isc_buffer_t *buffer, goto done; } client->tcpbuf = isc_mem_get(client->mctx, TCP_BUFFER_SIZE); - if (client->tcpbuf == NULL) { - result = ISC_R_NOMEMORY; - goto done; - } data = client->tcpbuf; if (tcpbuffer != NULL) { isc_buffer_init(tcpbuffer, data, TCP_BUFFER_SIZE); @@ -2236,7 +2232,7 @@ process_keytag(ns_client_t *client, isc_buffer_t *buf, size_t optlen) { } client->keytag = isc_mem_get(client->mctx, optlen); - if (client->keytag != NULL) { + { client->keytag_len = (uint16_t)optlen; memmove(client->keytag, isc_buffer_current(buf), optlen); } @@ -3109,10 +3105,6 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) { return (result); client = isc_mem_get(mctx, sizeof(*client)); - if (client == NULL) { - isc_mem_detach(&mctx); - return (ISC_R_NOMEMORY); - } client->mctx = mctx; client->sctx = NULL; @@ -3151,10 +3143,6 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) { } client->recvbuf = isc_mem_get(client->mctx, RECV_BUFFER_SIZE); - if (client->recvbuf == NULL) { - result = ISC_R_NOMEMORY; - goto cleanup_sendevent; - } client->recvevent = isc_socket_socketevent(client->mctx, client, ISC_SOCKEVENT_RECVDONE, @@ -3249,7 +3237,6 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) { cleanup_recvbuf: isc_mem_put(client->mctx, client->recvbuf, RECV_BUFFER_SIZE); - cleanup_sendevent: isc_event_free((isc_event_t **)&client->sendevent); client->magic = 0; @@ -3655,8 +3642,6 @@ ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr, #endif manager = isc_mem_get(mctx, sizeof(*manager)); - if (manager == NULL) - return (ISC_R_NOMEMORY); isc_mutex_init(&manager->lock); isc_mutex_init(&manager->listlock); @@ -4132,8 +4117,6 @@ ns_client_dumpmessage(ns_client_t *client, const char *reason) { do { buf = isc_mem_get(client->mctx, len); - if (buf == NULL) - break; isc_buffer_init(&buffer, buf, len); result = dns_message_totext(client->message, &dns_master_style_debug, @@ -4410,21 +4393,11 @@ ns_client_newdbversion(ns_client_t *client, unsigned int n) { for (i = 0; i < n; i++) { dbversion = isc_mem_get(client->mctx, sizeof(*dbversion)); - if (dbversion != NULL) { + { dbversion->db = NULL; dbversion->version = NULL; ISC_LIST_INITANDAPPEND(client->query.freeversions, - dbversion, link); - } else { - /* - * We only return ISC_R_NOMEMORY if we couldn't - * allocate anything. - */ - if (i == 0) { - return (ISC_R_NOMEMORY); - } else { - return (ISC_R_SUCCESS); - } + dbversion, link); } } diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index abb6be2795..923c057cee 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -190,8 +190,6 @@ ns_interfacemgr_create(isc_mem_t *mctx, REQUIRE(*mgrp == NULL); mgr = isc_mem_get(mctx, sizeof(*mgr)); - if (mgr == NULL) - return (ISC_R_NOMEMORY); mgr->mctx = NULL; isc_mem_attach(mctx, &mgr->mctx); @@ -381,8 +379,6 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, REQUIRE(NS_INTERFACEMGR_VALID(mgr)); ifp = isc_mem_get(mgr->mctx, sizeof(*ifp)); - if (ifp == NULL) - return (ISC_R_NOMEMORY); ifp->mgr = NULL; ifp->generation = mgr->generation; @@ -785,8 +781,6 @@ setup_listenon(ns_interfacemgr_t *mgr, isc_interface_t *interface, isc_sockaddr_t *old; addr = isc_mem_get(mgr->mctx, sizeof(*addr)); - if (addr == NULL) - return; isc_sockaddr_fromnetaddr(addr, &interface->address, port); diff --git a/lib/ns/listenlist.c b/lib/ns/listenlist.c index b664196e6f..f198b5c847 100644 --- a/lib/ns/listenlist.c +++ b/lib/ns/listenlist.c @@ -30,8 +30,6 @@ ns_listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp, ns_listenelt_t *elt = NULL; REQUIRE(target != NULL && *target == NULL); elt = isc_mem_get(mctx, sizeof(*elt)); - if (elt == NULL) - return (ISC_R_NOMEMORY); elt->mctx = mctx; ISC_LINK_INIT(elt, link); elt->port = port; @@ -53,8 +51,6 @@ ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target) { ns_listenlist_t *list = NULL; REQUIRE(target != NULL && *target == NULL); list = isc_mem_get(mctx, sizeof(*list)); - if (list == NULL) - return (ISC_R_NOMEMORY); list->mctx = mctx; list->refcount = 1; ISC_LIST_INIT(list->elts); diff --git a/lib/ns/query.c b/lib/ns/query.c index f1f2cf9b7d..310e8ccd7f 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -3937,8 +3937,6 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, if (st == NULL) { st = isc_mem_get(client->mctx, sizeof(*st)); - if (st == NULL) - return (ISC_R_NOMEMORY); st->state = 0; st->rpsdb = NULL; } diff --git a/lib/ns/server.c b/lib/ns/server.c index 4eb107be16..aad9c74cd8 100644 --- a/lib/ns/server.c +++ b/lib/ns/server.c @@ -42,8 +42,6 @@ ns_server_create(isc_mem_t *mctx, ns_matchview_t matchingview, REQUIRE(sctxp != NULL && *sctxp == NULL); sctx = isc_mem_get(mctx, sizeof(*sctx)); - if (sctx == NULL) - return (ISC_R_NOMEMORY); memset(sctx, 0, sizeof(*sctx)); diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index c515b40ba8..55609bbbaa 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -238,8 +238,6 @@ ixfr_rrstream_create(isc_mem_t *mctx, INSIST(sp != NULL && *sp == NULL); s = isc_mem_get(mctx, sizeof(*s)); - if (s == NULL) - return (ISC_R_NOMEMORY); s->common.mctx = NULL; isc_mem_attach(mctx, &s->common.mctx); s->common.methods = &ixfr_rrstream_methods; @@ -327,8 +325,6 @@ axfr_rrstream_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *ver, INSIST(sp != NULL && *sp == NULL); s = isc_mem_get(mctx, sizeof(*s)); - if (s == NULL) - return (ISC_R_NOMEMORY); s->common.mctx = NULL; isc_mem_attach(mctx, &s->common.mctx); s->common.methods = &axfr_rrstream_methods; @@ -448,8 +444,6 @@ soa_rrstream_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *ver, INSIST(sp != NULL && *sp == NULL); s = isc_mem_get(mctx, sizeof(*s)); - if (s == NULL) - return (ISC_R_NOMEMORY); s->common.mctx = NULL; isc_mem_attach(mctx, &s->common.mctx); s->common.methods = &soa_rrstream_methods; @@ -555,8 +549,6 @@ compound_rrstream_create(isc_mem_t *mctx, rrstream_t **soa_stream, INSIST(sp != NULL && *sp == NULL); s = isc_mem_get(mctx, sizeof(*s)); - if (s == NULL) - return (ISC_R_NOMEMORY); s->common.mctx = NULL; isc_mem_attach(mctx, &s->common.mctx); s->common.methods = &compound_rrstream_methods; @@ -1217,8 +1209,6 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id, INSIST(xfrp != NULL && *xfrp == NULL); xfr = isc_mem_get(mctx, sizeof(*xfr)); - if (xfr == NULL) - return (ISC_R_NOMEMORY); xfr->mctx = NULL; isc_mem_attach(mctx, &xfr->mctx); xfr->client = NULL; @@ -1268,10 +1258,6 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id, */ len = 65535; mem = isc_mem_get(mctx, len); - if (mem == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } isc_buffer_init(&xfr->buf, mem, len); /* @@ -1280,10 +1266,6 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id, */ len = 2 + 65535; mem = isc_mem_get(mctx, len); - if (mem == NULL) { - result = ISC_R_NOMEMORY; - goto failure; - } isc_buffer_init(&xfr->txlenbuf, mem, 2); isc_buffer_init(&xfr->txbuf, (char *) mem + 2, len - 2); xfr->txmem = mem; diff --git a/lib/samples/nsprobe.c b/lib/samples/nsprobe.c index d543dbd447..b8365505ae 100644 --- a/lib/samples/nsprobe.c +++ b/lib/samples/nsprobe.c @@ -777,13 +777,6 @@ resolve_nsaddress(isc_task_t *task, isc_event_t *event) { continue; server = isc_mem_get(mctx, sizeof(*server)); - if (server == NULL) { - fprintf(stderr, "resolve_nsaddress: " - "mem_get failed"); - result = ISC_R_NOMEMORY; - POST(result); - goto cleanup; - } isc_sockaddr_fromin(&server->address, &rdata_a.in_addr, 53); ISC_LINK_INIT(server, link); @@ -794,7 +787,6 @@ resolve_nsaddress(isc_task_t *task, isc_event_t *event) { } } - cleanup: dns_client_freeresanswer(client, &rev->answerlist); dns_client_destroyrestrans(&trans->resid); isc_event_free(&event); @@ -914,17 +906,6 @@ resolve_ns(isc_task_t *task, isc_event_t *event) { continue; pns = isc_mem_get(mctx, sizeof(*pns)); - if (pns == NULL) { - fprintf(stderr, - "resolve_ns: mem_get failed"); - result = ISC_R_NOMEMORY; - POST(result); - /* - * XXX: should we continue with the - * available servers anyway? - */ - goto cleanup; - } pns->name = dns_fixedname_initname(&pns->fixedname); @@ -939,7 +920,6 @@ resolve_ns(isc_task_t *task, isc_event_t *event) { } } - cleanup: dns_client_freeresanswer(client, &rev->answerlist); dns_client_destroyrestrans(&trans->resid); isc_event_free(&event); diff --git a/lib/samples/sample-update.c b/lib/samples/sample-update.c index 9922f186a9..6d47ab9d1f 100644 --- a/lib/samples/sample-update.c +++ b/lib/samples/sample-update.c @@ -495,10 +495,6 @@ update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, parse_name(&cmdline, name); rdata = isc_mem_get(mctx, sizeof(*rdata)); - if (rdata == NULL) { - fprintf(stderr, "memory allocation for rdata failed\n"); - exit(1); - } dns_rdata_init(rdata); /* @@ -609,10 +605,6 @@ update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, doneparsing: rdatalist = isc_mem_get(mctx, sizeof(*rdatalist)); - if (rdatalist == NULL) { - fprintf(stderr, "memory allocation for rdatalist failed\n"); - exit(1); - } dns_rdatalist_init(rdatalist); rdatalist->type = rdatatype; rdatalist->rdclass = rdataclass; @@ -622,10 +614,6 @@ update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, ISC_LIST_APPEND(usedrdatalists, rdatalist, link); rdataset = isc_mem_get(mctx, sizeof(*rdataset)); - if (rdataset == NULL) { - fprintf(stderr, "memory allocation for rdataset failed\n"); - exit(1); - } dns_rdataset_init(rdataset); dns_rdatalist_tordataset(rdatalist, rdataset); dns_rdataset_setownercase(rdataset, name); @@ -691,10 +679,6 @@ make_prereq(isc_mem_t *mctx, char *cmdline, bool ispositive, rdatatype = dns_rdatatype_any; rdata = isc_mem_get(mctx, sizeof(*rdata)); - if (rdata == NULL) { - fprintf(stderr, "memory allocation for rdata failed\n"); - exit(1); - } dns_rdata_init(rdata); if (isrrset && ispositive) @@ -703,10 +687,6 @@ make_prereq(isc_mem_t *mctx, char *cmdline, bool ispositive, rdata->flags = DNS_RDATA_UPDATE; rdatalist = isc_mem_get(mctx, sizeof(*rdatalist)); - if (rdatalist == NULL) { - fprintf(stderr, "memory allocation for rdatalist failed\n"); - exit(1); - } dns_rdatalist_init(rdatalist); rdatalist->type = rdatatype; if (ispositive) { @@ -722,10 +702,6 @@ make_prereq(isc_mem_t *mctx, char *cmdline, bool ispositive, ISC_LIST_APPEND(usedrdatalists, rdatalist, link); rdataset = isc_mem_get(mctx, sizeof(*rdataset)); - if (rdataset == NULL) { - fprintf(stderr, "memory allocation for rdataset failed\n"); - exit(1); - } dns_rdataset_init(rdataset); dns_rdatalist_tordataset(rdatalist, rdataset); dns_rdataset_setownercase(rdataset, name);