mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
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:
parent
9f33a6dcb4
commit
693831a58d
@ -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 *
|
||||
|
Loading…
Reference in New Issue
Block a user