virXPathString(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
char *ret;
if ((ctxt == NULL) || (xpath == NULL)) {
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;
}
xmlXPathContextPtr ctxt,
double *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
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;
}
int base,
long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
int base,
unsigned long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
xmlXPathContextPtr ctxt,
unsigned long long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
xmlXPathContextPtr ctxt,
long long *value)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
ret = -1;
}
- xmlXPathFreeObject(obj);
return ret;
}
virXPathBoolean(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
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;
}
virXPathNode(const char *xpath,
xmlXPathContextPtr ctxt)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
xmlNodePtr ret;
if ((ctxt == NULL) || (xpath == NULL)) {
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;
}
xmlXPathContextPtr ctxt,
xmlNodePtr **list)
{
- xmlXPathObjectPtr obj;
+ g_autoptr(xmlXPathObject) obj = NULL;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
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;
}