From: Francesco Romani Date: Fri, 9 Dec 2016 15:22:03 +0000 (+0100) Subject: virt plugin: fix error path in lv_domain_get_tag X-Git-Tag: collectd-5.8.0~276^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=756a1440c886c0571374187add8bc244a8cfb59a;p=collectd.git virt plugin: fix error path in lv_domain_get_tag Document the return value and fix the error path of lv_domain_get_tag Signed-off-by: Francesco Romani --- diff --git a/src/virt.c b/src/virt.c index 86f83ae8..d3012d92 100644 --- a/src/virt.c +++ b/src/virt.c @@ -740,12 +740,16 @@ static int lv_init(void) { return 0; } +/* + * returns 0 on success and <0 on error + */ static int lv_domain_get_tag(xmlXPathContextPtr xpath_ctx, const char *dom_name, char *dom_tag) { char xpath_str[BUFFER_MAX_LEN] = {'\0'}; xmlXPathObjectPtr xpath_obj = NULL; xmlNodePtr xml_node = NULL; - int err = -1; + int ret = -1; + int err; err = xmlXPathRegisterNs(xpath_ctx, (const xmlChar *)METADATA_VM_PARTITION_PREFIX, @@ -776,8 +780,7 @@ static int lv_domain_get_tag(xmlXPathContextPtr xpath_ctx, const char *dom_name, * from now on there is no real error, it's ok if a domain * doesn't have the metadata partition tag. */ - err = 0; - + ret = 0; if (xpath_obj->nodesetval == NULL || xpath_obj->nodesetval->nodeNr != 1) { DEBUG(PLUGIN_NAME " plugin: xmlXPathEval(%s) return nodeset size=%i " "expected=1 on domain %s", @@ -793,11 +796,16 @@ done: /* deregister to clean up */ err = xmlXPathRegisterNs(xpath_ctx, (const xmlChar *)METADATA_VM_PARTITION_PREFIX, NULL); - + if (err) { + /* we can't really recover here */ + ERROR(PLUGIN_NAME + " plugin: deregistration of namespace %s failed for domain %s", + METADATA_VM_PARTITION_PREFIX, dom_name); + } if (xpath_obj) xmlXPathFreeObject(xpath_obj); - return err; + return ret; } static int is_known_tag(const char *dom_tag) {