---
src/openvz/openvz_conf.c | 31 +++++++++++++++----------------
src/openvz/openvz_driver.c | 30 +++++++++++++++---------------
2 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 49fae28..9dbdc74 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -135,9 +135,9 @@ openvzParseBarrierLimit(const char* value,
{
char *token;
char *saveptr = NULL;
- char *str = strdup(value);
+ char *str;
- if (str == NULL) {
+ if (VIR_STRDUP(str, value) < 0) {
virReportOOMError();
goto error;
}
@@ -230,9 +230,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
goto no_memory;
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->data.ethernet.ipaddr = strdup(token);
-
- if (net->data.ethernet.ipaddr == NULL)
+ if (VIR_STRDUP(net->data.ethernet.ipaddr, token) < 0)
goto no_memory;
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
@@ -405,7 +403,8 @@ openvzReadFSConf(virDomainDefPtr def,
goto no_memory;
fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE;
- fs->src = strdup(temp);
+ if (VIR_STRDUP(fs->src, temp) < 0)
+ goto no_memory;
} else {
/* OSTEMPLATE was not found, VE was booted from a private dir directly */
ret = openvzReadVPSConfigParam(veid, "VE_PRIVATE", &temp);
@@ -428,7 +427,8 @@ openvzReadFSConf(virDomainDefPtr def,
VIR_FREE(veid_str);
}
- fs->dst = strdup("/");
+ if (VIR_STRDUP(fs->dst, "/") < 0)
+ goto no_memory;
param = "DISKSPACE";
ret = openvzReadVPSConfigParam(veid, param, &temp);
@@ -451,9 +451,6 @@ openvzReadFSConf(virDomainDefPtr def,
}
}
- if (fs->src == NULL || fs->dst == NULL)
- goto no_memory;
-
if (VIR_REALLOC_N(def->fss, def->nfss + 1) < 0)
goto no_memory;
def->fss[def->nfss++] = fs;
@@ -607,9 +604,9 @@ int openvzLoadDomains(struct openvz_driver *driver) {
goto cleanup;
}
- if (!(def->os.type = strdup("exe")))
+ if (VIR_STRDUP(def->os.type, "exe") < 0)
goto no_memory;
- if (!(def->os.init = strdup("/sbin/init")))
+ if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)
goto no_memory;
ret = openvzReadVPSConfigParam(veid, "CPUS", &temp);
@@ -800,8 +797,7 @@ openvzReadConfigParam(const char *conf_file, const char *param, char
**value)
saveptr = NULL;
if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) {
VIR_FREE(*value);
- *value = strdup(token);
- if (*value == NULL) {
+ if (VIR_STRDUP(*value, token) < 0) {
err = 1;
break;
}
@@ -952,10 +948,13 @@ openvzLocateConfDir(void)
{
const char *conf_dir_list[] = {"/etc/vz/conf",
"/usr/local/etc/conf", NULL};
int i=0;
+ char *ret = NULL;
while (conf_dir_list[i]) {
- if (!access(conf_dir_list[i], F_OK))
- return strdup(conf_dir_list[i]);
+ if (!access(conf_dir_list[i], F_OK)) {
+ ignore_value(VIR_STRDUP(ret, conf_dir_list[i]));
+ return ret;
+ }
i++;
}
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index e6d7146..027cda8 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -88,7 +88,7 @@ static void openvzDriverUnlock(struct openvz_driver *driver)
struct openvz_driver ovz_driver;
-static void cmdExecFree(const char *cmdExec[])
+static void cmdExecFree(char *cmdExec[])
{
int i=-1;
while (cmdExec[++i]) {
@@ -104,7 +104,7 @@ openvzDomainDefPostParse(virDomainDefPtr def,
{
/* fill the init path */
if (STREQ(def->os.type, "exe") && !def->os.init) {
- if (!(def->os.init = strdup("/sbin/init"))) {
+ if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) {
virReportOOMError();
return -1;
}
@@ -358,7 +358,7 @@ static char *openvzDomainGetOSType(virDomainPtr dom)
goto cleanup;
}
- if (!(ret = strdup(vm->def->os.type)))
+ if (VIR_STRDUP(ret, vm->def->os.type) < 0)
virReportOOMError();
cleanup:
@@ -772,12 +772,14 @@ openvzGenerateVethName(int veid, char *dev_name_ve)
{
char dev_name[32];
int ifNo = 0;
+ char *ret;
if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1)
return NULL;
if (snprintf(dev_name, sizeof(dev_name), "veth%d.%d", veid, ifNo) < 7)
return NULL;
- return strdup(dev_name);
+ ignore_value(VIR_STRDUP(ret, dev_name));
+ return ret;
}
static char *
@@ -788,7 +790,8 @@ openvzGenerateContainerVethName(int veid)
/* try to get line "^NETIF=..." from config */
if (openvzReadVPSConfigParam(veid, "NETIF", &temp) <= 0) {
- name = strdup("eth0");
+ if (VIR_STRDUP(name, "eth0") < 0)
+ virReportOOMError();
} else {
char *saveptr = NULL;
char *s;
@@ -803,15 +806,12 @@ openvzGenerateContainerVethName(int veid)
}
/* set new name */
- ignore_value(virAsprintf(&name, "eth%d", max + 1));
+ if (virAsprintf(&name, "eth%d", max + 1) < 0)
+ virReportOOMError();
}
VIR_FREE(temp);
- if (name == NULL) {
- virReportOOMError();
- }
-
return name;
}
@@ -821,7 +821,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
virBufferPtr configBuf)
{
int rc = 0, narg;
- const char *prog[OPENVZ_MAX_ARG];
+ char *prog[OPENVZ_MAX_ARG];
char macaddr[VIR_MAC_STRING_BUFLEN];
virMacAddr host_mac;
char host_macaddr[VIR_MAC_STRING_BUFLEN];
@@ -830,9 +830,9 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
#define ADD_ARG_LIT(thisarg) \
do { \
- if (narg >= OPENVZ_MAX_ARG) \
+ if (narg >= OPENVZ_MAX_ARG) \
goto no_memory; \
- if ((prog[narg++] = strdup(thisarg)) == NULL) \
+ if (VIR_STRDUP(prog[narg++], thisarg) < 0) \
goto no_memory; \
} while (0)
@@ -928,7 +928,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
if (prog[0] != NULL) {
ADD_ARG_LIT("--save");
- if (virRun(prog, NULL) < 0) {
+ if (virRun((const char * const*) prog, NULL) < 0) {
rc = -1;
goto exit;
}
@@ -1642,7 +1642,7 @@ static int openvzConnectListDefinedDomains(virConnectPtr conn
ATTRIBUTE_UNUSED,
continue;
}
snprintf(vpsname, sizeof(vpsname), "%d", veid);
- if (!(names[got] = strdup(vpsname))) {
+ if (VIR_STRDUP(names[got], vpsname) < 0) {
virReportOOMError();
goto out;
}
--
1.8.1.5