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@xxxxxxxxxx> --- tests/qemucaps2xmltest.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index ce1116b792..78a2148e1a 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -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 * -- 2.31.1