Likewise, given if (foo != NULL) free (foo); remove the useless "if" test.
Do the same for sexpr_free, since it has similar semantics.
Detect with this:
(-0x3b tells Perl to use ';' as the input record separator)
perl -0x3b -ne '/\b(if \((.+?)(?:\s*!=\s*NULL\s*)?\)\s+(sexpr_)?free *\(\2\))/s and
print "$ARGV: $1\n"'\ $(git ls-files)
Note that it also changes the code produced by generator.py.
This is just a heads-up.
Before committing it, I will add a rule using something like
the above to help avoid regressions.
BTW, there is some very misleading indentation in the vicinity
of some of these changes, but I didn't correct any of that.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
proxy/libvirt_proxy.c | 3 +-
python/generator.py | 2 +-
qemud/qemud.c | 5 +--
src/buf.c | 3 +-
src/conf.c | 7 +----
src/hash.c | 15 ++++---------
src/iptables.c | 6 +---
src/libvirt.c | 6 ++--
src/openvz_conf.c | 3 +-
src/qemu_conf.c | 8 ++----
src/qemu_driver.c | 18 +++++-----------
src/remote_internal.c | 26 ++++++++++++------------
src/test.c | 24 +++++++--------------
src/virsh.c | 53 ++++++++++++++++--------------------------------
src/virterror.c | 12 +++-------
src/xen_internal.c | 9 ++-----
src/xen_unified.c | 12 +++-------
src/xend_internal.c | 44 +++++++++++++---------------------------
src/xm_internal.c | 9 ++-----
src/xml.c | 21 ++++++-------------
src/xmlrpc.c | 20 +++++-------------
src/xs_internal.c | 2 -
tests/testutils.c | 3 +-
tests/xencapstest.c | 3 +-
tests/xmconfigtest.c | 3 +-
25 files changed, 110 insertions(+), 207 deletions(-)
diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c
index d8f2e64..5ccf855 100644
--- a/proxy/libvirt_proxy.c
+++ b/proxy/libvirt_proxy.c
@@ -505,8 +505,7 @@ retry2:
memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN);
strcpy(&request.extra.str[VIR_UUID_BUFLEN], name);
}
- if (name)
- free(name);
+ free(name);
break;
}
case VIR_PROXY_LOOKUP_UUID: {
diff --git a/python/generator.py b/python/generator.py
index 7625a93..30b03fd 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -375,7 +375,7 @@ def print_function_wrapper(name, output, export, include):
if ret[0] == 'void':
if file == "python_accessor":
if args[1][1] == "char *":
- c_call = "\n if (%s->%s != NULL) free(%s->%s);\n" % (
+ c_call = "\n free(%s->%s);\n" % (
args[0][0], args[1][0], args[0][0], args[1][0])
c_call = c_call + " %s->%s = (%s)strdup((const xmlChar *)%s);\n" %
(args[0][0],
args[1][0], args[1][1], args[1][0])
diff --git a/qemud/qemud.c b/qemud/qemud.c
index 467e011..4cbe04e 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -1132,7 +1132,7 @@ static void qemudDispatchClientFailure(struct qemud_server *server,
struct qemud
#if HAVE_SASL
if (client->saslconn) sasl_dispose(&client->saslconn);
- if (client->saslUsername) free(client->saslUsername);
+ free(client->saslUsername);
#endif
if (client->tlssession) gnutls_deinit (client->tlssession);
close(client->fd);
@@ -1638,8 +1638,7 @@ static void qemudCleanup(struct qemud_server *server) {
if (server->saslUsernameWhitelist) {
char **list = server->saslUsernameWhitelist;
while (*list) {
- if (*list)
- free(*list);
+ free(*list);
list++;
}
}
diff --git a/src/buf.c b/src/buf.c
index 5f58027..188d040 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -150,8 +150,7 @@ void
virBufferFree(virBufferPtr buf)
{
if (buf) {
- if (buf->content)
- free(buf->content);
+ free(buf->content);
free(buf);
}
}
diff --git a/src/conf.c b/src/conf.c
index 62c42ff..8e66d84 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -490,7 +490,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
ret = calloc(1, sizeof(*ret));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"),
0);
- if (str != NULL)
free(str);
return(NULL);
}
@@ -642,8 +641,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
free(name);
virConfFreeValue(value);
- if (comm != NULL)
- free(comm);
+ free(comm);
return(-1);
}
return(0);
@@ -776,8 +774,7 @@ __virConfFree(virConfPtr conf)
virConfEntryPtr next;
free(tmp->name);
virConfFreeValue(tmp->value);
- if (tmp->comment)
- free(tmp->comment);
+ free(tmp->comment);
next = tmp->next;
free(tmp);
tmp = next;
diff --git a/src/hash.c b/src/hash.c
index d95eea9..4e4ce60 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -226,8 +226,7 @@ virHashFree(virHashTablePtr table, virHashDeallocator f)
next = iter->next;
if ((f != NULL) && (iter->payload != NULL))
f(iter->payload, iter->name);
- if (iter->name)
- free(iter->name);
+ free(iter->name);
iter->payload = NULL;
if (!inside_table)
free(iter);
@@ -453,8 +452,7 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
if ((f != NULL) && (entry->payload != NULL))
f(entry->payload, entry->name);
entry->payload = NULL;
- if (entry->name)
- free(entry->name);
+ free(entry->name);
if (prev) {
prev->next = entry->next;
free(entry);
@@ -538,8 +536,7 @@ int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter,
virHashDealloc
if (iter(entry->payload, entry->name, data)) {
count++;
f(entry->payload, entry->name);
- if (entry->name)
- free(entry->name);
+ free(entry->name);
if (prev) {
prev->next = entry->next;
free(entry);
@@ -812,8 +809,7 @@ __virGetDomain(virConnectPtr conn, const char *name, const unsigned
char *uuid)
error:
pthread_mutex_unlock(&conn->lock);
if (ret != NULL) {
- if (ret->name != NULL)
- free(ret->name );
+ free(ret->name );
free(ret);
}
return(NULL);
@@ -946,8 +942,7 @@ __virGetNetwork(virConnectPtr conn, const char *name, const unsigned
char *uuid)
error:
pthread_mutex_unlock(&conn->lock);
if (ret != NULL) {
- if (ret->name != NULL)
- free(ret->name );
+ free(ret->name );
free(ret);
}
return(NULL);
diff --git a/src/iptables.c b/src/iptables.c
index 5ac9be6..b59faa4 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -254,8 +254,7 @@ iptRulesSave(iptRules *rules)
static void
iptRuleFree(iptRule *rule)
{
- if (rule->rule)
- free(rule->rule);
+ free(rule->rule);
rule->rule = NULL;
if (rule->argv) {
@@ -488,8 +487,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg,
...)
}
error:
- if (rule)
- free(rule);
+ free(rule);
if (argv) {
n = 0;
diff --git a/src/libvirt.c b/src/libvirt.c
index e400783..af81930 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -615,7 +615,7 @@ do_open (const char *name,
return ret;
failed:
- if (ret->name) free (ret->name);
+ free (ret->name);
if (ret->driver) ret->driver->close (ret);
if (uri) xmlFreeURI(uri);
virUnrefConnect(ret);
@@ -1978,8 +1978,8 @@ virDomainMigrate (virDomainPtr domain,
ddomain = virDomainLookupByName (dconn, dname);
done:
- if (uri_out) free (uri_out);
- if (cookie) free (cookie);
+ free (uri_out);
+ free (cookie);
return ddomain;
}
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index a886001..4e4019c 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -494,8 +494,7 @@ static struct openvz_vm_def
return def;
bail_out:
- if (prop)
- free(prop);
+ free(prop);
if (obj)
xmlXPathFreeObject(obj);
if (ctxt)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 922223e..0de641d 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1379,8 +1379,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
return def;
error:
- if (prop)
- free(prop);
+ free(prop);
if (obj)
xmlXPathFreeObject(obj);
if (ctxt)
@@ -1468,8 +1467,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
no_memory:
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "tapfds");
error:
- if (retval)
- free(retval);
+ free(retval);
if (tapfd != -1)
close(tapfd);
return NULL;
@@ -1941,7 +1939,7 @@ qemudParseVMDeviceDef(virConnectPtr conn,
error:
if (xml) xmlFreeDoc(xml);
- if (dev) free(dev);
+ free(dev);
return NULL;
}
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 566fb76..71a3125 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -228,7 +228,7 @@ qemudStartup(void) {
out_of_memory:
qemudLog (QEMUD_ERR, "qemudStartup: out of memory");
- if (base) free (base);
+ free (base);
free(qemu_driver);
qemu_driver = NULL;
return -1;
@@ -330,17 +330,11 @@ qemudShutdown(void) {
qemu_driver->nactivenetworks = 0;
qemu_driver->ninactivenetworks = 0;
- if (qemu_driver->configDir)
- free(qemu_driver->configDir);
- if (qemu_driver->autostartDir)
- free(qemu_driver->autostartDir);
- if (qemu_driver->networkConfigDir)
- free(qemu_driver->networkConfigDir);
- if (qemu_driver->networkAutostartDir)
- free(qemu_driver->networkAutostartDir);
-
- if (qemu_driver->vncTLSx509certdir)
- free(qemu_driver->vncTLSx509certdir);
+ free(qemu_driver->configDir);
+ free(qemu_driver->autostartDir);
+ free(qemu_driver->networkConfigDir);
+ free(qemu_driver->networkAutostartDir);
+ free(qemu_driver->vncTLSx509certdir);
if (qemu_driver->brctl)
brShutdown(qemu_driver->brctl);
diff --git a/src/remote_internal.c b/src/remote_internal.c
index 860b4d8..4d855ab 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -735,13 +735,13 @@ doRemoteOpen (virConnectPtr conn,
cleanup:
/* Free up the URL and strings. */
- if (name) free (name);
- if (command) free (command);
- if (sockname) free (sockname);
- if (authtype) free (authtype);
- if (netcat) free (netcat);
- if (username) free (username);
- if (port) free (port);
+ free (name);
+ free (command);
+ free (sockname);
+ free (authtype);
+ free (netcat);
+ free (username);
+ free (port);
if (cmd_argv) {
char **cmd_argv_ptr = cmd_argv;
while (*cmd_argv_ptr) {
@@ -1139,10 +1139,10 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
#endif
/* Free hostname copy */
- if (priv->hostname) free (priv->hostname);
+ free (priv->hostname);
/* See comment for remoteType. */
- if (priv->type) free (priv->type);
+ free (priv->type);
/* Free private data. */
priv->magic = DEAD;
@@ -3267,7 +3267,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int
in_open,
/* This server call shows complete, and earlier client step was OK */
if (complete && err == SASL_OK) {
- if (serverin) free(serverin);
+ free(serverin);
break;
}
}
@@ -3297,9 +3297,9 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int
in_open,
ret = 0;
cleanup:
- if (localAddr) free(localAddr);
- if (remoteAddr) free(remoteAddr);
- if (serverin) free(serverin);
+ free(localAddr);
+ free(remoteAddr);
+ free(serverin);
free(saslcb);
remoteAuthFreeCredentials(cred, ncred);
diff --git a/src/test.c b/src/test.c
index d228b31..d39207f 100644
--- a/src/test.c
+++ b/src/test.c
@@ -354,8 +354,7 @@ static int testLoadDomain(virConnectPtr conn,
return (handle);
error:
- if (name)
- free(name);
+ free(name);
return (-1);
}
@@ -525,16 +524,11 @@ static int testLoadNetwork(virConnectPtr conn,
return (handle);
error:
- if (ipaddress)
- free(ipaddress);
- if (ipnetmask)
- free(ipnetmask);
- if (dhcpstart)
- free(dhcpstart);
- if (dhcpend)
- free(dhcpend);
- if (name)
- free(name);
+ free(ipaddress);
+ free(ipnetmask);
+ free(dhcpstart);
+ free(dhcpend);
+ free(name);
return (-1);
}
@@ -838,10 +832,8 @@ static int testOpenFromFile(virConnectPtr conn,
return (0);
error:
- if (domains != NULL)
- free(domains);
- if (networks != NULL)
- free(networks);
+ free(domains);
+ free(networks);
if (xml)
xmlFreeDoc(xml);
if (fd != -1)
diff --git a/src/virsh.c b/src/virsh.c
index 78c7c85..d081008 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -428,8 +428,7 @@ cmdConnect(vshControl * ctl, vshCmd * cmd)
ctl->conn = NULL;
}
- if (ctl->name)
- free(ctl->name);
+ free(ctl->name);
ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "name", NULL));
if (!ro) {
@@ -577,8 +576,7 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
maxname = virConnectNumOfDefinedDomains(ctl->conn);
if (maxname < 0) {
vshError(ctl, FALSE, "%s", _("Failed to list inactive
domains"));
- if (ids)
- free(ids);
+ free(ids);
return FALSE;
}
if (maxname) {
@@ -586,8 +584,7 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
if ((maxname = virConnectListDefinedDomains(ctl->conn, names, maxname))
< 0) {
vshError(ctl, FALSE, "%s", _("Failed to list inactive
domains"));
- if (ids)
- free(ids);
+ free(ids);
free(names);
return FALSE;
}
@@ -639,10 +636,8 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
virDomainFree(dom);
free(names[i]);
}
- if (ids)
- free(ids);
- if (names)
- free(names);
+ free(ids);
+ free(names);
return TRUE;
}
@@ -1217,8 +1212,7 @@ cmdSchedinfo(vshControl * ctl, vshCmd * cmd)
}
}
cleanup:
- if (params)
- free(params);
+ free(params);
virDomainFree(dom);
return ret_val;
}
@@ -2513,8 +2507,7 @@ cmdNetworkList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
maxinactive = virConnectNumOfDefinedNetworks(ctl->conn);
if (maxinactive < 0) {
vshError(ctl, FALSE, "%s", _("Failed to list inactive
networks"));
- if (activeNames)
- free(activeNames);
+ free(activeNames);
return FALSE;
}
if (maxinactive) {
@@ -2522,8 +2515,7 @@ cmdNetworkList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
if ((maxinactive = virConnectListDefinedNetworks(ctl->conn, inactiveNames,
maxinactive)) < 0) {
vshError(ctl, FALSE, "%s", _("Failed to list inactive
networks"));
- if (activeNames)
- free(activeNames);
+ free(activeNames);
free(inactiveNames);
return FALSE;
}
@@ -2581,10 +2573,8 @@ cmdNetworkList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
virNetworkFree(network);
free(inactiveNames[i]);
}
- if (activeNames)
- free(activeNames);
- if (inactiveNames)
- free(inactiveNames);
+ free(activeNames);
+ free(inactiveNames);
return TRUE;
}
@@ -3230,10 +3220,8 @@ cmdAttachInterface(vshControl * ctl, vshCmd * cmd)
cleanup:
if (dom)
virDomainFree(dom);
- if (buf)
- free(buf);
- if (tmp)
- free(tmp);
+ free(buf);
+ free(tmp);
return ret;
}
@@ -3516,10 +3504,8 @@ cmdAttachDisk(vshControl * ctl, vshCmd * cmd)
cleanup:
if (dom)
virDomainFree(dom);
- if (buf)
- free(buf);
- if (tmp)
- free(tmp);
+ free(buf);
+ free(tmp);
return ret;
}
@@ -3868,8 +3854,7 @@ vshCommandOptFree(vshCmdOpt * arg)
a = a->next;
- if (tmp->data)
- free(tmp->data);
+ free(tmp->data);
free(tmp);
}
}
@@ -4267,7 +4252,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
c->next = NULL;
if (!vshCommandCheckOpts(ctl, c)) {
- if(c) free(c);
+ free(c);
goto syntaxError;
}
@@ -4286,8 +4271,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
vshCommandFree(ctl->cmd);
if (first)
vshCommandOptFree(first);
- if (tkdata)
- free(tkdata);
+ free(tkdata);
return FALSE;
}
@@ -4791,8 +4775,7 @@ static int
vshDeinit(vshControl * ctl)
{
vshCloseLogFile(ctl);
- if (ctl->name)
- free(ctl->name);
+ free(ctl->name);
if (ctl->conn) {
if (virConnectClose(ctl->conn) != 0) {
ctl->conn = NULL; /* prevent recursive call from vshError() */
diff --git a/src/virterror.c b/src/virterror.c
index 0c0423b..bf4062d 100644
--- a/src/virterror.c
+++ b/src/virterror.c
@@ -109,14 +109,10 @@ virResetError(virErrorPtr err)
{
if (err == NULL)
return;
- if (err->message != NULL)
- free(err->message);
- if (err->str1 != NULL)
- free(err->str1);
- if (err->str2 != NULL)
- free(err->str2);
- if (err->str3 != NULL)
- free(err->str3);
+ free(err->message);
+ free(err->str1);
+ free(err->str2);
+ free(err->str3);
memset(err, 0, sizeof(virError));
}
diff --git a/src/xen_internal.c b/src/xen_internal.c
index 2ca1052..133c253 100644
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -1680,8 +1680,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu,
op.u.setvcpumapd5.cpumap.nr_cpus = nr_cpus;
}
ret = xenHypervisorDoV2Dom(handle, &op);
- if (new)
- free(new);
+ free(new);
if (unlock_pages(cpumap, maplen) < 0) {
virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen);
@@ -2056,15 +2055,13 @@ xenHypervisorInit(void)
virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL);
close(fd);
in_init = 0;
- if (ipt)
- free(ipt);
+ free(ipt);
return(-1);
done:
close(fd);
in_init = 0;
- if (ipt)
- free(ipt);
+ free(ipt);
return(0);
}
diff --git a/src/xen_unified.c b/src/xen_unified.c
index 187b7f5..d46e63b 100644
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -200,12 +200,9 @@ xenDomainUsedCpus(virDomainPtr dom)
}
done:
- if (cpulist != NULL)
- free(cpulist);
- if (cpumap != NULL)
- free(cpumap);
- if (cpuinfo != NULL)
- free(cpuinfo);
+ free(cpulist);
+ free(cpumap);
+ free(cpuinfo);
return(res);
}
@@ -912,9 +909,8 @@ xenUnifiedDomainDumpXML (virDomainPtr dom, int flags)
char *cpus, *res;
cpus = xenDomainUsedCpus(dom);
res = xenDaemonDomainDumpXML(dom, flags, cpus);
- if (cpus != NULL)
free(cpus);
- return(res);
+ return(res);
}
if (priv->opened[XEN_UNIFIED_PROXY_OFFSET])
return xenProxyDomainDumpXML(dom, flags);
diff --git a/src/xend_internal.c b/src/xend_internal.c
index a9fc332..61af69b 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -620,8 +620,7 @@ xend_op_ext2(virConnectPtr xend, const char *path, char *error,
}
ret = http2unix(xend, xend_post(xend, path, buf.content, error, n_error));
- if (buf.content != NULL)
- free(buf.content);
+ free(buf.content);
return ret;
}
@@ -1640,10 +1639,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
virBufferAdd(&buf, " </disk>\n", 12);
bad_parse:
- if (drvName)
- free(drvName);
- if (drvType)
- free(drvType);
+ free(drvName);
+ free(drvType);
} else if (sexpr_lookup(node, "device/vif")) {
const char *tmp2;
tmp2 = sexpr_node(node, "device/vif/script");
@@ -1809,8 +1806,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
return (buf.content);
error:
- if (buf.content != NULL)
- free(buf.content);
+ free(buf.content);
return (NULL);
}
@@ -2809,7 +2805,6 @@ xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids)
}
error:
- if (root != NULL)
sexpr_free(root);
return(ret);
}
@@ -2843,7 +2838,6 @@ xenDaemonNumOfDomains(virConnectPtr conn)
}
error:
- if (root != NULL)
sexpr_free(root);
return(ret);
}
@@ -2877,8 +2871,7 @@ xenDaemonLookupByID(virConnectPtr conn, int id) {
return (ret);
error:
- if (name != NULL)
- free(name);
+ free(name);
return (NULL);
}
@@ -3152,10 +3145,8 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, priv->xendConfigVersion);
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, "domain");
- if (sexpr != NULL)
- free(sexpr);
- if (name != NULL)
- free(name);
+ free(sexpr);
+ free(name);
return (NULL);
}
@@ -3187,8 +3178,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
xenDaemonDomainDestroy(dom);
virUnrefDomain(dom);
}
- if (name != NULL)
- free(name);
+ free(name);
return (NULL);
}
@@ -3228,8 +3218,7 @@ xenDaemonAttachDevice(virDomainPtr domain, const char *xml)
str = virDomainGetOSType(domain);
if (strcmp(str, "linux"))
hvm = 1;
- if (str)
- free(str);
+ free(str);
sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
if (sexpr == NULL)
return (-1);
@@ -3460,10 +3449,8 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const
char *xmlDesc) {
sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, priv->xendConfigVersion);
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, "domain");
- if (sexpr != NULL)
- free(sexpr);
- if (name != NULL)
- free(name);
+ free(sexpr);
+ free(name);
return (NULL);
}
@@ -3482,8 +3469,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char
*xmlDesc) {
return (dom);
error:
- if (name != NULL)
- free(name);
+ free(name);
return (NULL);
}
int xenDaemonDomainCreate(virDomainPtr domain)
@@ -3558,8 +3544,7 @@ xenDaemonNumOfDefinedDomains(virConnectPtr conn)
}
error:
- if (root != NULL)
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
@@ -3591,8 +3576,7 @@ int xenDaemonListDefinedDomains(virConnectPtr conn, char **const
names, int maxn
}
error:
- if (root != NULL)
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
diff --git a/src/xm_internal.c b/src/xm_internal.c
index 6b502d0..a1317c4 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1865,8 +1865,7 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node,
int hvm) {
}
cleanup:
- if (bridge != NULL)
- free(bridge);
+ free(bridge);
if (mac != NULL)
xmlFree(mac);
if (source != NULL)
@@ -2238,8 +2237,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
if (!vif)
goto error;
if (!(thisVif = malloc(sizeof(*thisVif)))) {
- if (vif)
- free(vif);
+ free(vif);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
@@ -2410,8 +2408,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char
*xml) {
return (ret);
error:
- if (entry)
- free(entry);
+ free(entry);
if (conf)
virConfFree(conf);
return (NULL);
diff --git a/src/xml.c b/src/xml.c
index c698889..a546002 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -397,14 +397,12 @@ virParseXenCpuTopology(virConnectPtr conn, virBufferPtr xml,
parse_error:
virXMLError(conn, VIR_ERR_XEN_CALL, _("topology syntax error"), 0);
error:
- if (cpuset != NULL)
- free(cpuset);
+ free(cpuset);
return (-1);
memory_error:
- if (cpuset != NULL)
- free(cpuset);
+ free(cpuset);
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return (-1);
}
@@ -1066,16 +1064,14 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node,
if (str != NULL && !strcmp(str, "localtime")) {
virBufferAdd(buf, "(localtime 1)", 13);
}
- if (str)
- free(str);
+ free(str);
virBufferAdd(buf, "))", 2);
return (0);
error:
- if (nodes)
- free(nodes);
+ free(nodes);
return (-1);
}
@@ -1723,8 +1719,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char
**name,
vcpus, xendConfigVersion);
}
- if (str != NULL)
- free(str);
+ free(str);
if (res != 0)
goto error;
@@ -1797,8 +1792,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char
**name,
return (buf.content);
error:
- if (nam != NULL)
- free(nam);
+ free(nam);
if (name != NULL)
*name = NULL;
if (ctxt != NULL)
@@ -1807,8 +1801,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char
**name,
xmlFreeDoc(xml);
if (pctxt != NULL)
xmlFreeParserCtxt(pctxt);
- if (buf.content != NULL)
- free(buf.content);
+ free(buf.content);
return (NULL);
}
diff --git a/src/xmlrpc.c b/src/xmlrpc.c
index b433ef5..f956f0d 100644
--- a/src/xmlrpc.c
+++ b/src/xmlrpc.c
@@ -115,8 +115,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalInteger(xmlNodePtr node)
if (ret && value)
ret->value.integer = atoi(value);
- if (value)
- free(value);
+ free(value);
return ret;
}
@@ -131,8 +130,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalBoolean(xmlNodePtr node)
ret->value.boolean = true;
else
ret->value.boolean = false;
- if (value)
- free(value);
+ free(value);
return ret;
}
@@ -143,8 +141,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalDouble(xmlNodePtr node)
if (ret && value)
ret->value.real = atof(value);
- if (value)
- free(value);
+ free(value);
return ret;
}
@@ -198,8 +195,7 @@ static xmlRpcValueDictElementPtr
xmlRpcValueUnmarshalDictElement(xmlNodePtr node
ret->value = xmlRpcValueUnmarshal(cur);
} else {
xmlRpcError(VIR_ERR_XML_ERROR, _("unexpected dict node"), 0);
- if (ret->name)
- free(ret->name);
+ free(ret->name);
if (ret->value)
xmlRpcValueFree(ret->value);
free(ret);
@@ -679,12 +675,8 @@ xmlRpcContextPtr xmlRpcContextNew(const char *uri)
void xmlRpcContextFree(xmlRpcContextPtr context)
{
if (context) {
- if (context->uri)
- free(context->uri);
-
- if (context->faultMessage)
- free(context->faultMessage);
-
+ free(context->uri);
+ free(context->faultMessage);
free(context);
}
}
diff --git a/src/xs_internal.c b/src/xs_internal.c
index 726af30..1dbbba6 100644
--- a/src/xs_internal.c
+++ b/src/xs_internal.c
@@ -635,9 +635,7 @@ xenStoreLookupByName(virConnectPtr conn, const char *name)
ret->id = id;
done:
- if (xenddomain != NULL)
free(xenddomain);
- if (idlist != NULL)
free(idlist);
return(ret);
diff --git a/tests/testutils.c b/tests/testutils.c
index 1141edb..4fea6b6 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -83,8 +83,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void
*data), const
else
fprintf(stderr, "%-50s ... FAILED\n", title);
- if (ts)
- free(ts);
+ free(ts);
return ret;
}
diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index dd1c386..bf9ce07 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -62,8 +62,7 @@ static int testCompareFiles(const char *hostmachine,
fail:
- if (actualxml)
- free(actualxml);
+ free(actualxml);
if (fp1)
fclose(fp1);
if (fp2)
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index f49ca6c..51f4b67 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -153,8 +153,7 @@ static int testCompareFormatXML(const char *xmcfg_rel, const char
*xml_rel,
fail:
if (conf)
virConfFree(conf);
- if (gotxml)
- free(gotxml);
+ free(gotxml);
if (conn) {
conn->privateData = old_priv;
--
1.5.4.rc3.14.g44397