tests: use g_auto in testQemuGetCaps

Refactor testQemuGetCaps to use g_auto for cleanup,
remove the error label and use g_steal_pointer for
the successful return path.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Ján Tomko 2021-08-20 13:36:00 +02:00
parent 9f33a6dcb4
commit 693831a58d

View File

@ -50,22 +50,22 @@ testQemuDataInit(testQemuData *data)
static virQEMUCaps *
testQemuGetCaps(char *caps)
{
virQEMUCaps *qemuCaps = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
ssize_t i, n;
g_autofree xmlNodePtr *nodes = NULL;
if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt)))
goto error;
return NULL;
if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
fprintf(stderr, "failed to parse qemu capabilities flags");
goto error;
return NULL;
}
if (!(qemuCaps = virQEMUCapsNew()))
goto error;
return NULL;
for (i = 0; i < n; i++) {
g_autofree char *str = virXMLPropString(nodes[i], "name");
@ -73,17 +73,13 @@ testQemuGetCaps(char *caps)
int flag = virQEMUCapsTypeFromString(str);
if (flag < 0) {
fprintf(stderr, "Unknown qemu capabilities flag %s", str);
goto error;
return NULL;
}
virQEMUCapsSet(qemuCaps, flag);
}
}
return qemuCaps;
error:
virObjectUnref(qemuCaps);
return NULL;
return g_steal_pointer(&qemuCaps);
}
static virCaps *