提交 babb57aa 编写于 作者: J John Ferlan

Resolve valgrind error in virNetDevVlanParse()

Commit '861d4056' introduced the following:

TEST: networkxml2xmltest
      ..................                       18  OK
==25504== 7 bytes in 1 blocks are definitely lost in loss record 5 of 23
==25504==    at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==25504==    by 0x37C1085D71: strdup (strdup.c:42)
==25504==    by 0x4CB835F: virStrdup (virstring.c:546)
==25504==    by 0x4CC5179: virXPathString (virxml.c:90)
==25504==    by 0x4CC75C2: virNetDevVlanParse (netdev_vlan_conf.c:78)
==25504==    by 0x4CF928A: virNetworkPortGroupParseXML (network_conf.c:1555)
==25504==    by 0x4CFE385: virNetworkDefParseXML (network_conf.c:2049)
==25504==    by 0x4D0113B: virNetworkDefParseNode (network_conf.c:2273)
==25504==    by 0x4D01254: virNetworkDefParse (network_conf.c:2234)
==25504==    by 0x401E80: testCompareXMLToXMLHelper (networkxml2xmltest.c:32)
==25504==    by 0x402D4F: virtTestRun (testutils.c:158)
==25504==    by 0x401CE9: mymain (networkxml2xmltest.c:110)
==25504==
PASS: networkxml2xmltest

Also changed the label from error to cleanup and adjusted code since it's
all one exit path
上级 dc8614d7
...@@ -45,18 +45,18 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de ...@@ -45,18 +45,18 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
nTags = virXPathNodeSet("./tag", ctxt, &tagNodes); nTags = virXPathNodeSet("./tag", ctxt, &tagNodes);
if (nTags < 0) if (nTags < 0)
goto error; goto cleanup;
if (nTags == 0) { if (nTags == 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing tag id - each <vlan> must have " _("missing tag id - each <vlan> must have "
"at least one <tag id='n'/> subelement")); "at least one <tag id='n'/> subelement"));
goto error; goto cleanup;
} }
if (VIR_ALLOC_N(def->tag, nTags) < 0) { if (VIR_ALLOC_N(def->tag, nTags) < 0) {
virReportOOMError(); virReportOOMError();
goto error; goto cleanup;
} }
def->nativeMode = 0; def->nativeMode = 0;
...@@ -68,18 +68,18 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de ...@@ -68,18 +68,18 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
if (virXPathULong("string(./@id)", ctxt, &id) < 0) { if (virXPathULong("string(./@id)", ctxt, &id) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing or invalid vlan tag id attribute")); _("missing or invalid vlan tag id attribute"));
goto error; goto cleanup;
} }
if (id > 4095) { if (id > 4095) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("vlan tag id %lu too large (maximum 4095)"), id); _("vlan tag id %lu too large (maximum 4095)"), id);
goto error; goto cleanup;
} }
if ((nativeMode = virXPathString("string(./@nativeMode)", ctxt))) { if ((nativeMode = virXPathString("string(./@nativeMode)", ctxt))) {
if (def->nativeMode != 0) { if (def->nativeMode != 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("duplicate native vlan setting")); _("duplicate native vlan setting"));
goto error; goto cleanup;
} }
if ((def->nativeMode if ((def->nativeMode
= virNativeVlanModeTypeFromString(nativeMode)) <= 0) { = virNativeVlanModeTypeFromString(nativeMode)) <= 0) {
...@@ -87,8 +87,9 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de ...@@ -87,8 +87,9 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
_("Invalid \"nativeMode='%s'\" " _("Invalid \"nativeMode='%s'\" "
"in vlan <tag> element"), "in vlan <tag> element"),
nativeMode); nativeMode);
goto error; goto cleanup;
} }
VIR_FREE(nativeMode);
def->nativeTag = id; def->nativeTag = id;
} }
def->tag[ii] = id; def->tag[ii] = id;
...@@ -110,29 +111,30 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de ...@@ -110,29 +111,30 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("invalid \"trunk='%s'\" in <vlan> - trunk='yes' " _("invalid \"trunk='%s'\" in <vlan> - trunk='yes' "
"is required for more than one vlan tag"), trunk); "is required for more than one vlan tag"), trunk);
goto error; goto cleanup;
} }
if (def->nativeMode != 0) { if (def->nativeMode != 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid configuration in <vlan> - \"trunk='no'\" is " _("invalid configuration in <vlan> - \"trunk='no'\" is "
"not allowed with a native vlan id")); "not allowed with a native vlan id"));
goto error; goto cleanup;
} }
/* allow (but discard) "trunk='no' if there is a single tag */ /* allow (but discard) "trunk='no' if there is a single tag */
if (STRCASENEQ(trunk, "no")) { if (STRCASENEQ(trunk, "no")) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("invalid \"trunk='%s'\" in <vlan> " _("invalid \"trunk='%s'\" in <vlan> "
"- must be yes or no"), trunk); "- must be yes or no"), trunk);
goto error; goto cleanup;
} }
} }
} }
ret = 0; ret = 0;
error: cleanup:
ctxt->node = save; ctxt->node = save;
VIR_FREE(tagNodes); VIR_FREE(tagNodes);
VIR_FREE(trunk); VIR_FREE(trunk);
VIR_FREE(nativeMode);
if (ret < 0) if (ret < 0)
virNetDevVlanClear(def); virNetDevVlanClear(def);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册