Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/util/virxml.c | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 4360b15486..6b5ed08426 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -72,7 +72,7 @@ char *
virXPathString(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
char *ret;
if ((ctxt == NULL) || (xpath == NULL)) {
@@ -83,11 +83,9 @@ virXPathString(const char *xpath,
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
- xmlXPathFreeObject(obj);
return NULL;
}
ret = g_strdup((char *)obj->stringval);
- xmlXPathFreeObject(obj);
return ret;
}
@@ -147,7 +145,7 @@ virXPathNumber(const char *xpath,
xmlXPathContextPtr ctxt,
double *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -157,12 +155,10 @@ virXPathNumber(const char *xpath,
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
(isnan(obj->floatval))) {
- xmlXPathFreeObject(obj);
return -1;
}
*value = obj->floatval;
- xmlXPathFreeObject(obj);
return 0;
}
@@ -172,7 +168,7 @@ virXPathLongBase(const char *xpath,
int base,
long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
@@ -194,7 +190,6 @@ virXPathLongBase(const char *xpath,
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
@@ -274,7 +269,7 @@ virXPathULongBase(const char *xpath,
int base,
unsigned long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
@@ -296,7 +291,6 @@ virXPathULongBase(const char *xpath,
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
@@ -387,7 +381,7 @@ virXPathULongLong(const char *xpath,
xmlXPathContextPtr ctxt,
unsigned long long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
@@ -409,7 +403,6 @@ virXPathULongLong(const char *xpath,
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
@@ -430,7 +423,7 @@ virXPathLongLong(const char *xpath,
xmlXPathContextPtr ctxt,
long long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
@@ -452,7 +445,6 @@ virXPathLongLong(const char *xpath,
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
@@ -894,7 +886,7 @@ int
virXPathBoolean(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
@@ -905,12 +897,10 @@ virXPathBoolean(const char *xpath,
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
if ((obj == NULL) || (obj->type != XPATH_BOOLEAN) ||
(obj->boolval < 0) || (obj->boolval > 1)) {
- xmlXPathFreeObject(obj);
return -1;
}
ret = obj->boolval;
- xmlXPathFreeObject(obj);
return ret;
}
@@ -928,7 +918,7 @@ xmlNodePtr
virXPathNode(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
xmlNodePtr ret;
if ((ctxt == NULL) || (xpath == NULL)) {
@@ -940,12 +930,10 @@ virXPathNode(const char *xpath,
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr <= 0) ||
(obj->nodesetval->nodeTab == NULL)) {
- xmlXPathFreeObject(obj);
return NULL;
}
ret = obj->nodesetval->nodeTab[0];
- xmlXPathFreeObject(obj);
return ret;
}
@@ -965,7 +953,7 @@ virXPathNodeSet(const char *xpath,
xmlXPathContextPtr ctxt,
xmlNodePtr **list)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
@@ -984,21 +972,17 @@ virXPathNodeSet(const char *xpath,
if (obj->type != XPATH_NODESET) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Incorrect xpath '%s'"), xpath);
- xmlXPathFreeObject(obj);
return -1;
}
- if ((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
- xmlXPathFreeObject(obj);
+ if ((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0))
return 0;
- }
ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) {
*list = g_new0(xmlNodePtr, ret);
memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr));
}
- xmlXPathFreeObject(obj);
return ret;
}
--
2.31.1