hypervSerializeEmbeddedParam(hypervParamPtr p, const char *resourceUri,
WsXmlNodeH *methodNode)
{
- int result = -1;
WsXmlNodeH xmlNodeInstance = NULL,
xmlNodeProperty = NULL,
xmlNodeParam = NULL,
xmlNodeArray = NULL;
- WsXmlDocH xmlDocTemp = NULL,
- xmlDocCdata = NULL;
- char *cdataContent = NULL;
+ g_auto(WsXmlDocH) xmlDocTemp = NULL;
+ g_auto(WsXmlDocH) xmlDocCdata = NULL;
+ g_autofree char *cdataContent = NULL;
xmlNodePtr xmlNodeCdata = NULL;
hypervWmiClassInfoPtr classInfo = p->embedded.info;
- virHashKeyValuePairPtr items = NULL;
+ g_autofree virHashKeyValuePairPtr items = NULL;
hypervCimTypePtr property = NULL;
ssize_t numKeys = -1;
int len = 0, i = 0;
NULL))) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not add child node %s"),
p->embedded.name);
- goto cleanup;
+ return -1;
}
/* create the temp xml doc */
if (!(xmlDocTemp = ws_xml_create_doc(NULL, "INSTANCE"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create temporary xml doc"));
- goto cleanup;
+ return -1;
}
if (!(xmlNodeInstance = xml_parser_get_root(xmlDocTemp))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not get temp xml doc root"));
- goto cleanup;
+ return -1;
}
/* add CLASSNAME node to INSTANCE node */
classInfo->name))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add attribute to node"));
- goto cleanup;
+ return -1;
}
/* retrieve parameters out of hash table */
if (!items) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not read embedded param hash table"));
- goto cleanup;
+ return -1;
}
/* Add the parameters */
&property) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not read type information"));
- goto cleanup;
+ return -1;
}
if (!(xmlNodeProperty = ws_xml_add_child(xmlNodeInstance, NULL,
NULL))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add child to XML node"));
- goto cleanup;
+ return -1;
}
if (!(ws_xml_add_node_attr(xmlNodeProperty, NULL, "NAME", name))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add attribute to XML node"));
- goto cleanup;
+ return -1;
}
if (!(ws_xml_add_node_attr(xmlNodeProperty, NULL, "TYPE", property->type))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add attribute to XML node"));
- goto cleanup;
+ return -1;
}
/* If this attribute is an array, add VALUE.ARRAY node */
"VALUE.ARRAY", NULL))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add child to XML node"));
- goto cleanup;
+ return -1;
}
}
NULL, "VALUE", value))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add child to XML node"));
- goto cleanup;
+ return -1;
}
xmlNodeArray = NULL;
(xmlChar *)cdataContent, len))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create CDATA element"));
- goto cleanup;
+ return -1;
}
/*
if (!(xmlAddChild((xmlNodePtr)(void *)xmlNodeParam, xmlNodeCdata))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not add CDATA to doc root"));
- goto cleanup;
+ return -1;
}
/* we did it! */
- result = 0;
-
- cleanup:
- VIR_FREE(items);
- ws_xml_destroy_doc(xmlDocCdata);
- ws_xml_destroy_doc(xmlDocTemp);
- ws_xml_free_memory(cdataContent);
- return result;
+ return 0;
}