提交 b6a8d303 编写于 作者: L Laine Stump

conf: take advantage of VIR_AUTOPTR for virNetworkPortDefPtr

define a VIR_DEFINE_AUTOPTR_FUNC() to autofree virNetworkPortDefs, and
convert all uses of virNetworkPortDefPtr that are appropriate to use
it.

This coincidentally fixes multiple potential memory leaks (in failure
cases) in networkPortCreateXML()
Signed-off-by: NLaine Stump <laine@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 76fabfb2
...@@ -30671,7 +30671,7 @@ virNetworkPortDefPtr ...@@ -30671,7 +30671,7 @@ virNetworkPortDefPtr
virDomainNetDefToNetworkPort(virDomainDefPtr dom, virDomainNetDefToNetworkPort(virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkPortDefPtr port; VIR_AUTOPTR(virNetworkPortDef) port = NULL;
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -30686,34 +30686,30 @@ virDomainNetDefToNetworkPort(virDomainDefPtr dom, ...@@ -30686,34 +30686,30 @@ virDomainNetDefToNetworkPort(virDomainDefPtr dom,
if (virUUIDGenerate(port->uuid) < 0) { if (virUUIDGenerate(port->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto error; return NULL;
} }
memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN);
if (VIR_STRDUP(port->ownername, dom->name) < 0) if (VIR_STRDUP(port->ownername, dom->name) < 0)
goto error; return NULL;
if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0) if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0)
goto error; return NULL;
memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN); memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN);
if (virNetDevVPortProfileCopy(&port->virtPortProfile, iface->virtPortProfile) < 0) if (virNetDevVPortProfileCopy(&port->virtPortProfile, iface->virtPortProfile) < 0)
goto error; return NULL;
if (virNetDevBandwidthCopy(&port->bandwidth, iface->bandwidth) < 0) if (virNetDevBandwidthCopy(&port->bandwidth, iface->bandwidth) < 0)
goto error; return NULL;
if (virNetDevVlanCopy(&port->vlan, &iface->vlan) < 0) if (virNetDevVlanCopy(&port->vlan, &iface->vlan) < 0)
goto error; return NULL;
port->trustGuestRxFilters = iface->trustGuestRxFilters; port->trustGuestRxFilters = iface->trustGuestRxFilters;
return port; VIR_RETURN_PTR(port);
error:
virNetworkPortDefFree(port);
return NULL;
} }
int int
...@@ -30834,7 +30830,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30834,7 +30830,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virDomainActualNetDefPtr actual; virDomainActualNetDefPtr actual;
virNetworkPortDefPtr port; VIR_AUTOPTR(virNetworkPortDef) port = NULL;
if (!iface->data.network.actual) { if (!iface->data.network.actual) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -30859,15 +30855,15 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30859,15 +30855,15 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
if (virUUIDGenerate(port->uuid) < 0) { if (virUUIDGenerate(port->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto error; return NULL;
} }
memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN);
if (VIR_STRDUP(port->ownername, dom->name) < 0) if (VIR_STRDUP(port->ownername, dom->name) < 0)
goto error; return NULL;
if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0) if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0)
goto error; return NULL;
memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN); memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN);
...@@ -30876,7 +30872,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30876,7 +30872,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_NETWORK;
if (VIR_STRDUP(port->plug.bridge.brname, if (VIR_STRDUP(port->plug.bridge.brname,
actual->data.bridge.brname) < 0) actual->data.bridge.brname) < 0)
goto error; return NULL;
port->plug.bridge.macTableManager = actual->data.bridge.macTableManager; port->plug.bridge.macTableManager = actual->data.bridge.macTableManager;
break; break;
...@@ -30884,7 +30880,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30884,7 +30880,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE;
if (VIR_STRDUP(port->plug.bridge.brname, if (VIR_STRDUP(port->plug.bridge.brname,
actual->data.bridge.brname) < 0) actual->data.bridge.brname) < 0)
goto error; return NULL;
port->plug.bridge.macTableManager = actual->data.bridge.macTableManager; port->plug.bridge.macTableManager = actual->data.bridge.macTableManager;
break; break;
...@@ -30892,7 +30888,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30892,7 +30888,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_DIRECT; port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_DIRECT;
if (VIR_STRDUP(port->plug.direct.linkdev, if (VIR_STRDUP(port->plug.direct.linkdev,
actual->data.direct.linkdev) < 0) actual->data.direct.linkdev) < 0)
goto error; return NULL;
port->plug.direct.mode = actual->data.direct.mode; port->plug.direct.mode = actual->data.direct.mode;
break; break;
...@@ -30903,7 +30899,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30903,7 +30899,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Actual interface '%s' hostdev was not a PCI device"), _("Actual interface '%s' hostdev was not a PCI device"),
iface->ifname); iface->ifname);
goto error; return NULL;
} }
port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed); port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr; port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
...@@ -30929,7 +30925,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30929,7 +30925,7 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
default: default:
virReportEnumRangeError(virDomainHostdevSubsysPCIBackendType, virReportEnumRangeError(virDomainHostdevSubsysPCIBackendType,
actual->data.hostdev.def.source.subsys.u.pci.backend); actual->data.hostdev.def.source.subsys.u.pci.backend);
goto error; return NULL;
} }
break; break;
...@@ -30945,31 +30941,27 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom, ...@@ -30945,31 +30941,27 @@ virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unexpected network port type %s"), _("Unexpected network port type %s"),
virDomainNetTypeToString(virDomainNetGetActualType(iface))); virDomainNetTypeToString(virDomainNetGetActualType(iface)));
goto error; return NULL;
case VIR_DOMAIN_NET_TYPE_LAST: case VIR_DOMAIN_NET_TYPE_LAST:
default: default:
virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); virReportEnumRangeError(virNetworkPortPlugType, port->plugtype);
goto error; return NULL;
} }
if (virNetDevVPortProfileCopy(&port->virtPortProfile, actual->virtPortProfile) < 0) if (virNetDevVPortProfileCopy(&port->virtPortProfile, actual->virtPortProfile) < 0)
goto error; return NULL;
if (virNetDevBandwidthCopy(&port->bandwidth, actual->bandwidth) < 0) if (virNetDevBandwidthCopy(&port->bandwidth, actual->bandwidth) < 0)
goto error; return NULL;
if (virNetDevVlanCopy(&port->vlan, &actual->vlan) < 0) if (virNetDevVlanCopy(&port->vlan, &actual->vlan) < 0)
goto error; return NULL;
port->class_id = actual->class_id; port->class_id = actual->class_id;
port->trustGuestRxFilters = actual->trustGuestRxFilters; port->trustGuestRxFilters = actual->trustGuestRxFilters;
return port; VIR_RETURN_PTR(port);
error:
virNetworkPortDefFree(port);
return NULL;
} }
...@@ -30979,60 +30971,47 @@ virDomainNetCreatePort(virConnectPtr conn, ...@@ -30979,60 +30971,47 @@ virDomainNetCreatePort(virConnectPtr conn,
virDomainNetDefPtr iface, virDomainNetDefPtr iface,
unsigned int flags) unsigned int flags)
{ {
virNetworkPtr net = NULL; virErrorPtr save_err;
int ret = -1; VIR_AUTOUNREF(virNetworkPtr) net = NULL;
virNetworkPortDefPtr portdef = NULL; VIR_AUTOPTR(virNetworkPortDef) portdef = NULL;
virNetworkPortPtr port = NULL; VIR_AUTOUNREF(virNetworkPortPtr) port = NULL;
char *portxml = NULL; VIR_AUTOFREE(char *) portxml = NULL;
virErrorPtr saved;
if (!(net = virNetworkLookupByName(conn, iface->data.network.name))) if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
return -1; return -1;
if (flags & VIR_NETWORK_PORT_CREATE_RECLAIM) { if (flags & VIR_NETWORK_PORT_CREATE_RECLAIM) {
if (!(portdef = virDomainNetDefActualToNetworkPort(dom, iface))) if (!(portdef = virDomainNetDefActualToNetworkPort(dom, iface)))
goto cleanup; return -1;
} else { } else {
if (!(portdef = virDomainNetDefToNetworkPort(dom, iface))) if (!(portdef = virDomainNetDefToNetworkPort(dom, iface)))
goto cleanup; return -1;
} }
if (!(portxml = virNetworkPortDefFormat(portdef))) if (!(portxml = virNetworkPortDefFormat(portdef)))
goto cleanup; return -1;
/* prepare to re-use portdef */
virNetworkPortDefFree(portdef); virNetworkPortDefFree(portdef);
portdef = NULL; portdef = NULL;
if (!(port = virNetworkPortCreateXML(net, portxml, flags))) if (!(port = virNetworkPortCreateXML(net, portxml, flags)))
goto cleanup; return -1;
/* prepare to re-use portxml */
VIR_FREE(portxml); VIR_FREE(portxml);
if (!(portxml = virNetworkPortGetXMLDesc(port, 0))) if (!(portxml = virNetworkPortGetXMLDesc(port, 0)) ||
goto deleteport; !(portdef = virNetworkPortDefParseString(portxml)) ||
virDomainNetDefActualFromNetworkPort(iface, portdef) < 0) {
if (!(portdef = virNetworkPortDefParseString(portxml))) virErrorPreserveLast(&save_err);
goto deleteport; virNetworkPortDelete(port, 0);
virErrorRestore(&save_err);
if (virDomainNetDefActualFromNetworkPort(iface, portdef) < 0) return -1;
goto deleteport; }
virNetworkPortGetUUID(port, iface->data.network.portid); virNetworkPortGetUUID(port, iface->data.network.portid);
return 0;
ret = 0;
cleanup:
virNetworkPortDefFree(portdef);
VIR_FREE(portxml);
virObjectUnref(port);
virObjectUnref(net);
return ret;
deleteport:
saved = virSaveLastError();
virNetworkPortDelete(port, 0);
virSetError(saved);
virFreeError(saved);
goto cleanup;
} }
int int
......
...@@ -1887,7 +1887,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, ...@@ -1887,7 +1887,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
int ret = -1; int ret = -1;
int rc; int rc;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virNetworkPortDefPtr portdef = NULL; VIR_AUTOPTR(virNetworkPortDef) portdef = NULL;
if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir))) if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
goto cleanup; goto cleanup;
...@@ -1925,6 +1925,5 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, ...@@ -1925,6 +1925,5 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_DIR_CLOSE(dh); VIR_DIR_CLOSE(dh);
virNetworkPortDefFree(portdef);
return ret; return ret;
} }
...@@ -75,7 +75,7 @@ virNetworkPortDefFree(virNetworkPortDefPtr def) ...@@ -75,7 +75,7 @@ virNetworkPortDefFree(virNetworkPortDefPtr def)
static virNetworkPortDefPtr static virNetworkPortDefPtr
virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
{ {
virNetworkPortDefPtr def; VIR_AUTOPTR(virNetworkPortDef) def = NULL;
VIR_AUTOFREE(char *) uuid = NULL; VIR_AUTOFREE(char *) uuid = NULL;
xmlNodePtr virtPortNode; xmlNodePtr virtPortNode;
xmlNodePtr vlanNode; xmlNodePtr vlanNode;
...@@ -96,19 +96,19 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -96,19 +96,19 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (!uuid) { if (!uuid) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network port has no uuid")); "%s", _("network port has no uuid"));
goto error; return NULL;
} }
if (virUUIDParse(uuid, def->uuid) < 0) { if (virUUIDParse(uuid, def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse UUID '%s'"), uuid); _("Unable to parse UUID '%s'"), uuid);
goto error; return NULL;
} }
def->ownername = virXPathString("string(./owner/name)", ctxt); def->ownername = virXPathString("string(./owner/name)", ctxt);
if (!def->ownername) { if (!def->ownername) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network port has no owner name")); "%s", _("network port has no owner name"));
goto error; return NULL;
} }
VIR_FREE(uuid); VIR_FREE(uuid);
...@@ -116,13 +116,13 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -116,13 +116,13 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (!uuid) { if (!uuid) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network port has no owner UUID")); "%s", _("network port has no owner UUID"));
goto error; return NULL;
} }
if (virUUIDParse(uuid, def->owneruuid) < 0) { if (virUUIDParse(uuid, def->owneruuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse UUID '%s'"), uuid); _("Unable to parse UUID '%s'"), uuid);
goto error; return NULL;
} }
def->group = virXPathString("string(./group)", ctxt); def->group = virXPathString("string(./group)", ctxt);
...@@ -130,19 +130,19 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -130,19 +130,19 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virtPortNode = virXPathNode("./virtualport", ctxt); virtPortNode = virXPathNode("./virtualport", ctxt);
if (virtPortNode && if (virtPortNode &&
(!(def->virtPortProfile = virNetDevVPortProfileParse(virtPortNode, 0)))) { (!(def->virtPortProfile = virNetDevVPortProfileParse(virtPortNode, 0)))) {
goto error; return NULL;
} }
mac = virXPathString("string(./mac/@address)", ctxt); mac = virXPathString("string(./mac/@address)", ctxt);
if (!mac) { if (!mac) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("network port has no mac")); "%s", _("network port has no mac"));
goto error; return NULL;
} }
if (virMacAddrParse(mac, &def->mac) < 0) { if (virMacAddrParse(mac, &def->mac) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse MAC '%s'"), mac); _("Unable to parse MAC '%s'"), mac);
goto error; return NULL;
} }
bandwidthNode = virXPathNode("./bandwidth", ctxt); bandwidthNode = virXPathNode("./bandwidth", ctxt);
...@@ -155,11 +155,11 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -155,11 +155,11 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (bandwidthNode && if (bandwidthNode &&
virNetDevBandwidthParse(&def->bandwidth, &def->class_id, virNetDevBandwidthParse(&def->bandwidth, &def->class_id,
bandwidthNode, true) < 0) bandwidthNode, true) < 0)
goto error; return NULL;
vlanNode = virXPathNode("./vlan", ctxt); vlanNode = virXPathNode("./vlan", ctxt);
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0) if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
goto error; return NULL;
trustGuestRxFilters trustGuestRxFilters
...@@ -170,7 +170,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -170,7 +170,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Invalid guest rx filters trust setting '%s' "), _("Invalid guest rx filters trust setting '%s' "),
trustGuestRxFilters); trustGuestRxFilters);
goto error; return NULL;
} }
} }
...@@ -191,7 +191,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -191,7 +191,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (!(def->plug.bridge.brname = virXPathString("string(./plug/@bridge)", ctxt))) { if (!(def->plug.bridge.brname = virXPathString("string(./plug/@bridge)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port bridge name")); _("Missing network port bridge name"));
goto error; return NULL;
} }
macmgr = virXPathString("string(./plug/@macTableManager)", ctxt); macmgr = virXPathString("string(./plug/@macTableManager)", ctxt);
if (macmgr && if (macmgr &&
...@@ -200,7 +200,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -200,7 +200,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Invalid macTableManager setting '%s' " _("Invalid macTableManager setting '%s' "
"in network port"), macmgr); "in network port"), macmgr);
goto error; return NULL;
} }
break; break;
...@@ -208,7 +208,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -208,7 +208,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (!(def->plug.direct.linkdev = virXPathString("string(./plug/@dev)", ctxt))) { if (!(def->plug.direct.linkdev = virXPathString("string(./plug/@dev)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port link device name")); _("Missing network port link device name"));
goto error; return NULL;
} }
mode = virXPathString("string(./plug/@mode)", ctxt); mode = virXPathString("string(./plug/@mode)", ctxt);
if (mode && if (mode &&
...@@ -216,7 +216,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -216,7 +216,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virNetDevMacVLanModeTypeFromString(mode)) < 0) { virNetDevMacVLanModeTypeFromString(mode)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Invalid mode setting '%s' in network port"), mode); _("Invalid mode setting '%s' in network port"), mode);
goto error; return NULL;
} }
break; break;
...@@ -227,7 +227,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -227,7 +227,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virTristateBoolTypeFromString(managed)) < 0) { virTristateBoolTypeFromString(managed)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Invalid managed setting '%s' in network port"), mode); _("Invalid managed setting '%s' in network port"), mode);
goto error; return NULL;
} }
driver = virXPathString("string(./plug/driver/@name)", ctxt); driver = virXPathString("string(./plug/driver/@name)", ctxt);
if (driver && if (driver &&
...@@ -235,31 +235,25 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -235,31 +235,25 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
virNetworkForwardDriverNameTypeFromString(driver)) <= 0) { virNetworkForwardDriverNameTypeFromString(driver)) <= 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port driver name")); _("Missing network port driver name"));
goto error; return NULL;
} }
if (!(addressNode = virXPathNode("./plug/address", ctxt))) { if (!(addressNode = virXPathNode("./plug/address", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port PCI address")); _("Missing network port PCI address"));
goto error; return NULL;
} }
if (virPCIDeviceAddressParseXML(addressNode, &def->plug.hostdevpci.addr) < 0) if (virPCIDeviceAddressParseXML(addressNode, &def->plug.hostdevpci.addr) < 0)
goto error; return NULL;
break; break;
case VIR_NETWORK_PORT_PLUG_TYPE_LAST: case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
default: default:
virReportEnumRangeError(virNetworkPortPlugType, def->plugtype); virReportEnumRangeError(virNetworkPortPlugType, def->plugtype);
goto error; return NULL;
} }
cleanup: VIR_RETURN_PTR(def);
return def;
error:
virNetworkPortDefFree(def);
def = NULL;
goto cleanup;
} }
......
...@@ -82,6 +82,7 @@ struct _virNetworkPortDef { ...@@ -82,6 +82,7 @@ struct _virNetworkPortDef {
void void
virNetworkPortDefFree(virNetworkPortDefPtr port); virNetworkPortDefFree(virNetworkPortDefPtr port);
VIR_DEFINE_AUTOPTR_FUNC(virNetworkPortDef, virNetworkPortDefFree);
virNetworkPortDefPtr virNetworkPortDefPtr
virNetworkPortDefParseNode(xmlDocPtr xml, virNetworkPortDefParseNode(xmlDocPtr xml,
......
...@@ -5560,7 +5560,7 @@ networkPortCreateXML(virNetworkPtr net, ...@@ -5560,7 +5560,7 @@ networkPortCreateXML(virNetworkPtr net,
virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkDriverStatePtr driver = networkGetDriver();
virNetworkObjPtr obj; virNetworkObjPtr obj;
virNetworkDefPtr def; virNetworkDefPtr def;
virNetworkPortDefPtr portdef = NULL; VIR_AUTOPTR(virNetworkPortDef) portdef = NULL;
virNetworkPortPtr ret = NULL; virNetworkPortPtr ret = NULL;
int rc; int rc;
...@@ -5610,13 +5610,13 @@ networkPortCreateXML(virNetworkPtr net, ...@@ -5610,13 +5610,13 @@ networkPortCreateXML(virNetworkPtr net,
virErrorPreserveLast(&save_err); virErrorPreserveLast(&save_err);
ignore_value(networkReleasePort(obj, portdef)); ignore_value(networkReleasePort(obj, portdef));
virNetworkPortDefFree(portdef);
virErrorRestore(&save_err); virErrorRestore(&save_err);
goto cleanup; goto cleanup;
} }
ret = virGetNetworkPort(net, portdef->uuid); ret = virGetNetworkPort(net, portdef->uuid);
portdef = NULL;
cleanup: cleanup:
virNetworkObjEndAPI(&obj); virNetworkObjEndAPI(&obj);
return ret; return ret;
......
...@@ -38,7 +38,7 @@ testCompareXMLToXMLFiles(const char *expected) ...@@ -38,7 +38,7 @@ testCompareXMLToXMLFiles(const char *expected)
{ {
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virNetworkPortDefPtr dev = NULL; VIR_AUTOPTR(virNetworkPortDef) dev = NULL;
if (!(dev = virNetworkPortDefParseFile(expected))) if (!(dev = virNetworkPortDefParseFile(expected)))
goto cleanup; goto cleanup;
...@@ -52,7 +52,6 @@ testCompareXMLToXMLFiles(const char *expected) ...@@ -52,7 +52,6 @@ testCompareXMLToXMLFiles(const char *expected)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual); VIR_FREE(actual);
virNetworkPortDefFree(dev);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册