mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Remove error checking after using vshMalloc.
vshMalloc and friends always exit() on allocation failure, so there is no reason to do checking for NULL in the code that uses it. Signed-off-by: Chris Lalancette <clalance@redhat.com>
This commit is contained in:
parent
de6380726b
commit
9aa236e19f
@ -1629,8 +1629,6 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (nparams) {
|
if (nparams) {
|
||||||
params = vshMalloc(ctl, sizeof(virSchedParameter)* nparams);
|
params = vshMalloc(ctl, sizeof(virSchedParameter)* nparams);
|
||||||
if (params == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
memset(params, 0, sizeof(virSchedParameter)* nparams);
|
memset(params, 0, sizeof(virSchedParameter)* nparams);
|
||||||
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
|
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
|
||||||
@ -7909,51 +7907,40 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
/* Make XML of interface */
|
/* Make XML of interface */
|
||||||
tmp = vshMalloc(ctl, 1);
|
tmp = vshMalloc(ctl, 1);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
buf = vshMalloc(ctl, strlen(type) + 25);
|
buf = vshMalloc(ctl, strlen(type) + 25);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
sprintf(buf, " <interface type='%s'>\n" , type);
|
sprintf(buf, " <interface type='%s'>\n" , type);
|
||||||
|
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(source) + 28);
|
tmp = vshRealloc(ctl, tmp, strlen(source) + 28);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
if (typ == 1) {
|
if (typ == 1) {
|
||||||
sprintf(tmp, " <source network='%s'/>\n", source);
|
sprintf(tmp, " <source network='%s'/>\n", source);
|
||||||
} else if (typ == 2) {
|
} else if (typ == 2) {
|
||||||
sprintf(tmp, " <source bridge='%s'/>\n", source);
|
sprintf(tmp, " <source bridge='%s'/>\n", source);
|
||||||
}
|
}
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
if (target != NULL) {
|
if (target != NULL) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(target) + 24);
|
tmp = vshRealloc(ctl, tmp, strlen(target) + 24);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <target dev='%s'/>\n", target);
|
sprintf(tmp, " <target dev='%s'/>\n", target);
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mac != NULL) {
|
if (mac != NULL) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(mac) + 25);
|
tmp = vshRealloc(ctl, tmp, strlen(mac) + 25);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <mac address='%s'/>\n", mac);
|
sprintf(tmp, " <mac address='%s'/>\n", mac);
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script != NULL) {
|
if (script != NULL) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(script) + 25);
|
tmp = vshRealloc(ctl, tmp, strlen(script) + 25);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <script path='%s'/>\n", script);
|
sprintf(tmp, " <script path='%s'/>\n", script);
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + 19);
|
buf = vshRealloc(ctl, buf, strlen(buf) + 19);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, " </interface>\n");
|
strcat(buf, " </interface>\n");
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "persistent")) {
|
if (vshCommandOptBool(cmd, "persistent")) {
|
||||||
@ -8181,9 +8168,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
/* Make XML of disk */
|
/* Make XML of disk */
|
||||||
tmp = vshMalloc(ctl, 1);
|
tmp = vshMalloc(ctl, 1);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
buf = vshMalloc(ctl, 23);
|
buf = vshMalloc(ctl, 23);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
sprintf(buf, " <disk type='file'");
|
sprintf(buf, " <disk type='file'");
|
||||||
} else {
|
} else {
|
||||||
@ -8192,72 +8177,56 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(type) + 13);
|
tmp = vshRealloc(ctl, tmp, strlen(type) + 13);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " device='%s'>\n", type);
|
sprintf(tmp, " device='%s'>\n", type);
|
||||||
} else {
|
} else {
|
||||||
tmp = vshRealloc(ctl, tmp, 3);
|
tmp = vshRealloc(ctl, tmp, 3);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, ">\n");
|
sprintf(tmp, ">\n");
|
||||||
}
|
}
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
if (driver) {
|
if (driver) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(driver) + 22);
|
tmp = vshRealloc(ctl, tmp, strlen(driver) + 22);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <driver name='%s'", driver);
|
sprintf(tmp, " <driver name='%s'", driver);
|
||||||
} else {
|
} else {
|
||||||
tmp = vshRealloc(ctl, tmp, 25);
|
tmp = vshRealloc(ctl, tmp, 25);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <driver name='phy'");
|
sprintf(tmp, " <driver name='phy'");
|
||||||
}
|
}
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
if (subdriver) {
|
if (subdriver) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(subdriver) + 12);
|
tmp = vshRealloc(ctl, tmp, strlen(subdriver) + 12);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " type='%s'/>\n", subdriver);
|
sprintf(tmp, " type='%s'/>\n", subdriver);
|
||||||
} else {
|
} else {
|
||||||
tmp = vshRealloc(ctl, tmp, 4);
|
tmp = vshRealloc(ctl, tmp, 4);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, "/>\n");
|
sprintf(tmp, "/>\n");
|
||||||
}
|
}
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(source) + 25);
|
tmp = vshRealloc(ctl, tmp, strlen(source) + 25);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
sprintf(tmp, " <source file='%s'/>\n", source);
|
sprintf(tmp, " <source file='%s'/>\n", source);
|
||||||
} else {
|
} else {
|
||||||
sprintf(tmp, " <source dev='%s'/>\n", source);
|
sprintf(tmp, " <source dev='%s'/>\n", source);
|
||||||
}
|
}
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(target) + 24);
|
tmp = vshRealloc(ctl, tmp, strlen(target) + 24);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <target dev='%s'/>\n", target);
|
sprintf(tmp, " <target dev='%s'/>\n", target);
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
|
|
||||||
if (mode != NULL) {
|
if (mode != NULL) {
|
||||||
tmp = vshRealloc(ctl, tmp, strlen(mode) + 11);
|
tmp = vshRealloc(ctl, tmp, strlen(mode) + 11);
|
||||||
if (!tmp) goto cleanup;
|
|
||||||
sprintf(tmp, " <%s/>\n", mode);
|
sprintf(tmp, " <%s/>\n", mode);
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
buf = vshRealloc(ctl, buf, strlen(buf) + strlen(tmp) + 1);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, tmp);
|
strcat(buf, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = vshRealloc(ctl, buf, strlen(buf) + 13);
|
buf = vshRealloc(ctl, buf, strlen(buf) + 13);
|
||||||
if (!buf) goto cleanup;
|
|
||||||
strcat(buf, " </disk>\n");
|
strcat(buf, " </disk>\n");
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "persistent")) {
|
if (vshCommandOptBool(cmd, "persistent")) {
|
||||||
@ -8600,12 +8569,7 @@ editWriteToTempFile (vshControl *ctl, const char *doc)
|
|||||||
const char *tmpdir;
|
const char *tmpdir;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
ret = malloc (PATH_MAX);
|
ret = vshMalloc(ctl, PATH_MAX);
|
||||||
if (!ret) {
|
|
||||||
vshError(ctl, _("malloc: failed to allocate temporary file name: %s"),
|
|
||||||
strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpdir = getenv ("TMPDIR");
|
tmpdir = getenv ("TMPDIR");
|
||||||
if (!tmpdir) tmpdir = "/tmp";
|
if (!tmpdir) tmpdir = "/tmp";
|
||||||
|
Loading…
Reference in New Issue
Block a user