Commit 9bdc24a9 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Use coccinelle to cleanup the failure handling blocks from isc_mem_strdup

parent 601cb4e4
......@@ -140,8 +140,6 @@ add(char *key, int value) {
}
key = isc_mem_strdup(sym_mctx, key);
if (key == NULL)
return;
symvalue.as_pointer = NULL;
result = isc_symtab_define(symtab, key, value, symvalue,
......
......@@ -714,9 +714,6 @@ setup_dnsseckeys(dns_client_t *client) {
if (trust_anchor == NULL) {
trust_anchor = isc_mem_strdup(mctx, ".");
if (trust_anchor == NULL) {
fatal("out of memory");
}
}
if (trust_anchor != NULL) {
......@@ -1032,8 +1029,6 @@ plus_option(char *option) {
dlv_validation = state;
if (value != NULL) {
dlv_anchor = isc_mem_strdup(mctx, value);
if (dlv_anchor == NULL)
fatal("out of memory");
}
break;
case 'n': /* dnssec */
......@@ -1068,8 +1063,6 @@ plus_option(char *option) {
root_validation = state;
if (value != NULL) {
trust_anchor = isc_mem_strdup(mctx, value);
if (trust_anchor == NULL)
fatal("out of memory");
}
break;
case 'r': /* rrcomments */
......@@ -1252,8 +1245,6 @@ dash_option(char *option, char *next, bool *open_type_class) {
switch (opt) {
case 'a':
anchorfile = isc_mem_strdup(mctx, value);
if (anchorfile == NULL)
fatal("out of memory");
return (value_from_next);
case 'b':
hash = strchr(value, '#');
......@@ -1317,8 +1308,6 @@ dash_option(char *option, char *next, bool *open_type_class) {
isc_mem_free(mctx, curqname);
}
curqname = isc_mem_strdup(mctx, value);
if (curqname == NULL)
fatal("out of memory");
return (value_from_next);
case 't':
*open_type_class = false;
......@@ -1346,8 +1335,6 @@ dash_option(char *option, char *next, bool *open_type_class) {
warn("extra query name");
}
curqname = isc_mem_strdup(mctx, textname);
if (curqname == NULL)
fatal("out of memory");
if (typeset)
warn("extra query type");
qtype = dns_rdatatype_ptr;
......@@ -1494,8 +1481,6 @@ parse_args(int argc, char **argv) {
if (curqname == NULL) {
curqname = isc_mem_strdup(mctx, argv[0]);
if (curqname == NULL)
fatal("out of memory");
}
}
}
......@@ -1509,8 +1494,6 @@ parse_args(int argc, char **argv) {
if (curqname == NULL) {
qname = isc_mem_strdup(mctx, ".");
if (qname == NULL)
fatal("out of memory");
if (!typeset)
qtype = dns_rdatatype_ns;
......
......@@ -113,10 +113,6 @@ main(int argc, char **argv) {
* simplify cleanup later
*/
dir = isc_mem_strdup(mctx, isc_commandline_argument);
if (dir == NULL) {
fatal("Failed to allocate memory for "
"directory");
}
break;
case 'r':
removefile = true;
......
......@@ -253,10 +253,6 @@ main(int argc, char **argv) {
*/
directory = isc_mem_strdup(mctx,
isc_commandline_argument);
if (directory == NULL) {
fatal("Failed to allocate memory for "
"directory");
}
break;
case 'L':
ttl = strtottl(isc_commandline_argument);
......
......@@ -723,8 +723,6 @@ controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx,
obj = cfg_listelt_value(element);
str = cfg_obj_asstring(obj);
newstr = isc_mem_strdup(mctx, str);
if (newstr == NULL)
goto cleanup;
key = isc_mem_get(mctx, sizeof(*key));
key->keyname = newstr;
key->algorithm = DST_ALG_UNKNOWN;
......
......@@ -6969,8 +6969,6 @@ setstring(named_server_t *server, char **field, const char *value) {
if (value != NULL) {
copy = isc_mem_strdup(server->mctx, value);
if (copy == NULL)
return (ISC_R_NOMEMORY);
} else {
copy = NULL;
}
......@@ -7313,8 +7311,6 @@ configure_session_key(const cfg_obj_t **maps, named_server_t *server,
CHECK(dns_name_dup(keyname, mctx, server->session_keyname));
server->session_keyfile = isc_mem_strdup(mctx, keyfile);
if (server->session_keyfile == NULL)
goto cleanup;
server->session_keyalg = algtype;
server->session_keybits = bits;
......@@ -8005,7 +8001,7 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config,
"'lock-file' has no effect "
"because the server was run with -X");
server->lockfile = isc_mem_strdup(server->mctx,
named_g_defaultlockfile);
named_g_defaultlockfile);
} else {
filename = cfg_obj_asstring(obj);
server->lockfile = isc_mem_strdup(server->mctx,
......
......@@ -105,10 +105,6 @@ named_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx,
if (result == ISC_R_SUCCESS) {
s = cfg_obj_asstring(obj);
tctx->gssapi_keytab = isc_mem_strdup(mctx, s);
if (tctx->gssapi_keytab == NULL) {
result = ISC_R_NOMEMORY;
goto failure;
}
}
*tctxp = tctx;
......
......@@ -235,16 +235,8 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
cd->mctx = mctx;
cd->dl_path = isc_mem_strdup(cd->mctx, argv[1]);
if (cd->dl_path == NULL) {
result = ISC_R_NOMEMORY;
goto failed;
}
cd->dlzname = isc_mem_strdup(cd->mctx, dlzname);
if (cd->dlzname == NULL) {
result = ISC_R_NOMEMORY;
goto failed;
}
/* Initialize the lock */
isc_mutex_init(&cd->lock);
......
......@@ -232,16 +232,8 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
cd->mctx = mctx;
cd->dl_path = isc_mem_strdup(cd->mctx, argv[1]);
if (cd->dl_path == NULL) {
result = ISC_R_NOMEMORY;
goto failed;
}
cd->dlzname = isc_mem_strdup(cd->mctx, dlzname);
if (cd->dlzname == NULL) {
result = ISC_R_NOMEMORY;
goto failed;
}
triedload = true;
......
......@@ -1671,8 +1671,6 @@ evaluate_realm(char *cmdline) {
return (STATUS_SYNTAX);
}
realm = isc_mem_strdup(gmctx, buf);
if (realm == NULL)
fatal("out of memory");
return (STATUS_MORE);
#else
UNUSED(cmdline);
......
......@@ -82,10 +82,6 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
}
s = isc_mem_strdup(mctx, parameters);
if (s == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
result = isc_commandline_strtoargv(mctx, s, &argc, &argv, 0);
if (result != ISC_R_SUCCESS) {
......
......@@ -95,10 +95,6 @@ new_sample_instance(isc_mem_t *mctx, const char *db_name,
isc_mem_attach(mctx, &inst->mctx);
inst->db_name = isc_mem_strdup(mctx, db_name);
if (inst->db_name == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
inst->zone1_name = dns_fixedname_initname(&inst->zone1_fn);
inst->zone2_name = dns_fixedname_initname(&inst->zone2_fn);
......
......@@ -164,8 +164,6 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
int i;
tmpString = isc_mem_strdup(named_g_mctx, in);
if (tmpString == NULL)
return (ISC_R_NOMEMORY);
/*
* don't forget is_safe guarantees '.' will NOT be the
......@@ -897,20 +895,14 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
/* get and store our base directory */
cd->basedir = isc_mem_strdup(named_g_mctx, argv[1]);
if (cd->basedir == NULL)
goto no_mem;
cd->basedirsize = strlen(cd->basedir);
/* get and store our data sub-dir */
cd->datadir = isc_mem_strdup(named_g_mctx, argv[2]);
if (cd->datadir == NULL)
goto no_mem;
cd->datadirsize = strlen(cd->datadir);
/* get and store our zone xfr sub-dir */
cd->xfrdir = isc_mem_strdup(named_g_mctx, argv[3]);
if (cd->xfrdir == NULL)
goto no_mem;
cd->xfrdirsize = strlen(cd->xfrdir);
/* get and store our directory split count */
......
......@@ -562,28 +562,16 @@ ldap_get_results(const char *zone, const char *record,
/* set fields */
if (zone != NULL) {
dbi->zone = isc_mem_strdup(named_g_mctx, zone);
if (dbi->zone == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
} else {
dbi->zone = NULL;
}
if (record != NULL) {
dbi->record = isc_mem_strdup(named_g_mctx, record);
if (dbi->record == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
} else {
dbi->record = NULL;
}
if (client != NULL) {
dbi->client = isc_mem_strdup(named_g_mctx, client);
if (dbi->client == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
} else {
dbi->client = NULL;
}
......@@ -1012,20 +1000,8 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
ldap_inst->protocol = protocol;
ldap_inst->method = method;
ldap_inst->hosts = isc_mem_strdup(named_g_mctx, argv[6]);
if (ldap_inst->hosts == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
ldap_inst->user = isc_mem_strdup(named_g_mctx, argv[4]);
if (ldap_inst->user == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
ldap_inst->cred = isc_mem_strdup(named_g_mctx, argv[5]);
if (ldap_inst->cred == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
/* allocate memory for database connection list */
ldap_inst->db = isc_mem_get(named_g_mctx, sizeof(db_list_t));
......
......@@ -222,25 +222,10 @@ stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
memset(cd, 0, sizeof(config_data_t));
cd->myzone = isc_mem_strdup(named_g_mctx, argv[1]);
if (cd->myzone == NULL) {
isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
return (ISC_R_NOMEMORY);
}
cd->myname = isc_mem_strdup(named_g_mctx, argv[2]);
if (cd->myname == NULL) {
isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
isc_mem_free(named_g_mctx, cd->myzone);
return (ISC_R_NOMEMORY);
}
cd->myip = isc_mem_strdup(named_g_mctx, argv[3]);
if (cd->myip == NULL) {
isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
isc_mem_free(named_g_mctx, cd->myname);
isc_mem_free(named_g_mctx, cd->myzone);
return (ISC_R_NOMEMORY);
}
isc_mem_attach(named_g_mctx, &cd->mctx);
......
......@@ -158,11 +158,6 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
ISC_LIST_APPEND(*tql, tseg, link);
tseg->sql = isc_mem_strdup(mctx, sql);
if (tseg->sql == NULL) {
/* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
goto cleanup;
}
/* tseg->sql points directly to a string. */
tseg->direct = true;
tseg->strlen = strlen(tseg->sql);
......
......@@ -379,8 +379,6 @@ nameexist(const cfg_obj_t *obj, const char *name, int value,
isc_symvalue_t symvalue;
key = isc_mem_strdup(mctx, name);
if (key == NULL)
return (ISC_R_NOMEMORY);
symvalue.as_cpointer = obj;
result = isc_symtab_define(symtab, key, value, symvalue,
isc_symexists_reject);
......@@ -2127,20 +2125,17 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
case CFG_ZONE_STUB:
case CFG_ZONE_STATICSTUB:
tmp = isc_mem_strdup(mctx, namebuf);
if (tmp != NULL) {
{
isc_symvalue_t symvalue;
symvalue.as_cpointer = NULL;
tresult = isc_symtab_define(inview, tmp, 1,
symvalue, isc_symexists_replace);
symvalue,
isc_symexists_replace);
if (tresult == ISC_R_NOMEMORY) {
isc_mem_free(mctx, tmp);
}
if (result == ISC_R_SUCCESS &&
tresult != ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS)
result = tresult;
} else if (result != ISC_R_SUCCESS) {
result = ISC_R_NOMEMORY;
}
break;
......@@ -2878,8 +2873,6 @@ check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab,
dns_name_format(name, namebuf, sizeof(namebuf));
keyname = isc_mem_strdup(mctx, namebuf);
if (keyname == NULL)
return (ISC_R_NOMEMORY);
symvalue.as_cpointer = key;
tresult = isc_symtab_define(symtab, keyname, 1, symvalue,
isc_symexists_reject);
......
......@@ -204,10 +204,6 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
cache->name = NULL;
if (cachename != NULL) {
cache->name = isc_mem_strdup(cmctx, cachename);
if (cache->name == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_mem;
}
}
isc_mutex_init(&cache->lock);
......@@ -225,10 +221,6 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
goto cleanup_filelock;
cache->db_type = isc_mem_strdup(cmctx, db_type);
if (cache->db_type == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_stats;
}
/*
* For databases of type "rbt" we pass hmctx to dns_db_create()
......@@ -252,10 +244,6 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
for (i = extra; i < cache->db_argc; i++) {
cache->db_argv[i] = isc_mem_strdup(cmctx,
db_argv[i - extra]);
if (cache->db_argv[i] == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup_dbargv;
}
}
}
......@@ -462,8 +450,6 @@ dns_cache_setfilename(dns_cache_t *cache, const char *filename) {
REQUIRE(filename != NULL);
newname = isc_mem_strdup(cache->mctx, filename);
if (newname == NULL)
return (ISC_R_NOMEMORY);
LOCK(&cache->filelock);
if (cache->filename)
......
......@@ -440,9 +440,7 @@ toregion(dns_dtenv_t *env, isc_region_t *r, const char *str) {
REQUIRE(r != NULL);
if (str != NULL) {
p = (unsigned char *) isc_mem_strdup(env->mctx, str);
if (p == NULL)
return (ISC_R_NOMEMORY);
p = (unsigned char *)isc_mem_strdup(env->mctx, str);
}
if (r->base != NULL) {
......
......@@ -168,8 +168,6 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname,
imp->register_func = register_func;
imp->destroy_func = destroy_func;
imp->name = isc_mem_strdup(mctx, instname);
if (imp->name == NULL)
CHECK(ISC_R_NOMEMORY);
imp->inst = NULL;
INIT_LINK(imp, link);
......@@ -282,8 +280,6 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname,
imp->register_func = register_func;
imp->destroy_func = destroy_func;
imp->name = isc_mem_strdup(mctx, instname);
if (imp->name == NULL)
CHECK(ISC_R_NOMEMORY);
imp->inst = NULL;
INIT_LINK(imp, link);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment