summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <dan@berrange.com>2011-02-03 16:48:58 +0000
committerDaniel P. Berrange <dan@berrange.com>2011-02-03 16:48:58 +0000
commit26746f3b6f3ce9b46ee4cc982c6c8f139d246ea5 (patch)
treeb5295c9739a0452d9f30abdcaa12da0bd4c6dec5
parent7f2ef081e272eb217ca94bafaeda59a3cfc288b4 (diff)
downloadvirt-viewer-26746f3b6f3ce9b46ee4cc982c6c8f139d246ea5.tar.gz
virt-viewer-26746f3b6f3ce9b46ee4cc982c6c8f139d246ea5.tar.xz
virt-viewer-26746f3b6f3ce9b46ee4cc982c6c8f139d246ea5.zip
Avoid fetching XML document multiple times when extracting graphics
-rw-r--r--src/viewer.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/viewer.c b/src/viewer.c
index eb5f02d..617686f 100644
--- a/src/viewer.c
+++ b/src/viewer.c
@@ -610,9 +610,8 @@ static int viewer_matches_domain(VirtViewer *viewer,
return 0;
}
-static char * viewer_extract_xpath_string(virDomainPtr dom, const gchar *xpath)
+static char * viewer_extract_xpath_string(const gchar *xmldesc, const gchar *xpath)
{
- char *xmldesc = virDomainGetXMLDesc(dom, 0);
xmlDocPtr xml = NULL;
xmlParserCtxtPtr pctxt = NULL;
xmlXPathContextPtr ctxt = NULL;
@@ -626,7 +625,6 @@ static char * viewer_extract_xpath_string(virDomainPtr dom, const gchar *xpath)
xml = xmlCtxtReadDoc(pctxt, (const xmlChar *)xmldesc, "domain.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOWARNING);
- free(xmldesc);
if (!xml)
goto error;
@@ -798,10 +796,11 @@ static gboolean viewer_extract_connect_info(VirtViewer *viewer,
char *type = NULL;
char *xpath = NULL;
gboolean retval = FALSE;
+ char *xmldesc = virDomainGetXMLDesc(dom, 0);
viewer_connect_info_free(viewer);
- if ((type = viewer_extract_xpath_string(dom, "string(/domain/devices/graphics/@type)")) == NULL) {
+ if ((type = viewer_extract_xpath_string(xmldesc, "string(/domain/devices/graphics/@type)")) == NULL) {
viewer_simple_message_dialog(viewer->window, _("Cannot determine the graphic type for the guest %s"),
viewer->domkey);
goto cleanup;
@@ -820,8 +819,8 @@ static gboolean viewer_extract_connect_info(VirtViewer *viewer,
}
xpath = g_strdup_printf("string(/domain/devices/graphics[@type='%s']/@port)", type);
- if ((viewer->gport = viewer_extract_xpath_string(dom, xpath)) == NULL) {
- viewer_simple_message_dialog(viewer->window, _("Cannot determine the graphic port for the guest %s"),
+ if ((viewer->gport = viewer_extract_xpath_string(xmldesc, xpath)) == NULL) {
+ viewer_simple_message_dialog(viewer->window, _("Cannot determine the graphic address for the guest %s"),
viewer->domkey);
goto cleanup;
}
@@ -839,6 +838,7 @@ static gboolean viewer_extract_connect_info(VirtViewer *viewer,
cleanup:
free(xpath);
+ free(xmldesc);
return retval;
}