[libvirt] [PATCH] domain_conf.c: remove dead store
by Jim Meyering
Another dead store:
>From 06c5ed162cbdcfec74461e9d09c82244242cc6a2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 17:27:34 +0200
Subject: [PATCH] domain_conf.c: remove dead store
* src/domain_conf.c (virDomainSaveXML): ...and decl of "err".
---
src/domain_conf.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/domain_conf.c b/src/domain_conf.c
index 8dde5dd..4e8ad37 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -4456,12 +4456,11 @@ int virDomainSaveXML(virConnectPtr conn,
char *configFile = NULL;
int fd = -1, ret = -1;
size_t towrite;
- int err;
if ((configFile = virDomainConfigFile(conn, configDir, def->name)) == NULL)
goto cleanup;
- if ((err = virFileMakePath(configDir))) {
+ if (virFileMakePath(configDir)) {
virReportSystemError(conn, errno,
_("cannot create config directory '%s'"),
configDir);
--
1.6.4.2.409.g85dc3
15 years, 2 months
[libvirt] [PATCH] xm_internal.c: remove two ret=... dead stores
by Jim Meyering
Two more dead stores:
>From 92bf654b02e5c1eb3334fc13ef52f5b0679512ea Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 17:22:19 +0200
Subject: [PATCH] xm_internal.c: remove two ret=... dead stores
* src/xm_internal.c (xenXMDomainCreate): Remove dead stores.
---
src/xm_internal.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/xm_internal.c b/src/xm_internal.c
index e675672..e948fa0 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1851,10 +1851,10 @@ int xenXMDomainCreate(virDomainPtr domain) {
goto error;
domain->id = ret;
- if ((ret = xend_wait_for_devices(domain->conn, domain->name)) < 0)
+ if (xend_wait_for_devices(domain->conn, domain->name) < 0)
goto error;
- if ((ret = xenDaemonDomainResume(domain)) < 0)
+ if (xenDaemonDomainResume(domain) < 0)
goto error;
xenUnifiedUnlock(priv);
--
1.6.4.2.409.g85dc3
15 years, 2 months
[libvirt] [PATCH] lxc_container.c: avoid a leak on error paths
by Jim Meyering
This started with a dead-store report:
File: lxc_container.c
Location: line 417, column 10
Description: Although the value stored to 'rc' is used in the
enclosing expression, the value is never actually read from 'rc'
But there was a leak, too, upon any but the first failure.
This fixes both.
>From 141ba8bab2de00c911017bff6fca240c72a80633 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 16:12:35 +0200
Subject: [PATCH] lxc_container.c: avoid a leak on error paths
* src/lxc_container.c (lxcContainerMountBasicFS): Don't leak upon failure.
Add "cleanup:" label and change each post-allocation failure to
use "goto cleanup" rather than returning immediately.
---
src/lxc_container.c | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/lxc_container.c b/src/lxc_container.c
index 2073864..f4381e7 100644
--- a/src/lxc_container.c
+++ b/src/lxc_container.c
@@ -1,6 +1,6 @@
/*
* Copyright IBM Corp. 2008
- * Copyright Red Hat 2008
+ * Copyright Red Hat 2008-2009
*
* lxc_container.c: file description
*
@@ -384,12 +384,12 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
{ "none", "/selinux", "selinuxfs" },
#endif
};
- int i, rc;
+ int i, rc = -1;
char *devpts;
if (virAsprintf(&devpts, "/.oldroot%s/dev/pts", root->src) < 0) {
virReportOOMError(NULL);
- return -1;
+ return rc;
}
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
@@ -397,31 +397,35 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
virReportSystemError(NULL, errno,
_("failed to mkdir %s"),
mnts[i].src);
- return -1;
+ goto cleanup;
}
if (mount(mnts[i].src, mnts[i].dst, mnts[i].type, 0, NULL) < 0) {
virReportSystemError(NULL, errno,
_("failed to mount %s on %s"),
mnts[i].type, mnts[i].type);
- return -1;
+ goto cleanup;
}
}
if ((rc = virFileMakePath("/dev/pts") < 0)) {
virReportSystemError(NULL, rc, "%s",
_("cannot create /dev/pts"));
- return -1;
+ goto cleanup;
}
VIR_DEBUG("Trying to move %s to %s", devpts, "/dev/pts");
if ((rc = mount(devpts, "/dev/pts", NULL, MS_MOVE, NULL)) < 0) {
virReportSystemError(NULL, errno, "%s",
_("failed to mount /dev/pts in container"));
- return -1;
+ goto cleanup;
}
+
+ rc = 0;
+
+ cleanup:
VIR_FREE(devpts);
- return 0;
+ return rc;
}
static int lxcContainerPopulateDevices(void)
--
1.6.4.2.409.g85dc3
15 years, 2 months
[libvirt] Dead code vs. XXX comment: remove or not?
by Jim Meyering
clang reported that this assignment to type is a dead store,
since type is never used after this point.
This is xm_internal.c, line 1074:
/* XXX Forcing to pretend its a bridge */
if (type == -1) {
type = 1;
}
Normally I'd just remove the whole if block, but the XXX comment
makes me think someone has plans for this code.
I'll wait for a second opinion.
15 years, 2 months
[libvirt] address 3 more dead stores
by Jim Meyering
These changes fix two dead stores and add a comment suggesting
why *not* to remove the third one.
>From 41c778fdbaef9abf52bc4c3e278d3389d8198c34 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 10:55:55 +0200
Subject: [PATCH 1/3] interface_conf.c: remove a dead-store and declaration
* src/interface_conf.c (virInterfaceDefParseDhcp): Remove unused "old".
---
src/interface_conf.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/src/interface_conf.c b/src/interface_conf.c
index a74d17e..96e0710 100644
--- a/src/interface_conf.c
+++ b/src/interface_conf.c
@@ -228,11 +228,9 @@ static int
virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceDefPtr def,
xmlNodePtr dhcp, xmlXPathContextPtr ctxt) {
char *tmp;
- xmlNodePtr old;
int ret = 0;
def->proto.dhcp = 1;
- old = ctxt->node;
ctxt->node = dhcp;
/* Not much to do in the current version */
tmp = virXPathString(conn, "string(./@peerdns)", ctxt);
--
1.6.4.2.409.g85dc3
>From 10037ca58c8d93e427c480082704e7dd52424525 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 11:01:00 +0200
Subject: [PATCH 2/3] hash.c: remove a dead store
* src/hash.c (virHashFree): Remove useless assignment to inside_table.
---
src/hash.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/hash.c b/src/hash.c
index 9308c0c..45c5747 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -231,7 +231,6 @@ virHashFree(virHashTablePtr table, virHashDeallocator f)
inside_table = 0;
iter = next;
}
- inside_table = 0;
}
VIR_FREE(table->table);
}
--
1.6.4.2.409.g85dc3
>From 3b16e6d50d364a5307284a78a7b23d8631146663 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 4 Sep 2009 11:20:23 +0200
Subject: [PATCH 3/3] qemu_conf.c: add a comment suggesting why we leave a dead-store
* src/qemu_conf.c (qemuBuildHostNetStr): Do not remove the type_sep=','
dead store, since not having it would be a problem if we ever add a
new attribute=VAL option.
---
src/qemu_conf.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 2c4a37d..6ffca2f 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1269,7 +1269,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
if (net->hostnet_name) {
virBufferVSprintf(&buf, "%cname=%s", type_sep,
net->hostnet_name);
- type_sep = ',';
+ type_sep = ','; /* dead-store, but leave it, in case... */
}
if (virBufferError(&buf)) {
virReportOOMError(conn);
--
1.6.4.2.409.g85dc3
15 years, 2 months
[libvirt] [PATCH 4/7] VMware ESX: Simplify SOAP request and response handling
by Matthias Bolte
* src/esx/esx_vi.[ch]: convert esxVI_RemoteRequest_Execute() to a
simpler esxVI_Context_Execute() version, remove esxVI_RemoteRequest
and convert esxVI_RemoteResponse to esxVI_Response
* src/esx/esx_vi_methods.c: update and simplify callers to use
esxVI_Context_Execute() instead of esxVI_RemoteRequest_Execute()
15 years, 2 months
[libvirt] [PATCH 2/7] VMware ESX: Make esxVI_GetVirtualMachineIdentity() more robust
by Matthias Bolte
Check the config status before requesting config subelements
* src/esx/esx_driver.c: add configStatus to the requested properties
to check it in esxVI_GetVirtualMachineIdentity()
* src/esx/esx_vi.[ch]: add esxVI_GetManagedEntityStatus()
and use it in esxVI_GetVirtualMachineIdentity()
* src/esx/esx_vi_types.[ch]: add VI type esxVI_ManagedEntityStatus
15 years, 2 months
[libvirt] [PATCH] Fix more OOM handling bugs
by Daniel P. Berrange
* src/qemu_conf.c: Fix leak of values upon OOM
* src/xend_internal.c: Fix missing check for OOM failure
* tests/qemuargv2xmltest.c, tests/qemuxml2argvtest.c: Free
stateDir upon exit to avoid leak
---
src/qemu_conf.c | 21 ++++++++++++++++++---
src/xend_internal.c | 6 ++++++
tests/qemuargv2xmltest.c | 1 +
tests/qemuxml2argvtest.c | 1 +
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 22f5edd..ad41104 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1722,6 +1722,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
continue;
}
+ ADD_ARG_SPACE;
+
if (idx < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("unsupported disk type '%s'"), disk->dst);
@@ -1773,7 +1775,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
optstr = virBufferContentAndReset(&opt);
- ADD_ARG_LIT("-drive");
+ if ((qargv[qargc++] = strdup("-drive")) == NULL) {
+ VIR_FREE(optstr);
+ goto no_memory;
+ }
ADD_ARG(optstr);
}
} else {
@@ -1829,6 +1834,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
net->vlan = i;
+ ADD_ARG_SPACE;
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
qemuAssignNetNames(def, net) < 0)
goto no_memory;
@@ -1836,9 +1842,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
if (qemuBuildNicStr(conn, net, NULL, ',', net->vlan, &nic) < 0)
goto error;
- ADD_ARG_LIT("-net");
+ if ((qargv[qargc++] = strdup("-net")) == NULL) {
+ VIR_FREE(nic);
+ goto no_memory;
+ }
ADD_ARG(nic);
+
+ ADD_ARG_SPACE;
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
int tapfd = qemudNetworkIfaceConnect(conn, driver, net, qemuCmdFlags);
@@ -1862,7 +1873,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto error;
}
- ADD_ARG_LIT("-net");
+ if ((qargv[qargc++] = strdup("-net")) == NULL) {
+ VIR_FREE(host);
+ goto no_memory;
+ }
ADD_ARG(host);
VIR_FREE(tapfd_name);
@@ -2230,6 +2244,7 @@ static int qemuStringToArgvEnv(const char *args,
goto no_memory;
for (i = 0 ; i < envend ; i++) {
progenv[i] = arglist[i];
+ arglist[i] = NULL;
}
progenv[i] = NULL;
}
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 99847b0..20ddb89 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -5212,6 +5212,9 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
break;
}
+ if (virBufferError(buf))
+ return -1;
+
return 0;
}
@@ -5535,6 +5538,9 @@ xenDaemonFormatSxprSound(virConnectPtr conn,
virBufferVSprintf(buf, "%s%s", i ? "," : "", str);
}
+ if (virBufferError(buf))
+ return -1;
+
return 0;
}
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 7861520..4a92280 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -223,6 +223,7 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
+ free(driver.stateDir);
virCapabilitiesFree(driver.caps);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 6f25e7d..2f91288 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -270,6 +270,7 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP, "tcp:10.0.0.1:5000");
+ free(driver.stateDir);
virCapabilitiesFree(driver.caps);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
--
1.6.2.5
15 years, 2 months