if (authenv) {
VIR_DEBUG("Using path from env '%s'", authenv);
- if (!(*path = strdup(authenv)))
- goto no_memory;
+ if (VIR_STRDUP(*path, authenv) < 0)
+ goto cleanup;
return 0;
}
conn->uri->params[i].value) {
VIR_DEBUG("Using path from URI '%s'",
conn->uri->params[i].value);
- if (!(*path = strdup(conn->uri->params[i].value)))
- goto no_memory;
+ if (VIR_STRDUP(*path, conn->uri->params[i].value) < 0)
+ goto cleanup;
return 0;
}
}
VIR_FREE(*path);
- if (!(*path = strdup(SYSCONFDIR "/libvirt/auth.conf")))
- goto no_memory;
+ if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0)
+ goto cleanup;
VIR_DEBUG("Checking for readability of '%s'", *path);
if (access(*path, R_OK) == 0)
&tmp) < 0)
goto cleanup;
- if (tmp &&
- !(*value = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(*value, tmp) < 0)
goto cleanup;
- }
ret = 0;
goto error;
}
- if (!(auth->path = strdup(path))) {
- virReportOOMError();
+ if (VIR_STRDUP(auth->path, path) < 0)
goto error;
- }
if (!(auth->keyfile = virKeyFileNew()))
goto error;
goto error;
}
- if (!(auth->path = strdup(path))) {
- virReportOOMError();
+ if (VIR_STRDUP(auth->path, path) < 0)
goto error;
- }
if (!(auth->keyfile = virKeyFileNew()))
goto error;
#include "count-one-bits.h"
#include "virstring.h"
+#define VIR_FROM_THIS VIR_FROM_NONE
+
struct _virBitmap {
size_t max_bit;
size_t map_len;
return NULL;
cur = virBitmapNextSetBit(bitmap, -1);
- if (cur < 0)
- return strdup("");
+ if (cur < 0) {
+ char *ret;
+ ignore_value(VIR_STRDUP(ret, ""));
+ return ret;
+ }
start = prev = cur;
while (prev >= 0) {
return;
VIR_FREE(cmd->pidfile);
- if (!(cmd->pidfile = strdup(pidfile))) {
+ if (VIR_STRDUP_QUIET(cmd->pidfile, pidfile) < 0)
cmd->has_error = ENOMEM;
- }
}
#if defined(WITH_SECDRIVER_SELINUX)
VIR_FREE(cmd->seLinuxLabel);
- if (label && !(cmd->seLinuxLabel = strdup(label)))
+ if (VIR_STRDUP_QUIET(cmd->seLinuxLabel, label) < 0)
cmd->has_error = ENOMEM;
#endif
return;
#if defined(WITH_SECDRIVER_APPARMOR)
VIR_FREE(cmd->appArmorProfile);
- if (profile && !(cmd->appArmorProfile = strdup(profile)))
+ if (VIR_STRDUP_QUIET(cmd->appArmorProfile, profile) < 0)
cmd->has_error = ENOMEM;
#endif
return;
if (!cmd || cmd->has_error)
return;
- if (!(env = strdup(str))) {
+ if (VIR_STRDUP_QUIET(env, str) < 0) {
cmd->has_error = ENOMEM;
return;
}
if (!cmd || cmd->has_error)
return;
- if (!(arg = strdup(val))) {
+ if (VIR_STRDUP_QUIET(arg, val) < 0) {
cmd->has_error = ENOMEM;
return;
}
}
cmd->args[cmd->nargs] = virBufferContentAndReset(buf);
- if (!cmd->args[cmd->nargs])
- cmd->args[cmd->nargs] = strdup("");
if (!cmd->args[cmd->nargs]) {
- cmd->has_error = ENOMEM;
- return;
+ if (VIR_STRDUP_QUIET(cmd->args[cmd->nargs], "") < 0) {
+ cmd->has_error = ENOMEM;
+ return;
+ }
}
cmd->nargs++;
}
narg = 0;
while (vals[narg] != NULL) {
- char *arg = strdup(vals[narg++]);
- if (!arg) {
+ char *arg;
+
+ if (VIR_STRDUP_QUIET(arg, vals[narg++]) < 0) {
cmd->has_error = ENOMEM;
return;
}
char *arg = va_arg(list, char *);
if (!arg)
break;
- arg = strdup(arg);
- if (!arg) {
+ if (VIR_STRDUP_QUIET(arg, arg) < 0) {
cmd->has_error = ENOMEM;
va_end(list);
return;
cmd->has_error = -1;
VIR_DEBUG("cannot set directory twice");
} else {
- cmd->pwd = strdup(pwd);
- if (!cmd->pwd)
+ if (VIR_STRDUP_QUIET(cmd->pwd, pwd) < 0)
cmd->has_error = ENOMEM;
}
}
return;
}
- cmd->inbuf = strdup(inbuf);
- if (!cmd->inbuf)
+ if (VIR_STRDUP_QUIET(cmd->inbuf, inbuf) < 0)
cmd->has_error = ENOMEM;
}
#include <config.h>
#include <string.h>
-
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "virlog.h"
#include "viralloc.h"
#include "virfile.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_CONF
virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
return NULL;
}
- ret = strndup(base, ctxt->cur - base);
- if (ret == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
- }
NEXT;
} else if ((ctxt->cur + 6 < ctxt->end) &&
(STRPREFIX(ctxt->cur, "\"\"\""))) {
virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
return NULL;
}
- ret = strndup(base, ctxt->cur - base);
- if (ret == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
- }
ctxt->cur += 3;
} else if (CUR == '"') {
NEXT;
virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
return NULL;
}
- ret = strndup(base, ctxt->cur - base);
- if (ret == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
- }
NEXT;
}
return ret;
((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) &&
((CUR == ':') || (CUR == '.') || (CUR == '-')))))
NEXT;
- ret = strndup(base, ctxt->cur - base);
- if (ret == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
return NULL;
- }
return ret;
}
NEXT;
base = ctxt->cur;
while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
- comm = strndup(base, ctxt->cur - base);
- if (comm == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0)
return -1;
- }
virConfAddEntry(ctxt->conf, NULL, NULL, comm);
return 0;
}
NEXT;
base = ctxt->cur;
while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
- comm = strndup(base, ctxt->cur - base);
- if (comm == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) {
VIR_FREE(name);
virConfFreeValue(value);
return -1;
return -1;
}
cur->comment = NULL;
- if (!(cur->name = strdup(setting))) {
- virReportOOMError();
+ if (VIR_STRDUP(cur->name, setting) < 0) {
virConfFreeValue(value);
VIR_FREE(cur);
return -1;
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
goto alloc_error;
- if (!(addnhostsfile->hosts[idx].ip = strdup(ipstr)))
- goto alloc_error;
+ if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0)
+ goto error;
addnhostsfile->hosts[idx].nhostnames = 0;
addnhostsfile->nhosts++;
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
goto alloc_error;
- if (!(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames]
- = strdup(name)))
- goto alloc_error;
+ if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames],
+ name) < 0)
+ goto error;
VIR_FREE(ipstr);
alloc_error:
virReportOOMError();
+ error:
VIR_FREE(ipstr);
return -1;
}
return NULL;
}
- if (!(ctx->config_dir = strdup(config_dir))) {
- virReportOOMError();
+ if (VIR_STRDUP(ctx->config_dir, config_dir) < 0)
goto error;
- }
if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir)))
goto error;
return NULL;
if (!(caps = virObjectNew(dnsmasqCapsClass)))
return NULL;
- if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
+ if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) {
+ virReportOOMError();
goto error;
- if (!(caps->binaryPath = strdup(binaryPath ? binaryPath : DNSMASQ)))
+ }
+ if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0)
goto error;
return caps;
error:
- virReportOOMError();
virObjectUnref(caps);
return NULL;
}
#include "virstring.h"
#include "virutil.h"
+#define VIR_FROM_THIS VIR_FROM_NONE
+
#if HAVE_FIREWALLD
static char *firewall_cmd_path = NULL;
static int
ebtRulesAppend(ebtRules *rules,
char *rule,
- const char **argv,
+ char **argv,
int command_idx)
{
if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
if (VIR_ALLOC(rules) < 0)
return NULL;
- if (!(rules->table = strdup(table)))
+ if (VIR_STRDUP(rules->table, table) < 0)
goto error;
- if (!(rules->chain = strdup(chain)))
+ if (VIR_STRDUP(rules->chain, chain) < 0)
goto error;
rules->rules = NULL;
{
va_list args;
int retval = ENOMEM;
- const char **argv;
+ char **argv;
char *rule = NULL;
const char *s;
int n, command_idx;
#if HAVE_FIREWALLD
if (firewall_cmd_path) {
- if (!(argv[n++] = strdup(firewall_cmd_path)))
+ if (VIR_STRDUP(argv[n++], firewall_cmd_path) < 0)
goto error;
- if (!(argv[n++] = strdup("--direct")))
+ if (VIR_STRDUP(argv[n++], "--direct") < 0)
goto error;
- if (!(argv[n++] = strdup("--passthrough")))
+ if (VIR_STRDUP(argv[n++], "--passthrough") < 0)
goto error;
- if (!(argv[n++] = strdup("eb")))
+ if (VIR_STRDUP(argv[n++], "eb") < 0)
goto error;
} else
#endif
- if (!(argv[n++] = strdup(EBTABLES_PATH)))
+ if (VIR_STRDUP(argv[n++], EBTABLES_PATH) < 0)
goto error;
command_idx = n;
if (action == ADD || action == REMOVE) {
- if (!(argv[n++] = strdup("--insert")))
+ if (VIR_STRDUP(argv[n++], "--insert") < 0)
goto error;
- if (!(argv[n++] = strdup(rules->chain)))
+ if (VIR_STRDUP(argv[n++], rules->chain) < 0)
goto error;
}
- if (!(argv[n++] = strdup(arg)))
+ if (VIR_STRDUP(argv[n++], arg) < 0)
goto error;
va_start(args, arg);
while ((s = va_arg(args, const char *))) {
- if (!(argv[n++] = strdup(s))) {
+ if (VIR_STRDUP(argv[n++], s) < 0) {
va_end(args);
goto error;
}
va_end(args);
- if (!(rule = virArgvToString(&argv[command_idx])))
+ if (!(rule = virArgvToString((const char **) &argv[command_idx])))
goto error;
if (action == REMOVE) {
VIR_FREE(argv[command_idx]);
- if (!(argv[command_idx] = strdup("--delete")))
+ if (VIR_STRDUP(argv[command_idx], "--delete") < 0)
goto error;
}
- if (virRun(argv, NULL) < 0) {
+ if (virRun((const char **)argv, NULL) < 0) {
retval = errno;
goto error;
}
typedef struct
{
char *rule;
- const char **argv;
+ char **argv;
int command_idx;
} ebtRule;
err->code = VIR_ERR_INTERNAL_ERROR;
err->domain = VIR_FROM_NONE;
err->level = VIR_ERR_ERROR;
- err->message = strdup(_("An error occurred, but the cause is unknown"));
+ ignore_value(VIR_STRDUP_QUIET(err->message,
+ _("An error occurred, but the cause is unknown")));
}
to->code = from->code;
to->domain = from->domain;
to->level = from->level;
- if (from->message && !(to->message = strdup(from->message)))
+ if (VIR_STRDUP_QUIET(to->message, from->message) < 0)
ret = -1;
- if (from->str1 && !(to->str1 = strdup(from->str1)))
+ if (VIR_STRDUP_QUIET(to->str1, from->str1) < 0)
ret = -1;
- if (from->str2 && !(to->str2 = strdup(from->str2)))
+ if (VIR_STRDUP_QUIET(to->str2, from->str2) < 0)
ret = -1;
- if (from->str3 && !(to->str3 = strdup(from->str3)))
+ if (VIR_STRDUP_QUIET(to->str3, from->str3) < 0)
ret = -1;
to->int1 = from->int1;
to->int2 = from->int2;
* formats the message; drop message on OOM situations
*/
if (fmt == NULL) {
- str = strdup(_("No error message provided"));
+ ignore_value(VIR_STRDUP_QUIET(str, _("No error message provided")));
} else {
va_list ap;
va_start(ap, fmt);
to->code = code;
to->message = str;
to->level = level;
- if (str1 != NULL)
- to->str1 = strdup(str1);
- if (str2 != NULL)
- to->str2 = strdup(str2);
- if (str3 != NULL)
- to->str3 = strdup(str3);
+ ignore_value(VIR_STRDUP_QUIET(to->str1, str1));
+ ignore_value(VIR_STRDUP_QUIET(to->str2, str2));
+ ignore_value(VIR_STRDUP_QUIET(to->str3, str3));
to->int1 = int1;
to->int2 = int2;
while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
if (STREQ(mb.mnt_type, type)) {
- ret = strdup(mb.mnt_dir);
+ ignore_value(VIR_STRDUP_QUIET(ret, mb.mnt_dir));
goto cleanup;
}
}
if (lstat(linkpath, &st) < 0)
return -1;
- if (!S_ISLNK(st.st_mode)) {
- if (!(*resultpath = strdup(linkpath)))
- return -1;
- return 0;
- }
+ if (!S_ISLNK(st.st_mode))
+ return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0;
}
*resultpath = canonicalize_file_name(linkpath);
* copy of that path, after validating that it is executable
*/
if (IS_ABSOLUTE_FILE_NAME(file)) {
+ char *ret = NULL;
if (virFileIsExecutable(file))
- return strdup(file);
- else
- return NULL;
+ ignore_value(VIR_STRDUP_QUIET(ret, file));
+ return ret;
}
/* If we are passed an anchored path (containing a /), then there
/* copy PATH env so we can tweak it */
path = getenv("PATH");
- if (path == NULL || (path = strdup(path)) == NULL)
+ if (VIR_STRDUP_QUIET(path, path) <= 0)
return NULL;
/* for each path segment, append the file to search for and test for
int ret = -1;
char *tmp;
- if ((tmp = strdup(path)) == NULL)
+ if (VIR_STRDUP(tmp, path) < 0) {
+ errno = ENOMEM;
goto cleanup;
+ }
ret = virFileMakePathHelper(tmp, mode);
char *buf;
if (path[0] == '/') {
- if (!(*abspath = strdup(path)))
+ if (VIR_STRDUP(*abspath, path) < 0)
return -1;
} else {
buf = getcwd(NULL, 0);
char *cleanpath;
int idx = 0;
- cleanpath = strdup(path);
- if (!cleanpath) {
- virReportOOMError();
+ if (VIR_STRDUP(cleanpath, path) < 0)
return NULL;
- }
/* Need to sanitize:
* // -> //
#include "virlog.h"
#include "virhashcode.h"
#include "virrandom.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE
static void *virHashStrCopy(const void *name)
{
- return strdup(name);
+ char *ret;
+ ignore_value(VIR_STRDUP(ret, name));
+ return ret;
}
static void virHashStrFree(void *name)
#include "virobject.h"
#include "virthread.h"
#include "virutil.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_IDENTITY
_("Unable to lookup SELinux process context"));
goto cleanup;
}
- seccontext = strdup(con);
- freecon(con);
- if (!seccontext) {
- virReportOOMError();
+ if (VIR_STRDUP(seccontext, con) < 0) {
+ freecon(con);
goto cleanup;
}
+ freecon(con);
#endif
if (!(ret = virIdentityNew()))
goto cleanup;
}
- if (!(ident->attrs[attr] = strdup(value))) {
- virReportOOMError();
+ if (VIR_STRDUP(ident->attrs[attr], value) < 0)
goto cleanup;
- }
ret = 0;
return -1;
}
} else {
- if (!(path = strdup(VIR_INITCTL_FIFO))) {
- virReportOOMError();
+ if (VIR_STRDUP(path, VIR_INITCTL_FIFO) < 0)
return -1;
- }
}
if ((fd = open(path, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) < 0) {
if (VIR_ALLOC(rules) < 0)
return NULL;
- if (!(rules->table = strdup(table)))
+ if (VIR_STRDUP(rules->table, table) < 0)
goto error;
- if (!(rules->chain = strdup(chain)))
+ if (VIR_STRDUP(rules->chain, chain) < 0)
goto error;
return rules;
return NULL;
val->type = VIR_JSON_TYPE_STRING;
- if (!(val->data.string = strdup(data))) {
+ if (VIR_STRDUP(val->data.string, data) < 0) {
VIR_FREE(val);
return NULL;
}
return NULL;
val->type = VIR_JSON_TYPE_STRING;
- if (!(val->data.string = strndup(data, length))) {
+ if (VIR_STRNDUP(val->data.string, data, length) < 0) {
VIR_FREE(val);
return NULL;
}
return NULL;
val->type = VIR_JSON_TYPE_NUMBER;
- if (!(val->data.number = strdup(data))) {
+ if (VIR_STRDUP(val->data.number, data) < 0) {
VIR_FREE(val);
return NULL;
}
if (virJSONValueObjectHasKey(object, key))
return -1;
- if (!(newkey = strdup(key)))
+ if (VIR_STRDUP(newkey, key) < 0)
return -1;
if (VIR_REALLOC_N(object->data.object.pairs,
yajl_size_t l)
{
virJSONParserPtr parser = ctx;
- char *str = strndup(s, l);
+ char *str;
virJSONValuePtr value;
- if (!str)
+ if (VIR_STRNDUP(str, s, l) < 0)
return -1;
value = virJSONValueNewNumber(str);
VIR_FREE(str);
state = &parser->state[parser->nstate-1];
if (state->key)
return 0;
- state->key = strndup((const char *)stringVal, stringLen);
- if (!state->key)
+ if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0)
return 0;
return 1;
}
goto cleanup;
}
- if (!(ret = strdup((const char *)str)))
- virReportOOMError();
+ ignore_value(VIR_STRDUP(ret, (const char *)str));
cleanup:
yajl_gen_free(g);
#include "virhash.h"
#include "virkeyfile.h"
#include "virerror.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_CONF
return -1;
}
- if (!(ctxt->groupname = strndup(name, ctxt->cur - name))) {
- virReportOOMError();
+ if (VIR_STRNDUP(ctxt->groupname, name, ctxt->cur - name) < 0)
return -1;
- }
NEXT;
return -1;
}
- if (!(key = strndup(keystart, ctxt->cur - keystart))) {
- virReportOOMError();
+ if (VIR_STRNDUP(key, keystart, ctxt->cur - keystart) < 0)
return -1;
- }
NEXT;
valuestart = ctxt->cur;
len = ctxt->cur - valuestart;
if (IS_EOF && !IS_EOL(CUR))
len++;
- if (!(value = strndup(valuestart, len))) {
- virReportOOMError();
+ if (VIR_STRNDUP(value, valuestart, len) < 0)
goto cleanup;
- }
if (virHashAddEntry(ctxt->group, key, value) < 0) {
VIR_FREE(value);
return NULL;
}
} else {
- if (!(ret = strdup(resname))) {
- virReportOOMError();
+ if (VIR_STRDUP(ret, resname) < 0)
return NULL;
- }
}
return ret;
res->fd = -1;
res->flags = flags;
- if (!(res->name = strdup(resname)))
- goto no_memory;
+ if (VIR_STRDUP(res->name, resname) < 0)
+ goto error;
if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname)))
goto no_memory;
return NULL;
}
- if (directory &&
- !(lockspace->dir = strdup(directory)))
- goto no_memory;
+ if (VIR_STRDUP(lockspace->dir, directory) < 0)
+ goto error;
if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE,
virLockSpaceResourceDataFree)))
return lockspace;
-no_memory:
- virReportOOMError();
error:
virLockSpaceFree(lockspace);
return NULL;
if (virJSONValueObjectHasKey(object, "directory")) {
const char *dir = virJSONValueObjectGetString(object, "directory");
- if (!(lockspace->dir = strdup(dir))) {
- virReportOOMError();
+ if (VIR_STRDUP(lockspace->dir, dir) < 0)
goto error;
- }
}
if (!(resources = virJSONValueObjectGet(object, "resources"))) {
virLockSpaceResourceFree(res);
goto error;
}
- if (!(res->name = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(res->name, tmp) < 0) {
virLockSpaceResourceFree(res);
goto error;
}
virLockSpaceResourceFree(res);
goto error;
}
- if (!(res->path = strdup(tmp))) {
- virReportOOMError();
+ if (VIR_STRDUP(res->path, tmp) < 0) {
virLockSpaceResourceFree(res);
goto error;
}
}
}
- mdup = strdup(match);
- if (mdup == NULL) {
+ if (VIR_STRDUP_QUIET(mdup, match) < 0) {
i = -1;
goto cleanup;
}
virLogNbFilters++;
cleanup:
virLogUnlock();
+ if (i < 0)
+ virReportOOMError();
return i;
}
return -1;
if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) {
- if (name == NULL)
+ if (!name) {
+ virReportOOMError();
return -1;
- ndup = strdup(name);
- if (ndup == NULL)
+ }
+ if (VIR_STRDUP(ndup, name) < 0)
return -1;
}
* ident needs to be kept around on Solaris
*/
VIR_FREE(current_ident);
- current_ident = strdup(ident);
- if (current_ident == NULL)
+ if (VIR_STRDUP(current_ident, ident) < 0)
return -1;
openlog(current_ident, 0, 0);
if (str == cur)
goto cleanup;
#if HAVE_SYSLOG_H
- name = strndup(str, cur - str);
- if (name == NULL)
+ if (VIR_STRNDUP(name, str, cur - str) < 0)
goto cleanup;
if (virLogAddOutputToSyslog(prio, name) == 0)
count++;
cur++;
if (str == cur)
goto cleanup;
- name = strndup(str, cur - str);
- if (name == NULL)
+ if (VIR_STRNDUP(name, str, cur - str) < 0)
goto cleanup;
if (virFileAbsPath(name, &abspath) < 0) {
VIR_FREE(name);
cur++;
if (str == cur)
goto cleanup;
- name = strndup(str, cur - str);
- if (name == NULL)
+ if (VIR_STRNDUP(name, str, cur - str) < 0)
goto cleanup;
if (virLogDefineFilter(name, prio, flags) >= 0)
count++;
#include "virmacaddr.h"
#include "virerror.h"
#include "virthread.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NET
if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
if (VIR_ALLOC(calld) < 0)
goto memory_error;
- if ((calld->cr_ifname = strdup(ifname)) == NULL)
- goto memory_error;
+ if (VIR_STRDUP(calld->cr_ifname, ifname) < 0)
+ goto error;
if (VIR_ALLOC(calld->virtPortProfile) < 0)
goto memory_error;
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
virMacAddrSet(&calld->macaddress, macaddress);
- if ((calld->linkdev = strdup(linkdev)) == NULL)
- goto memory_error;
+ if (VIR_STRDUP(calld->linkdev, linkdev) < 0)
+ goto error;
memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
calld->vmOp = vmOp;
VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
goto disassociate_exit;
}
- if (!(*res_ifname = strdup(cr_ifname))) {
+ if (VIR_STRDUP(*res_ifname, cr_ifname) < 0) {
VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
- virReportOOMError();
goto disassociate_exit;
}
} else {
- if (!(*res_ifname = strdup(cr_ifname))) {
- virReportOOMError();
+ if (VIR_STRDUP(*res_ifname, cr_ifname) < 0)
goto disassociate_exit;
- }
rc = 0;
}
return -1;
}
- *ifname = strdup(ifr.ifr_name);
- if (*ifname == NULL) {
- virReportOOMError();
- return -1;
- }
- return 0;
+ return VIR_STRDUP(*ifname, ifr.ifr_name) < 0 ? -1 : 0;
#else
return -1;
#endif
/* In case we are looping more than once, set other
* TAPs to have the same name */
VIR_FREE(*ifname);
- if (ifr.ifr_name && VIR_STRDUP(*ifname, ifr.ifr_name) < 0)
+ if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0)
goto cleanup;
}
goto cleanup;
}
} else {
- physfndev = strdup(ifname);
- if (!physfndev) {
- virReportOOMError();
+ if (VIR_STRDUP(physfndev, ifname) < 0) {
rc = -1;
goto cleanup;
}
#include "viratomic.h"
#include "virerror.h"
#include "virlog.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE
virClassPtr parent;
unsigned int magic;
- const char *name;
+ char *name;
size_t objectSize;
virObjectDisposeCallback dispose;
return NULL;
}
- if (VIR_ALLOC(klass) < 0)
- goto no_memory;
+ if (VIR_ALLOC(klass) < 0) {
+ virReportOOMError();
+ goto error;
+ }
klass->parent = parent;
- if (!(klass->name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(klass->name, name) < 0)
+ goto error;
klass->magic = virAtomicIntInc(&magicCounter);
klass->objectSize = objectSize;
klass->dispose = dispose;
return klass;
-no_memory:
+error:
VIR_FREE(klass);
- virReportOOMError();
return NULL;
}
goto cleanup;
}
/* drvdir = "/sys/bus/pci/drivers/${drivername}" */
- if (!(driver = strdup(last_component(drvdir)))) {
- virReportOOMError();
+ if (VIR_STRDUP(driver, last_component(drvdir)) < 0)
goto cleanup;
- }
if (!dev->unbind_from_stub)
goto remove_slot;
dev = virPCIDeviceNew(domain, bus, slot, function);
if (dev != NULL) {
- if ((*pciConfigAddr = strdup(dev->name)) == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0)
goto cleanup;
- }
ret = 0;
}
continue;
/* Assume a single directory entry */
- *netname = strdup(entry->d_name);
- if (!*netname)
- virReportOOMError();
- else
+ if (VIR_STRDUP(*netname, entry->d_name) > 0)
ret = 0;
break;
}
if (entry->d_name[0] == '.')
continue;
- if (!(name = strdup(entry->d_name))) {
- virReportOOMError();
- goto cleanup;
- }
+ ignore_value(VIR_STRDUP(name, entry->d_name));
+ break;
}
cleanup:
if (ret == NULL)
return ret;
ret->kind = SEXPR_VALUE;
- if (len > 0) {
- ret->u.value = strndup(str, len);
- } else {
- ret->u.value = strdup(str);
- }
- if (ret->u.value == NULL) {
+ if (VIR_STRNDUP(ret->u.value, str, len > 0 ? len : strlen(str)) < 0)
VIR_FREE(ret);
- return NULL;
- }
return ret;
}
ptr++;
}
- ret->u.value = strndup(start, ptr - start);
- if (ret->u.value == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0)
goto error;
- }
if (*ptr == '\'')
ptr++;
ptr++;
}
- ret->u.value = strndup(start, ptr - start);
- if (ret->u.value == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0)
goto error;
- }
}
ret->kind = SEXPR_VALUE;
if ((node == NULL) || (sexpr == NULL))
return NULL;
- buffer = strdup(node);
-
- if (buffer == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(buffer, node) < 0)
return NULL;
- }
ptr = buffer;
token = strsep(&ptr, "/");
{
const char *val = sexpr_node(sexpr, node);
- if (val && *val) {
- *dst = strdup(val);
- if (!(*dst))
- return -1;
- } else {
- *dst = NULL;
- }
+ if (val && *val)
+ return VIR_STRDUP(*dst, val) < 0 ? -1 : 0;
+
+ *dst = NULL;
return 0;
}
separator ? separator : ":") < 0)
goto no_memory;
} else {
- if (!(addrstr = strdup("127.0.0.1")))
- goto no_memory;
+ if (VIR_STRDUP(addrstr, "127.0.0.1") < 0)
+ goto error;
}
return addrstr;
}
if (virAsprintf(&addrstr, "%s%s%s", host, separator, port) == -1)
goto no_memory;
} else {
- if (!(addrstr = strdup(host)))
- goto no_memory;
+ if (VIR_STRDUP(addrstr, host) < 0)
+ goto error;
}
return addrstr;
no_memory:
virReportOOMError();
+error:
return NULL;
}
return BACKING_STORE_OK;
}
- *res = strndup((const char*)buf + 4+4, COW_FILENAME_MAXLEN);
- if (*res == NULL) {
- virReportOOMError();
+ if (VIR_STRNDUP(*res, (const char*)buf + 4 + 4, COW_FILENAME_MAXLEN) < 0)
return BACKING_STORE_ERROR;
- }
return BACKING_STORE_OK;
}
goto cleanup;
}
*end = '\0';
- *res = strdup(start);
- if (*res == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(*res, start) < 0)
goto cleanup;
- }
ret = BACKING_STORE_OK;
meta->backingStoreIsFile = false;
if (backing != NULL) {
- meta->backingStore = strdup(backing);
- if (meta->backingStore == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(meta->backingStore, backing) < 0) {
VIR_FREE(backing);
goto cleanup;
}
struct statfs sb;
int statfs_ret;
- if ((dirpath = strdup(path)) == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(dirpath, path) < 0)
return -1;
- }
do {
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
goto no_memory;
- if (!(tokens[ntokens] = strndup(remainder, len)))
- goto no_memory;
+ if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0)
+ goto error;
ntokens++;
remainder = tmp + delimlen;
tmp = strstr(remainder, delim);
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
goto no_memory;
- if (!(tokens[ntokens] = strdup(remainder)))
- goto no_memory;
+ if (VIR_STRDUP(tokens[ntokens], remainder) < 0)
+ goto error;
ntokens++;
}
no_memory:
virReportOOMError();
+error:
for (i = 0; i < ntokens; i++)
VIR_FREE(tokens[i]);
VIR_FREE(tokens);
return NULL;
}
ret = virBufferContentAndReset(&buf);
- if (!ret) {
- if (!(ret = strdup(""))) {
- virReportOOMError();
- return NULL;
- }
- }
+ if (!ret)
+ ignore_value(VIR_STRDUP(ret, ""));
return ret;
}
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol &&
- ((ret->system_family = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
+ return -1;
if ((cur = strstr(base, "model")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol && ((ret->system_serial = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "machine")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol && ((ret->system_version = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
+ return -1;
}
return 0;
-
-no_memory:
- return -1;
}
static int
cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
- goto no_memory;
+ return -1;
}
processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur);
- if (eol &&
- ((processor->processor_socket_destination = strndup
- (cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_socket_destination,
+ cur, eol - cur) < 0)
+ return -1;
if ((cur = strstr(base, "cpu")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol &&
- ((processor->processor_type = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_type,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "revision")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol &&
- ((processor->processor_version = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_version,
+ cur, eol - cur) < 0)
+ return -1;
}
base = cur;
}
return 0;
-
-no_memory:
- return -1;
}
/* virSysinfoRead for PowerPC
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol &&
- ((ret->system_family = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
+ return -1;
if ((cur = strstr(base, "model")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol && ((ret->system_serial = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "machine")) != NULL) {
cur = strchr(cur, ':') + 1;
eol = strchr(cur, '\n');
virSkipSpaces(&cur);
- if (eol && ((ret->system_version = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
+ return -1;
}
return 0;
-
-no_memory:
- return -1;
}
static int
eol = strchr(base, '\n');
cur = strchr(base, ':') + 1;
virSkipSpaces(&cur);
- if (eol &&
- ((processor_type = strndup(cur, eol - cur))
- == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0)
+ goto error;
base = cur;
while ((tmp_base = strstr(base, "processor")) != NULL) {
cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
- goto no_memory;
+ virReportOOMError();
+ goto error;
}
processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur);
if (eol &&
- ((processor->processor_socket_destination = strndup
- (cur, eol - cur)) == NULL))
- goto no_memory;
+ VIR_STRNDUP(processor->processor_socket_destination,
+ cur, eol - cur) < 0)
+ goto error;
if (processor_type &&
- !(processor->processor_type = strdup(processor_type)))
- goto no_memory;
+ VIR_STRDUP(processor->processor_type, processor_type) < 0)
+ goto error;
base = cur;
}
VIR_FREE(processor_type);
return 0;
-no_memory:
+error:
VIR_FREE(processor_type);
return -1;
}
start += 1;
end = strchrnul(start, delim2);
virSkipSpaces(&start);
- if (!((*value) = strndup(start, end - start))) {
- virReportOOMError();
- goto error;
- }
+ if (VIR_STRNDUP(*value, start, end - start) < 0)
+ return NULL;
virTrimSpaces(*value, NULL);
return end;
}
-
-error:
return NULL;
}
goto cleanup;
}
processor = &ret->processor[ret->nprocessor - 1];
- processor->processor_manufacturer = strdup(manufacturer);
+ if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0)
+ goto cleanup;
if (!virSysinfoParseDelimited(procline, "version",
&processor->processor_version,
'=', ',') ||
if ((cur = strstr(base, "Vendor: ")) != NULL) {
cur += 8;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->bios_vendor = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->bios_vendor, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->bios_version = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->bios_version, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Release Date: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->bios_date = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->bios_date, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "BIOS Revision: ")) != NULL) {
cur += 15;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->bios_release = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->bios_release, cur, eol - cur) < 0)
+ return -1;
}
return 0;
-
-no_memory:
- return -1;
}
static int
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
- if ((eol) &&
- ((ret->system_manufacturer = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_manufacturer, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Product Name: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_product = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_product, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_version = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_serial = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "UUID: ")) != NULL) {
cur += 6;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_uuid = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_uuid, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "SKU Number: ")) != NULL) {
cur += 12;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_sku = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_sku, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Family: ")) != NULL) {
cur += 8;
eol = strchr(cur, '\n');
- if ((eol) && ((ret->system_family = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
+ return -1;
}
return 0;
-
-no_memory:
- return -1;
}
static int
base = tmp_base;
eol = NULL;
- if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
- goto no_memory;
- }
+ if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
+ return -1;
processor = &ret->processor[ret->nprocessor - 1];
if ((cur = strstr(base, "Socket Designation: ")) != NULL) {
cur += 20;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_socket_destination
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_socket_destination,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Type: ")) != NULL) {
cur += 6;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_type = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Family: ")) != NULL) {
cur += 8;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_family = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_family, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_manufacturer
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_manufacturer,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Signature: ")) != NULL) {
cur += 11;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_signature
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_signature,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_version = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_version,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "External Clock: ")) != NULL) {
cur += 16;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_external_clock
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_external_clock,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Max Speed: ")) != NULL) {
cur += 11;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_max_speed
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_max_speed,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Status: ")) != NULL) {
cur += 8;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_status = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_status, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_serial_number
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_serial_number,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Part Number: ")) != NULL) {
cur += 13;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((processor->processor_part_number
- = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(processor->processor_part_number,
+ cur, eol - cur) < 0)
+ return -1;
}
base += strlen("Processor Information");
}
return 0;
-
-no_memory:
- return -1;
}
static int
base = tmp_base;
eol = NULL;
- if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) {
- goto no_memory;
- }
+ if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0)
+ return -1;
memory = &ret->memory[ret->nmemory - 1];
if ((cur = strstr(base, "Size: ")) != NULL) {
goto next;
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_size = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_size, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Form Factor: ")) != NULL) {
cur += 13;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_form_factor = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_form_factor,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Locator: ")) != NULL) {
cur += 9;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_locator = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_locator,cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Bank Locator: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_bank_locator = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_bank_locator,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Type: ")) != NULL) {
cur += 6;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_type = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_type, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Type Detail: ")) != NULL) {
cur += 13;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_type_detail = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_type_detail, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Speed: ")) != NULL) {
cur += 7;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_speed = strndup(cur, eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_speed, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_manufacturer = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_manufacturer, cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_serial_number = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_serial_number,
+ cur, eol - cur) < 0)
+ return -1;
}
if ((cur = strstr(base, "Part Number: ")) != NULL) {
cur += 13;
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
- if ((eol) &&
- ((memory->memory_part_number = strndup(cur,
- eol - cur)) == NULL))
- goto no_memory;
+ if (eol && VIR_STRNDUP(memory->memory_part_number, cur, eol - cur) < 0)
+ return -1;
}
next:
}
return 0;
-
-no_memory:
- return -1;
}
virSysinfoDefPtr
break;
case VIR_TYPED_PARAM_STRING:
param->value.s = va_arg(ap, char *);
- if (!param->value.s)
- param->value.s = strdup("");
- if (!param->value.s) {
- virReportOOMError();
+ if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
goto cleanup;
- }
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
}
break;
case VIR_TYPED_PARAM_STRING:
- if (!(param->value.s = strdup(val))) {
- virReportOOMError();
+ if (VIR_STRDUP(param->value.s, val) < 0)
goto cleanup;
- }
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
}
*maxparams = max;
- if (value && !(str = strdup(value))) {
- virReportOOMError();
+ if (VIR_STRDUP(str, value) < 0)
goto error;
- }
if (virTypedParameterAssign(*params + n, name,
VIR_TYPED_PARAM_STRING, str) < 0) {
char *pname = NULL;
char *pvalue = NULL;
- if (!(pname = strdup(name)))
- goto no_memory;
- if (!(pvalue = strdup(value)))
- goto no_memory;
+ if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0)
+ goto error;
- if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
- goto no_memory;
+ if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) {
+ virReportOOMError();
+ goto error;
+ }
uri->params[uri->paramsCount].name = pname;
uri->params[uri->paramsCount].value = pvalue;
return 0;
-no_memory:
+error:
VIR_FREE(pname);
VIR_FREE(pvalue);
- virReportOOMError();
return -1;
}
return NULL;
}
- if (VIR_ALLOC(ret) < 0)
- goto no_memory;
+ if (VIR_ALLOC(ret) < 0) {
+ virReportOOMError();
+ goto error;
+ }
- if (xmluri->scheme &&
- !(ret->scheme = strdup(xmluri->scheme)))
- goto no_memory;
- if (xmluri->server &&
- !(ret->server = strdup(xmluri->server)))
- goto no_memory;
+ if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0)
+ goto error;
+ if (VIR_STRDUP(ret->server, xmluri->server) < 0)
+ goto error;
ret->port = xmluri->port;
- if (xmluri->path &&
- !(ret->path = strdup(xmluri->path)))
- goto no_memory;
+ if (VIR_STRDUP(ret->path, xmluri->path) < 0)
+ goto error;
#ifdef HAVE_XMLURI_QUERY_RAW
- if (xmluri->query_raw &&
- !(ret->query = strdup(xmluri->query_raw)))
- goto no_memory;
+ if (VIR_STRDUP(ret->query, xmluri->query_raw) < 0)
+ goto error;
#else
- if (xmluri->query &&
- !(ret->query = strdup(xmluri->query)))
- goto no_memory;
+ if (VIR_STRDUP(ret->query, xmluri->query) < 0)
+ goto error;
#endif
- if (xmluri->fragment &&
- !(ret->fragment = strdup(xmluri->fragment)))
- goto no_memory;
- if (xmluri->user &&
- !(ret->user = strdup(xmluri->user)))
- goto no_memory;
+ if (VIR_STRDUP(ret->fragment, xmluri->fragment) < 0)
+ goto error;
+ if (VIR_STRDUP(ret->user, xmluri->user) < 0)
+ goto error;
/* First check: does it even make sense to jump inside */
if (ret->server != NULL &&
return ret;
-no_memory:
- virReportOOMError();
error:
xmlFreeURI(xmluri);
virURIFree(ret);
* string as-is; it's up to callers to check whether "localhost"
* is allowed.
*/
- result = strdup(hostname);
- goto check_and_return;
+ ignore_value(VIR_STRDUP(result, hostname));
+ goto cleanup;
}
/* otherwise, it's a shortened, non-localhost, hostname. Attempt to
if (r != 0) {
VIR_WARN("getaddrinfo failed for '%s': %s",
hostname, gai_strerror(r));
- result = strdup(hostname);
- goto check_and_return;
+ ignore_value(VIR_STRDUP(result, hostname));
+ goto cleanup;
}
/* Tell static analyzers about getaddrinfo semantics. */
* localhost. Ignore the canonicalized name and just return the
* original hostname
*/
- result = strdup(hostname);
+ ignore_value(VIR_STRDUP(result, hostname));
else
/* Caller frees this string. */
- result = strdup(info->ai_canonname);
+ ignore_value(VIR_STRDUP(result, info->ai_canonname));
freeaddrinfo(info);
-check_and_return:
+cleanup:
if (result == NULL)
virReportOOMError();
return result;
return NULL;
}
- if (field == VIR_USER_ENT_DIRECTORY)
- ret = strdup(pw->pw_dir);
- else
- ret = strdup(pw->pw_name);
-
+ ignore_value(VIR_STRDUP(ret, field == VIR_USER_ENT_DIRECTORY ?
+ pw->pw_dir : pw->pw_name));
VIR_FREE(strbuf);
- if (!ret)
- virReportOOMError();
-
return ret;
}
return NULL;
}
- ret = strdup(gr->gr_name);
-
+ ignore_value(VIR_STRDUP(ret, gr->gr_name));
VIR_FREE(strbuf);
- if (!ret)
- virReportOOMError();
-
return ret;
}
*path = NULL;
if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) {
- if (SHGetPathFromIDList(pidl, buf)) {
- if (!(*path = strdup(buf))) {
- virReportOOMError();
- ret = -1;
- }
- }
+ if (SHGetPathFromIDList(pidl, buf) && VIR_STRDUP(*path, buf) < 0)
+ ret = -1;
CoTaskMemFree(pidl);
}
return ret;
strcpy(windowsdir, "C:\\");
}
- if (!(*path = strdup(windowsdir))) {
- virReportOOMError();
- ret = -1;
- }
-
- return ret;
+ return VIR_STRDUP(*path, windowsdir) < 0 ? -1 : 0;
}
/* USERPROFILE is probably the closest equivalent to $HOME? */
dir = getenv("USERPROFILE");
- if (dir) {
- if (!(ret = strdup(dir))) {
- virReportOOMError();
- return NULL;
- }
- }
+ if (VIR_STRDUP(ret, dir) < 0)
+ return NULL;
if (!ret &&
virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0)
continue;
}
- ret = strdup(entry->d_name);
+ ignore_value(VIR_STRDUP(ret, entry->d_name));
break;
}
if ((strlen(max_vports) >= strlen(vports)) ||
((strlen(max_vports) == strlen(vports)) &&
strcmp(max_vports, vports) > 0)) {
- ret = strdup(entry->d_name);
+ ignore_value(VIR_STRDUP(ret, entry->d_name));
goto cleanup;
}
xmlXPathFreeObject(obj);
return NULL;
}
- ret = strdup((char *) obj->stringval);
+ ignore_value(VIR_STRDUP(ret, (char *) obj->stringval));
xmlXPathFreeObject(obj);
- if (ret == NULL) {
- virReportOOMError();
- }
return ret;
}