[libvirt PATCH] All pointers to virXMLPropString() use g_autofree.
All modified functions are similar, in all cases "cleanup" label is removed, along with all the "goto" calls. Signed-off-by: Nicolas Brignone --- src/conf/device_conf.c | 183 + 1 file changed, 56 insertions(+), 127 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 7d48a3f..9fa6141 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -208,45 +208,43 @@ int virPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddressPtr addr) { -char *domain, *slot, *bus, *function, *multi; xmlNodePtr cur; xmlNodePtr zpci = NULL; -int ret = -1; memset(addr, 0, sizeof(*addr)); -domain = virXMLPropString(node, "domain"); -bus = virXMLPropString(node, "bus"); -slot = virXMLPropString(node, "slot"); -function = virXMLPropString(node, "function"); -multi= virXMLPropString(node, "multifunction"); +g_autofree char *domain = virXMLPropString(node, "domain"); +g_autofree char *bus = virXMLPropString(node, "bus"); +g_autofree char *slot = virXMLPropString(node, "slot"); +g_autofree char *function = virXMLPropString(node, "function"); +g_autofree char *multi= virXMLPropString(node, "multifunction"); if (domain && virStrToLong_uip(domain, NULL, 0, &addr->domain) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'domain' attribute")); -goto cleanup; +return -1; } if (bus && virStrToLong_uip(bus, NULL, 0, &addr->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'bus' attribute")); -goto cleanup; +return -1; } if (slot && virStrToLong_uip(slot, NULL, 0, &addr->slot) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'slot' attribute")); -goto cleanup; +return -1; } if (function && virStrToLong_uip(function, NULL, 0, &addr->function) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'function' attribute")); -goto cleanup; +return -1; } if (multi && @@ -254,11 +252,11 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown value '%s' for 'multifunction' attribute"), multi); -goto cleanup; +return -1; } if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, true)) -goto cleanup; +return -1; cur = node->children; while (cur) { @@ -270,17 +268,9 @@ virPCIDeviceAddressParseXML(xmlNodePtr node, } if (zpci && virZPCIDeviceAddressParseXML(zpci, addr) < 0) -goto cleanup; +return -1; -ret = 0; - - cleanup: -VIR_FREE(domain); -VIR_FREE(bus); -VIR_FREE(slot); -VIR_FREE(function); -VIR_FREE(multi); -return ret; +return 0; } void @@ -309,187 +299,149 @@ int virDomainDeviceCCWAddressParseXML(xmlNodePtr node, virDomainDeviceCCWAddressPtr addr) { -int ret = -1; -char *cssid; -char *ssid; -char *devno; - memset(addr, 0, sizeof(*addr)); -cssid = virXMLPropString(node, "cssid"); -ssid = virXMLPropString(node, "ssid"); -devno = virXMLPropString(node, "devno"); +g_autofree char *cssid = virXMLPropString(node, "cssid"); +g_autofree char *ssid = virXMLPropString(node, "ssid"); +g_autofree char *devno = virXMLPropString(node, "devno"); if (cssid && ssid && devno) { if (cssid && virStrToLong_uip(cssid, NULL, 0, &addr->cssid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'cssid' attribute")); -goto cleanup; +return -1; } if (ssid && virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'ssid' attribute")); -goto cleanup; +return -1; } if (devno && virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) {
[libvirt PATCH 1/1] conf: move graphics validation checks out of *ParseXML function.
Existing virDomainDefPostParseGraphics function seems to be the right place to put this validations. After moving this validation, one less argument is needed in virDomainGraphicsListenDefParseXML, so removing the "graphics" argument from the function signature. Signed-off-by: Nicolas Brignone --- src/conf/domain_conf.c | 66 +++--- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8d328819..3228f12a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4804,13 +4804,15 @@ virDomainDefPostParseTimer(virDomainDefPtr def) } -static void +static int virDomainDefPostParseGraphics(virDomainDef *def) { size_t i; for (i = 0; i < def->ngraphics; i++) { +size_t j; virDomainGraphicsDefPtr graphics = def->graphics[i]; +const char *graphicsType = virDomainGraphicsTypeToString(graphics->type); /* If spice graphics is configured without ports and with autoport='no' * then we start qemu with Spice to not listen anywhere. Let's convert @@ -4826,8 +4828,38 @@ virDomainDefPostParseGraphics(virDomainDef *def) VIR_FREE(glisten->address); glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE; } + +} + +for (j = 0; j < graphics->nListens; j++) { +virDomainGraphicsListenDefPtr glisten = virDomainGraphicsGetListen(graphics, j); +switch (glisten->type) { +case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: +if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC && +graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, +_("listen type 'socket' is not available for " +"graphics type '%s'"), graphicsType); +return -1; +} +break; +case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: +if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE && +graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, +_("listen type 'none' is not available for " +"graphics type '%s'"), graphicsType); +return -1; +} +break; +case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: +case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: +case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: +break; +} } } +return 0; } @@ -5915,7 +5947,8 @@ virDomainDefPostParseCommon(virDomainDefPtr def, /* clean up possibly duplicated metadata entries */ virXMLNodeSanitizeNamespaces(def->metadata); -virDomainDefPostParseGraphics(def); +if (virDomainDefPostParseGraphics(def) < 0) +return -1; if (virDomainDefPostParseCPU(def) < 0) return -1; @@ -14140,13 +14173,11 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, */ static int virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, - virDomainGraphicsDefPtr graphics, xmlNodePtr node, xmlNodePtr parent, unsigned int flags) { int ret = -1; -const char *graphicsType = virDomainGraphicsTypeToString(graphics->type); int tmp, typeVal; g_autofree char *type = virXMLPropString(node, "type"); g_autofree char *address = virXMLPropString(node, "address"); @@ -14175,31 +14206,6 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, } def->type = typeVal; -switch (def->type) { -case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: -if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC && -graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("listen type 'socket' is not available for " - "graphics type '%s'"), graphicsType); -goto error; -} -break; -case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: -if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE && -graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("li
[libvirt PATCH 0/1] Move graphics validation checks out of *ParseXML function.
- Based on https://gitlab.com/libvirt/libvirt/-/issues/7 specific recommendation about moving validation checks into *PostParse. - syntax-check and tests passing verified. - I Considered creating a new "Validate" function, but according to the issue I used the PostParse Function. Nicolas Brignone (1): conf: move graphics validation checks out of *ParseXML function. src/conf/domain_conf.c | 66 +++--- 1 file changed, 36 insertions(+), 30 deletions(-) -- 2.25.2