Exit if allocation fails.
if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
if (iihash)
DEB_syslog(LOG_INFO, "Malloc-txt: %s", UNKN);
- return (iihash)?strdup(UNKN):UNKN;
+ return (iihash) ? xstrdup(UNKN) : UNKN;
}
pt = answer + sizeof(HEADER);
if ((val = split_txtrec(ctl, ipinfo_lookup(lookup_key)))) {
DEB_syslog(LOG_INFO, "Looked up: %s", key);
if (iihash)
- if ((item.key = strdup(key))) {
+ if ((item.key = xstrdup(key))) {
item.data = items;
hsearch(item, ENTER);
DEB_syslog(LOG_INFO, "Insert into hash: %s", key);
longipstr (host, &hostip, ctl->af);
r = findip (ctl, &hostip);
if (r)
- r->name = strdup (name);
+ r->name = xstrdup (name);
else
error (0, 0, "dns_ack: Couldn't find host %s", host);
}
if (name == NULL) {
error(EXIT_FAILURE, errno, "memory allocation failure");
}
- name->name = strdup(item);
+ name->name = xstrdup(item);
name->next = names;
names = name;
}
error(EXIT_FAILURE, errno, "cannot allocate %zu bytes", size);
return ret;
}
+
+extern char *xstrdup(const char *str)
+{
+ char *ret;
+
+ if (!str)
+ return NULL;
+ ret = strdup(str);
+ if (!ret)
+ error(EXIT_FAILURE, errno, "cannot duplicate string: %s", str);
+ return ret;
+}
}
extern void *xmalloc(const size_t size);
+extern char *xstrdup(const char *str);