diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 20e2c04dc3075a6b8dbc0b307dd6c4b7cceab249..e1653b156f61f86bd65bd4363536943acf3a44c9 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -370,8 +370,8 @@ virLockDaemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { - if (!(*pidfile = strdup(LOCALSTATEDIR "/run/virtlockd.pid"))) - goto no_memory; + if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/virtlockd.pid") < 0) + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -388,7 +388,8 @@ virLockDaemonPidFilePath(bool privileged, if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + virReportOOMError(); + goto error; } VIR_FREE(rundir); @@ -396,8 +397,6 @@ virLockDaemonPidFilePath(bool privileged, return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -408,8 +407,8 @@ virLockDaemonUnixSocketPaths(bool privileged, char **sockfile) { if (privileged) { - if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) - goto no_memory; + if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0) + goto error; } else { char *rundir = NULL; mode_t old_umask; @@ -426,15 +425,14 @@ virLockDaemonUnixSocketPaths(bool privileged, if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0) { VIR_FREE(rundir); - goto no_memory; + virReportOOMError(); + goto error; } VIR_FREE(rundir); } return 0; -no_memory: - virReportOOMError(); error: return -1; } @@ -869,10 +867,8 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client, _("Missing ownerName data in JSON document")); goto error; } - if (!(priv->ownerName = strdup(ownerName))) { - virReportOOMError(); + if (VIR_STRDUP(priv->ownerName, ownerName) < 0) goto error; - } if (!(ownerUUID = virJSONValueObjectGetString(object, "ownerUUID"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing ownerUUID data in JSON document")); @@ -1223,14 +1219,18 @@ int main(int argc, char **argv) { case 'p': VIR_FREE(pid_file); - if (!(pid_file = strdup(optarg))) + if (VIR_STRDUP_QUIET(pid_file, optarg) < 0) { + VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); + } break; case 'f': VIR_FREE(remote_config_file); - if (!(remote_config_file = strdup(optarg))) + if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0) { + VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); + } break; case OPT_VERSION: @@ -1314,8 +1314,8 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - if (!(run_dir = strdup(LOCALSTATEDIR "/run/libvirt"))) { - virReportOOMError(); + if (VIR_STRDUP_QUIET(run_dir, LOCALSTATEDIR "/run/libvirt") < 0) { + VIR_ERROR(_("Can't allocate memory")); goto cleanup; } } else { diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index c3d59bd236831909a668134a5135863c3e8ec096..4d7fe7d8def5baca884dabbadca57095f01d016c 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -53,8 +53,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and "goto" the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do { \ @@ -63,10 +63,8 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \ goto error; \ VIR_FREE(data->var_name); \ - if (!(data->var_name = strdup(p->str))) { \ - virReportOOMError(); \ + if (VIR_STRDUP(data->var_name, p->str) < 0) \ goto error; \ - } \ } \ } while (0) @@ -85,8 +83,8 @@ int virLockDaemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (!(*configfile = strdup(SYSCONFDIR "/libvirt/virtlockd.conf"))) - goto no_memory; + if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/virtlockd.conf") < 0) + goto error; } else { char *configdir = NULL; diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 8a92802b3aceb24bbaffc95b59bdcd4a4df09b73..c2e100048930bdd162b1144829b005338b06957b 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -25,7 +25,7 @@ #include "rpc/virnetserver.h" #include "rpc/virnetserverclient.h" #include "virlog.h" - +#include "virstring.h" #include "lock_daemon.h" #include "lock_protocol.h" #include "lock_daemon_dispatch_stubs.h" @@ -275,10 +275,8 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } - if (!(priv->ownerName = strdup(args->owner.name))) { - virReportOOMError(); + if (VIR_STRDUP(priv->ownerName, args->owner.name) < 0) goto cleanup; - } memcpy(priv->ownerUUID, args->owner.uuid, VIR_UUID_BUFLEN); priv->ownerId = args->owner.id; priv->ownerPid = args->owner.pid; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c index 807710584ac83c0c24f087bd9d4f1578e0f5ce9e..afe9e942b3057ffad5257bca62eb31207327f032 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -129,8 +129,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("file_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->fileLockSpaceDir); - if (!(driver->fileLockSpaceDir = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(driver->fileLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } @@ -140,8 +139,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("lvm_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->lvmLockSpaceDir); - if (!(driver->lvmLockSpaceDir = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(driver->lvmLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } @@ -151,8 +149,7 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile) CHECK_TYPE("scsi_lockspace_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->scsiLockSpaceDir); - if (!(driver->scsiLockSpaceDir = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(driver->scsiLockSpaceDir, p->str) < 0) { virConfFree(conf); return -1; } @@ -174,10 +171,8 @@ static char *virLockManagerLockDaemonPath(bool privileged) { char *path; if (privileged) { - if (!(path = strdup(LOCALSTATEDIR "/run/libvirt/virtlockd-sock"))) { - virReportOOMError(); + if (VIR_STRDUP(path, LOCALSTATEDIR "/run/libvirt/virtlockd-sock") < 0) return NULL; - } } else { char *rundir = NULL; @@ -468,10 +463,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr lock, if (STREQ(params[i].key, "uuid")) { memcpy(priv->uuid, params[i].value.uuid, VIR_UUID_BUFLEN); } else if (STREQ(params[i].key, "name")) { - if (!(priv->name = strdup(params[i].value.str))) { - virReportOOMError(); + if (VIR_STRDUP(priv->name, params[i].value.str) < 0) return -1; - } } else if (STREQ(params[i].key, "id")) { priv->id = params[i].value.i; } else if (STREQ(params[i].key, "pid")) { @@ -590,8 +583,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an LVM UUID %s for %s", newName, name); - if (!(newLockspace = strdup(driver->lvmLockSpaceDir))) - goto no_memory; + if (VIR_STRDUP(newLockspace, driver->lvmLockSpaceDir) < 0) + goto error; autoCreate = true; break; } @@ -607,8 +600,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, if (newName) { VIR_DEBUG("Got an SCSI ID %s for %s", newName, name); - if (!(newLockspace = strdup(driver->scsiLockSpaceDir))) - goto no_memory; + if (VIR_STRDUP(newLockspace, driver->scsiLockSpaceDir) < 0) + goto error; autoCreate = true; break; } @@ -617,17 +610,17 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, } if (driver->fileLockSpaceDir) { - if (!(newLockspace = strdup(driver->fileLockSpaceDir))) - goto no_memory; + if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0) + goto error; if (!(newName = virLockManagerLockDaemonDiskLeaseName(name))) goto no_memory; autoCreate = true; VIR_DEBUG("Using indirect lease %s for %s", newName, name); } else { - if (!(newLockspace = strdup(""))) - goto no_memory; - if (!(newName = strdup(name))) - goto no_memory; + if (VIR_STRDUP(newLockspace, "") < 0) + goto error; + if (VIR_STRDUP(newName, name) < 0) + goto error; VIR_DEBUG("Using direct lease for %s", name); } @@ -664,8 +657,8 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock, virReportOOMError(); return -1; } - if (!(newName = strdup(name))) - goto no_memory; + if (VIR_STRDUP(newName, name) < 0) + goto error; } break; default: diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index 4b48868325d7c51fde479c4496cb3f7f44eebfb8..eb15e29cb49ee26f7caab93cf8a0ba4970e36e1e 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -129,8 +129,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING); if (p && p->str) { VIR_FREE(driver->autoDiskLeasePath); - if (!(driver->autoDiskLeasePath = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(driver->autoDiskLeasePath, p->str) < 0) { virConfFree(conf); return -1; } @@ -150,8 +149,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) p = virConfGetValue(conf, "user"); CHECK_TYPE("user", VIR_CONF_STRING); if (p) { - if (!(tmp = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(tmp, p->str) < 0) { virConfFree(conf); return -1; } @@ -167,8 +165,7 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) p = virConfGetValue(conf, "group"); CHECK_TYPE("group", VIR_CONF_STRING); if (p) { - if (!(tmp = strdup(p->str))) { - virReportOOMError(); + if (VIR_STRDUP(tmp, p->str) < 0) { virConfFree(conf); return -1; } @@ -408,9 +405,8 @@ static int virLockManagerSanlockInit(unsigned int version, driver->autoDiskLease = false; driver->user = (uid_t) -1; driver->group = (gid_t) -1; - if (!(driver->autoDiskLeasePath = strdup(LOCALSTATEDIR "/lib/libvirt/sanlock"))) { + if (VIR_STRDUP(driver->autoDiskLeasePath, LOCALSTATEDIR "/lib/libvirt/sanlock") < 0) { VIR_FREE(driver); - virReportOOMError(); goto error; } diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 82bbe6b7d0224f23b87ede3795645a9828f06a74..4cffc3fe5175bf60edcc5c36606470e6210abbe2 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -194,10 +194,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name, plugin->driver = driver; plugin->handle = handle; plugin->refs = 1; - if (!(plugin->name = strdup(name))) { - virReportOOMError(); + if (VIR_STRDUP(plugin->name, name) < 0) goto cleanup; - } VIR_FREE(configFile); VIR_FREE(modfile);