[libvirt PATCH 00/24] tests: use g_auto more (glib chronicles)

Ján Tomko (24): tests: virnetdaemontest: split variable declarations conf: add cleanup func for virNetworkXMLOption conf: add cleanup func for virMacMap tests: use g_autoptr instead of virObjectUnref tests: qemu: use g_autofree tests: network: use g_autofree tests: libxl: use g_autofree tests: nwfilter: use g_autofree tests: vmx: use g_autofree tests: vir: use g_autofree tests: use g_autofree tests: use g_autoptr instead of virJSONValueFree tests: use g_auto for virCPUDataFree tests: use g_auto instead of VIR_FORCE_FCLOSE tests: use VIR_AUTOCLOSE tests: use g_auto instead of vshTableFree tests: use g_auto instead of virDomainFree tests: qemu: remove pointless labels tests: vmx: remove pointless labels tests: libxl: remove pointless labels tests: nwfilter: remove pointless labels tests: vshtabletest: remove pointless labels tests: vir: remove pointless labels tests: remove pointless labels src/conf/network_conf.h | 1 + src/util/virmacmap.h | 2 + tests/cputest.c | 51 ++++------- tests/domaincapstest.c | 60 +++++-------- tests/domainconftest.c | 18 ++-- tests/eventtest.c | 3 +- tests/fchosttest.c | 70 +++++---------- tests/fdstreamtest.c | 24 ++--- tests/genericxml2xmltest.c | 6 +- tests/interfacexml2xmltest.c | 9 +- tests/libxlxml2domconfigtest.c | 18 ++-- tests/lxcconf2xmltest.c | 37 +++----- tests/lxcxml2xmltest.c | 6 +- tests/metadatatest.c | 37 +++----- tests/networkxml2conftest.c | 19 ++-- tests/networkxml2firewalltest.c | 9 +- tests/networkxml2xmltest.c | 13 +-- tests/networkxml2xmlupdatetest.c | 16 ++-- tests/nodedevxml2xmltest.c | 9 +- tests/nsstest.c | 4 +- tests/nwfilterebiptablestest.c | 84 ++++++----------- tests/nwfilterxml2firewalltest.c | 12 +-- tests/nwfilterxml2xmltest.c | 10 +-- tests/openvzutilstest.c | 23 ++--- tests/qemuagenttest.c | 31 ++----- tests/qemucapsprobemock.c | 12 +-- tests/qemucommandutiltest.c | 15 ++-- tests/qemumonitorjsontest.c | 116 +++++++++--------------- tests/qemumonitortestutils.c | 45 +++------- tests/qemuxml2argvtest.c | 24 ++--- tests/scsihosttest.c | 37 +++----- tests/secretxml2xmltest.c | 7 +- tests/securityselinuxlabeltest.c | 27 ++---- tests/sockettest.c | 4 +- tests/testutils.c | 8 +- tests/testutilslxc.c | 4 +- tests/vboxsnapshotxmltest.c | 12 +-- tests/vircapstest.c | 20 ++--- tests/vircgrouptest.c | 3 +- tests/virconftest.c | 44 ++++----- tests/vircryptotest.c | 35 +++----- tests/virfilecachetest.c | 3 +- tests/virfilemock.c | 3 +- tests/virfiletest.c | 61 +++++-------- tests/virhostcputest.c | 42 +++------ tests/viriscsitest.c | 18 ++-- tests/virkmodtest.c | 39 +++----- tests/virmacmaptest.c | 49 ++++------ tests/virnetdaemontest.c | 13 ++- tests/virnetsockettest.c | 6 +- tests/virnettlshelpers.c | 4 +- tests/virnetworkportxml2xmltest.c | 23 ++--- tests/virnumamock.c | 14 +-- tests/virnwfilterbindingxml2xmltest.c | 7 +- tests/virpcimock.c | 4 +- tests/virpcitest.c | 56 +++++------- tests/virresctrltest.c | 34 +++---- tests/virrotatingfiletest.c | 4 +- tests/virscsitest.c | 31 ++----- tests/virstringtest.c | 44 +++------ tests/virsystemdtest.c | 29 ++---- tests/virtestmock.c | 10 +-- tests/viruritest.c | 3 +- tests/virusbmock.c | 7 +- tests/virusbtest.c | 6 +- tests/vmwarevertest.c | 20 ++--- tests/vmx2xmltest.c | 35 +++----- tests/vshtabletest.c | 125 ++++++++++---------------- tests/xlconfigtest.c | 85 +++++++----------- tests/xmconfigtest.c | 62 +++++-------- tests/xml2vmxtest.c | 32 +++---- 71 files changed, 628 insertions(+), 1226 deletions(-) -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virnetdaemontest.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index ce0384f026..f764268c50 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -270,8 +270,10 @@ static int testExecRestart(const void *opaque) int ret = -1; virNetDaemon *dmn = NULL; const struct testExecRestartData *data = opaque; - char *infile = NULL, *outfile = NULL; - char *injsonstr = NULL, *outjsonstr = NULL; + char *infile = NULL; + char *outfile = NULL; + char *injsonstr = NULL; + char *outjsonstr = NULL; virJSONValue *injson = NULL; virJSONValue *outjson = NULL; int fdclient[2] = { -1, -1 }, fdserver[2] = { -1, -1 }; -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/conf/network_conf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 34007e1969..30958eff64 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -44,6 +44,7 @@ struct _virNetworkXMLOption { virXMLNamespace ns; }; typedef struct _virNetworkXMLOption virNetworkXMLOption; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkXMLOption, virObjectUnref); typedef enum { -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virmacmap.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/virmacmap.h b/src/util/virmacmap.h index 582c4a8bdf..c0efa2b20f 100644 --- a/src/util/virmacmap.h +++ b/src/util/virmacmap.h @@ -21,8 +21,10 @@ #pragma once #include "internal.h" +#include "virobject.h" typedef struct virMacMap virMacMap; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMacMap, virObjectUnref) char * virMacMapFileName(const char *dnsmasqStateDir, -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/cputest.c | 9 +++------ tests/domaincapstest.c | 6 ++---- tests/networkxml2conftest.c | 3 +-- tests/networkxml2xmltest.c | 3 +-- tests/vircapstest.c | 6 ++---- tests/virmacmaptest.c | 6 ++---- tests/virpcitest.c | 18 ++++++------------ tests/virresctrltest.c | 6 ++---- tests/virscsitest.c | 3 +-- tests/virusbtest.c | 3 +-- tests/xlconfigtest.c | 6 ++---- tests/xmconfigtest.c | 3 +-- 12 files changed, 24 insertions(+), 48 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index 3e99b9486b..11305d56c5 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -526,7 +526,7 @@ cpuTestCPUID(bool guest, const void *arg) g_autofree char *host = NULL; g_autoptr(virCPUDef) cpu = NULL; g_autofree char *result = NULL; - virDomainCapsCPUModels *models = NULL; + g_autoptr(virDomainCapsCPUModels) models = NULL; hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, virArchToString(data->arch), data->host); @@ -563,7 +563,6 @@ cpuTestCPUID(bool guest, const void *arg) ret = cpuTestCompareXML(data->arch, cpu, result); cleanup: - virObjectUnref(models); return ret; } @@ -728,8 +727,8 @@ cpuTestUpdateLive(const void *arg) g_autoptr(virCPUData) disabledData = NULL; g_autofree char *expectedFile = NULL; g_autoptr(virCPUDef) expected = NULL; - virDomainCapsCPUModels *hvModels = NULL; - virDomainCapsCPUModels *models = NULL; + g_autoptr(virDomainCapsCPUModels) hvModels = NULL; + g_autoptr(virDomainCapsCPUModels) models = NULL; int ret = -1; cpuFile = g_strdup_printf("cpuid-%s-guest", data->host); @@ -795,8 +794,6 @@ cpuTestUpdateLive(const void *arg) ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected); cleanup: - virObjectUnref(hvModels); - virObjectUnref(models); return ret; } diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index ca29644dee..6ab14a0179 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -75,7 +75,7 @@ fillQemuCaps(virDomainCaps *domCaps, { int ret = -1; char *path = NULL; - virQEMUCaps *qemuCaps = NULL; + g_autoptr(virQEMUCaps) qemuCaps = NULL; virDomainCapsLoader *loader = &domCaps->os.loader; virDomainVirtType virtType; @@ -127,7 +127,6 @@ fillQemuCaps(virDomainCaps *domCaps, ret = 0; cleanup: - virObjectUnref(qemuCaps); VIR_FREE(path); return ret; } @@ -208,7 +207,7 @@ static int test_virDomainCapsFormat(const void *opaque) { const struct testData *data = opaque; - virDomainCaps *domCaps = NULL; + g_autoptr(virDomainCaps) domCaps = NULL; char *path = NULL; char *domCapsXML = NULL; int ret = -1; @@ -256,7 +255,6 @@ test_virDomainCapsFormat(const void *opaque) cleanup: VIR_FREE(domCapsXML); VIR_FREE(path); - virObjectUnref(domCaps); return ret; } diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 7444390b77..a2ecc6e80a 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -27,7 +27,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, virCommand *cmd = NULL; char *pidfile = NULL; dnsmasqContext *dctx = NULL; - virNetworkXMLOption *xmlopt = NULL; + g_autoptr(virNetworkXMLOption) xmlopt = NULL; if (!(xmlopt = networkDnsmasqCreateXMLConf())) goto fail; @@ -85,7 +85,6 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, VIR_FREE(hostsfileactual); VIR_FREE(pidfile); virCommandFree(cmd); - virObjectUnref(xmlopt); virNetworkObjEndAPI(&obj); dnsmasqContextFree(dctx); return ret; diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index 3b0a0b7c95..e1b5cdc748 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, int ret; testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS; virNetworkDef *dev = NULL; - virNetworkXMLOption *xmlopt = NULL; + g_autoptr(virNetworkXMLOption) xmlopt = NULL; if (!(xmlopt = networkDnsmasqCreateXMLConf())) goto cleanup; @@ -72,7 +72,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, VIR_FREE(actual); virNetworkDefFree(dev); - virObjectUnref(xmlopt); return ret; } diff --git a/tests/vircapstest.c b/tests/vircapstest.c index 7ec5b85222..ebabbbb9a0 100644 --- a/tests/vircapstest.c +++ b/tests/vircapstest.c @@ -151,7 +151,7 @@ static int test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED) { int ret = 0; - virCaps *caps = NULL; + g_autoptr(virCaps) caps = NULL; if (!(caps = testQemuCapsInit())) { ret = -1; @@ -196,7 +196,6 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED) CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc"); out: - virObjectUnref(caps); return ret; } #endif /* WITH_QEMU */ @@ -206,7 +205,7 @@ static int test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED) { int ret = 0; - virCaps *caps = NULL; + g_autoptr(virCaps) caps = NULL; if (!(caps = testLXCCapsInit())) { ret = -1; @@ -221,7 +220,6 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED) VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL); out: - virObjectUnref(caps); return ret; } #endif /* WITH_LXC */ diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 1b536af1ab..4e78615029 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -35,7 +35,7 @@ static int testMACLookup(const void *opaque) { const struct testData *data = opaque; - virMacMap *mgr = NULL; + g_autoptr(virMacMap) mgr = NULL; GSList *macs; GSList *next; size_t i, j; @@ -79,7 +79,6 @@ testMACLookup(const void *opaque) ret = 0; cleanup: VIR_FREE(file); - virObjectUnref(mgr); return ret; } @@ -88,7 +87,7 @@ static int testMACRemove(const void *opaque) { const struct testData *data = opaque; - virMacMap *mgr = NULL; + g_autoptr(virMacMap) mgr = NULL; GSList *macs; size_t i; char *file = NULL; @@ -117,7 +116,6 @@ testMACRemove(const void *opaque) ret = 0; cleanup: VIR_FREE(file); - virObjectUnref(mgr); return ret; } diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 0466e5a0f7..1cffe6e279 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -93,8 +93,8 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED) int ret = -1; virPCIDevice *dev[] = {NULL, NULL, NULL}; size_t i, nDev = G_N_ELEMENTS(dev); - virPCIDeviceList *activeDevs = NULL; - virPCIDeviceList *inactiveDevs = NULL; + g_autoptr(virPCIDeviceList) activeDevs = NULL; + g_autoptr(virPCIDeviceList) inactiveDevs = NULL; int count; if (!(activeDevs = virPCIDeviceListNew()) || @@ -126,8 +126,6 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED) cleanup: for (i = 0; i < nDev; i++) virPCIDeviceFree(dev[i]); - virObjectUnref(activeDevs); - virObjectUnref(inactiveDevs); return ret; } @@ -137,8 +135,8 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) int ret = -1; virPCIDevice *dev[] = {NULL, NULL, NULL}; size_t i, nDev = G_N_ELEMENTS(dev); - virPCIDeviceList *activeDevs = NULL; - virPCIDeviceList *inactiveDevs = NULL; + g_autoptr(virPCIDeviceList) activeDevs = NULL; + g_autoptr(virPCIDeviceList) inactiveDevs = NULL; int count; if (!(activeDevs = virPCIDeviceListNew()) || @@ -164,8 +162,6 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) cleanup: for (i = 0; i < nDev; i++) virPCIDeviceFree(dev[i]); - virObjectUnref(activeDevs); - virObjectUnref(inactiveDevs); return ret; } @@ -175,8 +171,8 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) int ret = -1; virPCIDevice *dev[] = {NULL, NULL, NULL}; size_t i, nDev = G_N_ELEMENTS(dev); - virPCIDeviceList *activeDevs = NULL; - virPCIDeviceList *inactiveDevs = NULL; + g_autoptr(virPCIDeviceList) activeDevs = NULL; + g_autoptr(virPCIDeviceList) inactiveDevs = NULL; int count; if (!(activeDevs = virPCIDeviceListNew()) || @@ -213,8 +209,6 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - virObjectUnref(activeDevs); - virObjectUnref(inactiveDevs); return ret; } diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index 26fbde3668..b1dbf66d41 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -21,10 +21,10 @@ test_virResctrlGetUnused(const void *opaque) char *system_dir = NULL; char *resctrl_dir = NULL; int ret = -1; - virResctrlAlloc *alloc = NULL; + g_autoptr(virResctrlAlloc) alloc = NULL; char *schemata_str = NULL; char *schemata_file; - virCaps *caps = NULL; + g_autoptr(virCaps) caps = NULL; system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir, data->filename); @@ -65,8 +65,6 @@ test_virResctrlGetUnused(const void *opaque) ret = 0; cleanup: - virObjectUnref(caps); - virObjectUnref(alloc); VIR_FREE(system_dir); VIR_FREE(resctrl_dir); VIR_FREE(schemata_str); diff --git a/tests/virscsitest.c b/tests/virscsitest.c index 0d7c35a261..1b6a7b9ae9 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -60,7 +60,7 @@ test1(const void *data G_GNUC_UNUSED) static int test2(const void *data G_GNUC_UNUSED) { - virSCSIDeviceList *list = NULL; + g_autoptr(virSCSIDeviceList) list = NULL; virSCSIDevice *dev = NULL; virSCSIDevice *dev1 = NULL; bool free_dev = true; @@ -157,7 +157,6 @@ test2(const void *data G_GNUC_UNUSED) virSCSIDeviceFree(dev); if (free_dev1) virSCSIDeviceFree(dev1); - virObjectUnref(list); return ret; } diff --git a/tests/virusbtest.c b/tests/virusbtest.c index baad7dd821..39a8f1a18e 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -70,7 +70,7 @@ static int testDeviceFind(const void *opaque) const struct findTestInfo *info = opaque; int ret = -1; virUSBDevice *dev = NULL; - virUSBDeviceList *devs = NULL; + g_autoptr(virUSBDeviceList) devs = NULL; int rv = 0; size_t i, ndevs = 0; @@ -123,7 +123,6 @@ static int testDeviceFind(const void *opaque) ret = 0; cleanup: - virObjectUnref(devs); virUSBDeviceFree(dev); return ret; } diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index e5c4a053bc..0a2997b8b6 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -67,7 +67,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) { char *gotxlcfgData = NULL; g_autoptr(virConf) conf = NULL; - virConnectPtr conn = NULL; + g_autoptr(virConnect) conn = NULL; int wrote = 4096; int ret = -1; virDomainDef *def = NULL; @@ -111,7 +111,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) VIR_FREE(replacedXML); VIR_FREE(gotxlcfgData); virDomainDefFree(def); - virObjectUnref(conn); return ret; } @@ -127,7 +126,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) char *gotxml = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; - virConnectPtr conn; + g_autoptr(virConnect) conn = NULL; virDomainDef *def = NULL; char *replacedXML = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); @@ -166,7 +165,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) VIR_FREE(xlcfgData); VIR_FREE(gotxml); virDomainDefFree(def); - virObjectUnref(conn); return ret; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index bf74e4a163..9d5eb85bf9 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -42,7 +42,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) char *gotxmcfgData = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; - virConnectPtr conn = NULL; + g_autoptr(virConnect) conn = NULL; int wrote = 4096; virDomainDef *def = NULL; @@ -75,7 +75,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) fail: VIR_FREE(gotxmcfgData); virDomainDefFree(def); - virObjectUnref(conn); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemucapsprobemock.c | 6 ++--- tests/qemucommandutiltest.c | 3 +-- tests/qemumonitorjsontest.c | 48 +++++++++++++------------------------ tests/qemuxml2argvtest.c | 3 +-- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c index 3c05a80ca2..00670101ce 100644 --- a/tests/qemucapsprobemock.c +++ b/tests/qemucapsprobemock.c @@ -58,7 +58,7 @@ int qemuMonitorSend(qemuMonitor *mon, qemuMonitorMessage *msg) { - char *reformatted; + g_autofree char *reformatted = NULL; REAL_SYM(realQemuMonitorSend); @@ -73,7 +73,6 @@ qemuMonitorSend(qemuMonitor *mon, printLineSkipEmpty("\n", stdout); printLineSkipEmpty(reformatted, stdout); - VIR_FREE(reformatted); return realQemuMonitorSend(mon, msg); } @@ -89,7 +88,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, qemuMonitorMessage *msg) { virJSONValue *value = NULL; - char *json = NULL; + g_autofree char *json = NULL; int ret; REAL_SYM(realQemuMonitorJSONIOProcessLine); @@ -116,7 +115,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, } cleanup: - VIR_FREE(json); virJSONValueFree(value); return ret; } diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index 33f92d2935..6b5e477849 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -39,7 +39,7 @@ testQemuCommandBuildFromJSON(const void *opaque) const testQemuCommandBuildObjectFromJSONData *data = opaque; virJSONValue *val = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - char *result = NULL; + g_autofree char *result = NULL; int ret = -1; if (!(val = virJSONValueFromString(data->props))) { @@ -66,7 +66,6 @@ testQemuCommandBuildFromJSON(const void *opaque) ret = 0; cleanup: virJSONValueFree(val); - VIR_FREE(result); return ret; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 9ec5f06981..c64c5c6b6f 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -650,8 +650,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption *xmlopt, { struct qemuMonitorJSONTestAttachChardevData data = {0}; - char *jsonreply = NULL; - char *fulllabel = NULL; + g_autofree char *jsonreply = NULL; + g_autofree char *fulllabel = NULL; int ret = -1; if (!reply) @@ -680,8 +680,6 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption *xmlopt, cleanup: qemuMonitorTestFree(data.test); - VIR_FREE(jsonreply); - VIR_FREE(fulllabel); return ret; } @@ -1723,7 +1721,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque) virDomainXMLOption *xmlopt = data->xmlopt; int ret = -1; qemuMonitorMigrationStats stats, expectedStats; - char *error = NULL; + g_autofree char *error = NULL; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -1784,7 +1782,6 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque) ret = 0; cleanup: - VIR_FREE(error); return ret; } @@ -2162,10 +2159,10 @@ testQemuMonitorJSONGetCPUData(const void *opaque) { const struct testCPUData *data = opaque; virCPUData *cpuData = NULL; - char *jsonFile = NULL; - char *dataFile = NULL; - char *jsonStr = NULL; - char *actual = NULL; + g_autofree char *jsonFile = NULL; + g_autofree char *dataFile = NULL; + g_autofree char *jsonStr = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(qemuMonitorTest) test = NULL; @@ -2211,10 +2208,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque) ret = 0; cleanup: - VIR_FREE(jsonFile); - VIR_FREE(dataFile); - VIR_FREE(jsonStr); - VIR_FREE(actual); virCPUDataFree(cpuData); return ret; } @@ -2409,12 +2402,12 @@ testQemuMonitorCPUInfo(const void *opaque) { const struct testCPUInfoData *data = opaque; virDomainObj *vm = NULL; - char *queryCpusFile = NULL; - char *queryHotpluggableFile = NULL; - char *dataFile = NULL; - char *queryCpusStr = NULL; - char *queryHotpluggableStr = NULL; - char *actual = NULL; + g_autofree char *queryCpusFile = NULL; + g_autofree char *queryHotpluggableFile = NULL; + g_autofree char *dataFile = NULL; + g_autofree char *queryCpusStr = NULL; + g_autofree char *queryHotpluggableStr = NULL; + g_autofree char *actual = NULL; const char *queryCpusFunction; qemuMonitorCPUInfo *vcpus = NULL; int rc; @@ -2468,12 +2461,6 @@ testQemuMonitorCPUInfo(const void *opaque) ret = 0; cleanup: - VIR_FREE(queryCpusFile); - VIR_FREE(queryHotpluggableFile); - VIR_FREE(dataFile); - VIR_FREE(queryCpusStr); - VIR_FREE(queryHotpluggableStr); - VIR_FREE(actual); qemuMonitorCPUInfoFree(vcpus, data->maxvcpus); return ret; } @@ -2518,8 +2505,8 @@ testBlockNodeNameDetect(const void *opaque) { const char *testname = opaque; const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-"; - char *resultFile = NULL; - char *actual = NULL; + g_autofree char *resultFile = NULL; + g_autofree char *actual = NULL; virJSONValue *namedNodesJson = NULL; virJSONValue *blockstatsJson = NULL; GHashTable *nodedata = NULL; @@ -2553,8 +2540,6 @@ testBlockNodeNameDetect(const void *opaque) ret = 0; cleanup: - VIR_FREE(resultFile); - VIR_FREE(actual); virHashFree(nodedata); virJSONValueFree(namedNodesJson); virJSONValueFree(blockstatsJson); @@ -2943,7 +2928,7 @@ mymain(void) testQemuMonitorJSONSimpleFuncData simpleFunc; struct testQAPISchemaData qapiData; virJSONValue *metaschema = NULL; - char *metaschemastr = NULL; + g_autofree char *metaschemastr = NULL; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; @@ -3235,7 +3220,6 @@ mymain(void) DO_TEST(qemuMonitorJSONGetCPUModelBaseline); cleanup: - VIR_FREE(metaschemastr); virJSONValueFree(metaschema); virHashFree(qapiData.schema); qemuTestDriverFree(&driver); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 3b331d5fd4..90b7da8055 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -643,7 +643,7 @@ testCompareXMLToArgv(const void *data) virDomainChrSourceDef monitor_chr; g_autoptr(virConnect) conn = NULL; virError *err = NULL; - char *log = NULL; + g_autofree char *log = NULL; g_autoptr(virCommand) cmd = NULL; qemuDomainObjPrivate *priv = NULL; g_autoptr(xmlDoc) xml = NULL; @@ -815,7 +815,6 @@ testCompareXMLToArgv(const void *data) ret = 0; cleanup: - VIR_FREE(log); virDomainChrSourceDefClear(&monitor_chr); virObjectUnref(vm); virIdentitySetCurrent(NULL); -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/networkxml2conftest.c | 16 +++++----------- tests/networkxml2firewalltest.c | 9 +++------ tests/networkxml2xmltest.c | 10 +++------- tests/networkxml2xmlupdatetest.c | 16 +++++----------- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index a2ecc6e80a..b76d72793a 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -20,12 +20,12 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, char *outhostsfile, dnsmasqCaps *caps) { char *confactual = NULL; - char *hostsfileactual = NULL; + g_autofree char *hostsfileactual = NULL; int ret = -1; virNetworkDef *def = NULL; virNetworkObj *obj = NULL; virCommand *cmd = NULL; - char *pidfile = NULL; + g_autofree char *pidfile = NULL; dnsmasqContext *dctx = NULL; g_autoptr(virNetworkXMLOption) xmlopt = NULL; @@ -82,8 +82,6 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, fail: VIR_FREE(confactual); - VIR_FREE(hostsfileactual); - VIR_FREE(pidfile); virCommandFree(cmd); virNetworkObjEndAPI(&obj); dnsmasqContextFree(dctx); @@ -100,9 +98,9 @@ testCompareXMLToConfHelper(const void *data) { int result = -1; const testInfo *info = data; - char *inxml = NULL; - char *outconf = NULL; - char *outhostsfile = NULL; + g_autofree char *inxml = NULL; + g_autofree char *outconf = NULL; + g_autofree char *outhostsfile = NULL; inxml = g_strdup_printf("%s/networkxml2confdata/%s.xml", abs_srcdir, info->name); outconf = g_strdup_printf("%s/networkxml2confdata/%s.conf", abs_srcdir, info->name); @@ -110,10 +108,6 @@ testCompareXMLToConfHelper(const void *data) result = testCompareXMLToConfFiles(inxml, outconf, outhostsfile, info->caps); - VIR_FREE(inxml); - VIR_FREE(outconf); - VIR_FREE(outhostsfile); - return result; } diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c index 91336a0c55..e4f86bc3fc 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -91,7 +91,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline, const char *baseargs) { - char *actualargv = NULL; + g_autofree char *actualargv = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; virNetworkDef *def = NULL; int ret = -1; @@ -121,7 +121,6 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; cleanup: - VIR_FREE(actualargv); virNetworkDefFree(def); return ret; } @@ -137,8 +136,8 @@ testCompareXMLToIPTablesHelper(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *args = NULL; + g_autofree char *xml = NULL; + g_autofree char *args = NULL; xml = g_strdup_printf("%s/networkxml2firewalldata/%s.xml", abs_srcdir, info->name); @@ -147,8 +146,6 @@ testCompareXMLToIPTablesHelper(const void *data) result = testCompareXMLToArgvFiles(xml, args, info->baseargs); - VIR_FREE(xml); - VIR_FREE(args); return result; } diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index e1b5cdc748..ca24305ace 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -26,7 +26,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, unsigned int flags, testCompareNetXML2XMLResult expectResult) { - char *actual = NULL; + g_autofree char *actual = NULL; int ret; testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS; virNetworkDef *dev = NULL; @@ -70,7 +70,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, } virResetLastError(); - VIR_FREE(actual); virNetworkDefFree(dev); return ret; } @@ -86,8 +85,8 @@ testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; int result = -1; - char *inxml = NULL; - char *outxml = NULL; + g_autofree char *inxml = NULL; + g_autofree char *outxml = NULL; inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name); outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name); @@ -95,9 +94,6 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(inxml, outxml, info->flags, info->expectResult); - VIR_FREE(inxml); - VIR_FREE(outxml); - return result; } diff --git a/tests/networkxml2xmlupdatetest.c b/tests/networkxml2xmlupdatetest.c index 11cfdfc25e..4471b4dd9e 100644 --- a/tests/networkxml2xmlupdatetest.c +++ b/tests/networkxml2xmlupdatetest.c @@ -19,8 +19,8 @@ testCompareXMLToXMLFiles(const char *netxml, const char *updatexml, unsigned int command, unsigned int section, int parentIndex, bool expectFailure) { - char *updateXmlData = NULL; - char *actual = NULL; + g_autofree char *updateXmlData = NULL; + g_autofree char *actual = NULL; int ret = -1; virNetworkDef *def = NULL; @@ -55,8 +55,6 @@ testCompareXMLToXMLFiles(const char *netxml, const char *updatexml, } } error: - VIR_FREE(updateXmlData); - VIR_FREE(actual); virNetworkDefFree(def); return ret; } @@ -78,9 +76,9 @@ testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; int result = -1; - char *netxml = NULL; - char *updatexml = NULL; - char *outxml = NULL; + g_autofree char *netxml = NULL; + g_autofree char *updatexml = NULL; + g_autofree char *outxml = NULL; netxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->netxml); @@ -93,10 +91,6 @@ testCompareXMLToXMLHelper(const void *data) info->command, info->section, info->parentIndex, info->expectFailure); - VIR_FREE(netxml); - VIR_FREE(updatexml); - VIR_FREE(outxml); - return result; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/libxlxml2domconfigtest.c | 15 +++++---------- tests/xlconfigtest.c | 25 ++++++++----------------- tests/xmconfigtest.c | 16 +++++----------- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 19385c6fb5..2bc5c26223 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -53,9 +53,9 @@ testCompareXMLToDomConfig(const char *xmlfile, xentoollog_logger *log = NULL; virPortAllocatorRange *gports = NULL; virDomainDef *vmdef = NULL; - char *actualjson = NULL; - char *tempjson = NULL; - char *expectjson = NULL; + g_autofree char *actualjson = NULL; + g_autofree char *tempjson = NULL; + g_autofree char *expectjson = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); libxl_domain_config_init(&actualconfig); @@ -128,9 +128,6 @@ testCompareXMLToDomConfig(const char *xmlfile, vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); - VIR_FREE(expectjson); - VIR_FREE(actualjson); - VIR_FREE(tempjson); virDomainDefFree(vmdef); virPortAllocatorRangeFree(gports); libxl_domain_config_dispose(&actualconfig); @@ -150,16 +147,14 @@ testCompareXMLToDomConfigHelper(const void *data) { int ret = -1; const struct testInfo *info = data; - char *xmlfile = NULL; - char *jsonfile = NULL; + g_autofree char *xmlfile = NULL; + g_autofree char *jsonfile = NULL; xmlfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.xml", abs_srcdir, info->name); jsonfile = g_strdup_printf("%s/libxlxml2domconfigdata/%s.json", abs_srcdir, info->name); ret = testCompareXMLToDomConfig(xmlfile, jsonfile); - VIR_FREE(xmlfile); - VIR_FREE(jsonfile); return ret; } diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 0a2997b8b6..95ee670b00 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -45,7 +45,7 @@ static libxlDriverPrivate *driver; static char * testReplaceVarsXML(const char *xml) { - char *xmlcfgData; + g_autofree char *xmlcfgData = NULL; char *replacedXML; if (virTestLoadFile(xml, &xmlcfgData) < 0) @@ -54,7 +54,6 @@ testReplaceVarsXML(const char *xml) replacedXML = virStringReplace(xmlcfgData, "/LIBXL_FIRMWARE_DIR", LIBXL_FIRMWARE_DIR); - VIR_FREE(xmlcfgData); return replacedXML; } @@ -65,13 +64,13 @@ testReplaceVarsXML(const char *xml) static int testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) { - char *gotxlcfgData = NULL; + g_autofree char *gotxlcfgData = NULL; g_autoptr(virConf) conf = NULL; g_autoptr(virConnect) conn = NULL; int wrote = 4096; int ret = -1; virDomainDef *def = NULL; - char *replacedXML = NULL; + g_autofree char *replacedXML = NULL; gotxlcfgData = g_new0(char, wrote); @@ -108,8 +107,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) ret = 0; fail: - VIR_FREE(replacedXML); - VIR_FREE(gotxlcfgData); virDomainDefFree(def); return ret; @@ -122,13 +119,13 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) static int testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) { - char *xlcfgData = NULL; - char *gotxml = NULL; + g_autofree char *xlcfgData = NULL; + g_autofree char *gotxml = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; g_autoptr(virConnect) conn = NULL; virDomainDef *def = NULL; - char *replacedXML = NULL; + g_autofree char *replacedXML = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); conn = virGetConnect(); @@ -161,9 +158,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) ret = 0; fail: - VIR_FREE(replacedXML); - VIR_FREE(xlcfgData); - VIR_FREE(gotxml); virDomainDefFree(def); return ret; @@ -181,8 +175,8 @@ testCompareHelper(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *cfg = NULL; + g_autofree char *xml = NULL; + g_autofree char *cfg = NULL; xml = g_strdup_printf("%s/xlconfigdata/test-%s.xml", abs_srcdir, info->name); cfg = g_strdup_printf("%s/xlconfigdata/test-%s.cfg", abs_srcdir, info->name); @@ -192,9 +186,6 @@ testCompareHelper(const void *data) else result = testCompareFormatXML(cfg, xml, info->replaceVars); - VIR_FREE(xml); - VIR_FREE(cfg); - return result; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 9d5eb85bf9..a756f752f8 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -39,7 +39,7 @@ static libxlDriverPrivate *driver; static int testCompareParseXML(const char *xmcfg, const char *xml) { - char *gotxmcfgData = NULL; + g_autofree char *gotxmcfgData = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; g_autoptr(virConnect) conn = NULL; @@ -73,7 +73,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) ret = 0; fail: - VIR_FREE(gotxmcfgData); virDomainDefFree(def); return ret; @@ -82,8 +81,8 @@ testCompareParseXML(const char *xmcfg, const char *xml) static int testCompareFormatXML(const char *xmcfg, const char *xml) { - char *xmcfgData = NULL; - char *gotxml = NULL; + g_autofree char *xmcfgData = NULL; + g_autofree char *gotxml = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; virDomainDef *def = NULL; @@ -107,8 +106,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml) ret = 0; fail: - VIR_FREE(xmcfgData); - VIR_FREE(gotxml); virDomainDefFree(def); return ret; @@ -125,8 +122,8 @@ testCompareHelper(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *cfg = NULL; + g_autofree char *xml = NULL; + g_autofree char *cfg = NULL; xml = g_strdup_printf("%s/xmconfigdata/test-%s.xml", abs_srcdir, info->name); cfg = g_strdup_printf("%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name); @@ -136,9 +133,6 @@ testCompareHelper(const void *data) else result = testCompareFormatXML(cfg, xml); - VIR_FREE(xml); - VIR_FREE(cfg); - return result; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/nwfilterebiptablestest.c | 21 +++++++-------------- tests/nwfilterxml2firewalltest.c | 12 ++++-------- tests/nwfilterxml2xmltest.c | 10 +++------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c index 65b63959fb..7b32e90d19 100644 --- a/tests/nwfilterebiptablestest.c +++ b/tests/nwfilterebiptablestest.c @@ -101,7 +101,7 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -X libvirt-I-vnet0\n" "ebtables --concurrent -t nat -F libvirt-O-vnet0\n" "ebtables --concurrent -t nat -X libvirt-O-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -119,7 +119,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -167,7 +166,7 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -L libvirt-P-vnet0\n" "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -185,7 +184,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -211,7 +209,7 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -X libvirt-J-vnet0\n" "ebtables --concurrent -t nat -F libvirt-P-vnet0\n" "ebtables --concurrent -t nat -X libvirt-P-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -229,7 +227,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -240,7 +237,7 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED) g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; const char *expected = VIR_NWFILTER_NEW_RULES_TEARDOWN; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -258,7 +255,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -306,7 +302,7 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -A libvirt-J-vnet0 -j DROP\n" "ebtables --concurrent -t nat -A PREROUTING -i vnet0 -j libvirt-J-vnet0\n" "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } }; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -325,7 +321,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -381,7 +376,7 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -A POSTROUTING -o vnet0 -j libvirt-P-vnet0\n" "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } }; const char *servers[] = { "192.168.122.1", "10.0.0.1", "10.0.0.2" }; @@ -410,7 +405,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -460,7 +454,7 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -A POSTROUTING -o vnet0 -j libvirt-P-vnet0\n" "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -478,7 +472,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(actual); return ret; } diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index 7fefd3ce75..3e8436a98c 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -229,7 +229,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDef *inc, { GHashTable *tmpvars = NULL; int ret = -1; - char *xml; + g_autofree char *xml = NULL; xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml", abs_srcdir, inc->filterref); @@ -249,7 +249,6 @@ virNWFilterIncludeDefToRuleInst(virNWFilterIncludeDef *inc, if (ret < 0) virNWFilterInstReset(inst); virHashFree(tmpvars); - VIR_FREE(xml); return ret; } @@ -350,7 +349,7 @@ static int testSetDefaultParameters(GHashTable *vars) static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline) { - char *actualargv = NULL; + g_autofree char *actualargv = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; GHashTable *vars = virHashNew(virNWFilterVarValueHashFree); virNWFilterInst inst; @@ -382,7 +381,6 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; cleanup: - VIR_FREE(actualargv); virNWFilterInstReset(&inst); virHashFree(vars); return ret; @@ -398,8 +396,8 @@ testCompareXMLToIPTablesHelper(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *args = NULL; + g_autofree char *xml = NULL; + g_autofree char *args = NULL; xml = g_strdup_printf("%s/nwfilterxml2firewalldata/%s.xml", abs_srcdir, info->name); @@ -408,8 +406,6 @@ testCompareXMLToIPTablesHelper(const void *data) result = testCompareXMLToArgvFiles(xml, args); - VIR_FREE(xml); - VIR_FREE(args); return result; } diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index 82ce042e01..7a7e05965b 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -20,7 +20,7 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool expect_error) { - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; virNWFilterDef *dev = NULL; @@ -44,7 +44,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, ret = 0; fail: - VIR_FREE(actual); virNWFilterDefFree(dev); return ret; } @@ -59,17 +58,14 @@ testCompareXMLToXMLHelper(const void *data) { int result = -1; const test_parms *tp = data; - char *inxml = NULL; - char *outxml = NULL; + g_autofree char *inxml = NULL; + g_autofree char *outxml = NULL; inxml = g_strdup_printf("%s/nwfilterxml2xmlin/%s.xml", abs_srcdir, tp->name); outxml = g_strdup_printf("%s/nwfilterxml2xmlout/%s.xml", abs_srcdir, tp->name); result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning); - VIR_FREE(inxml); - VIR_FREE(outxml); - return result; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vmx2xmltest.c | 13 ++++--------- tests/xml2vmxtest.c | 14 ++++---------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 33bf243717..cd44a84a07 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -69,8 +69,8 @@ static int testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) { int ret = -1; - char *vmxData = NULL; - char *formatted = NULL; + g_autofree char *vmxData = NULL; + g_autofree char *formatted = NULL; virDomainDef *def = NULL; if (virTestLoadFile(vmx, &vmxData) < 0) @@ -102,8 +102,6 @@ testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) ret = 0; cleanup: - VIR_FREE(vmxData); - VIR_FREE(formatted); virDomainDefFree(def); return ret; @@ -119,8 +117,8 @@ testCompareHelper(const void *data) { int ret = -1; const struct testInfo *info = data; - char *vmx = NULL; - char *xml = NULL; + g_autofree char *vmx = NULL; + g_autofree char *xml = NULL; vmx = g_strdup_printf("%s/vmx2xmldata/%s.vmx", abs_srcdir, info->file); @@ -129,9 +127,6 @@ testCompareHelper(const void *data) ret = testCompareFiles(vmx, xml, info->should_fail); - VIR_FREE(vmx); - VIR_FREE(xml); - return ret; } diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index fb87000529..cb70f70f4f 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -71,7 +71,7 @@ static int testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) { int result = -1; - char *formatted = NULL; + g_autofree char *formatted = NULL; virDomainDef *def = NULL; def = virDomainDefParseFile(xml, xmlopt, NULL, @@ -95,7 +95,6 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) result = 0; failure: - VIR_FREE(formatted); virDomainDefFree(def); return result; @@ -112,8 +111,8 @@ testCompareHelper(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *vmx = NULL; + g_autofree char *xml = NULL; + g_autofree char *vmx = NULL; xml = g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir, info->input); @@ -122,9 +121,6 @@ testCompareHelper(const void *data) result = testCompareFiles(xml, vmx, info->virtualHW_version); - VIR_FREE(xml); - VIR_FREE(vmx); - return result; } @@ -141,7 +137,7 @@ static char * testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED) { bool success = false; - char *copyOfDatastorePath = NULL; + g_autofree char *copyOfDatastorePath = NULL; char *tmp = NULL; char *saveptr = NULL; char *datastoreName = NULL; @@ -182,8 +178,6 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED) if (! success) VIR_FREE(absolutePath); - VIR_FREE(copyOfDatastorePath); - return absolutePath; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vircgrouptest.c | 3 +-- tests/virconftest.c | 6 ++---- tests/vircryptotest.c | 12 ++++-------- tests/virfilecachetest.c | 3 +-- tests/virfilemock.c | 3 +-- tests/virfiletest.c | 6 ++---- tests/virhostcputest.c | 23 +++++++---------------- tests/viriscsitest.c | 3 +-- tests/virkmodtest.c | 9 +++------ tests/virmacmaptest.c | 12 ++++-------- tests/virnetdaemontest.c | 12 ++++-------- tests/virnetsockettest.c | 6 ++---- tests/virnetworkportxml2xmltest.c | 8 ++------ tests/virnumamock.c | 7 ++----- tests/virnwfilterbindingxml2xmltest.c | 7 ++----- tests/virpcitest.c | 16 +++++----------- tests/virresctrltest.c | 12 ++++-------- tests/virscsitest.c | 13 ++++--------- tests/virstringtest.c | 12 ++++-------- tests/virsystemdtest.c | 9 +++------ tests/virtestmock.c | 10 +++------- tests/viruritest.c | 3 +-- tests/virusbmock.c | 7 ++----- tests/virusbtest.c | 3 +-- 24 files changed, 65 insertions(+), 140 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 1060f6073e..7d54df1a85 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -174,7 +174,7 @@ testCgroupDetectMounts(const void *args) { int result = -1; const struct _detectMountsData *data = args; - char *parsed = NULL; + g_autofree char *parsed = NULL; const char *actual; g_autoptr(virCgroup) group = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; @@ -209,7 +209,6 @@ testCgroupDetectMounts(const void *args) cleanup: g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); - VIR_FREE(parsed); return result; } diff --git a/tests/virconftest.c b/tests/virconftest.c index f1a58b01cf..a7189579d3 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -70,7 +70,7 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED) int ret = -1; virConfValue *val; unsigned long long llvalue; - char *str = NULL; + g_autofree char *str = NULL; int uintvalue; if (!conf) @@ -119,7 +119,6 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(str); return ret; } @@ -341,7 +340,7 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED) int ret = -1; g_autoptr(virConf) conf = virConfReadString(srcdata, 0); - char *str = NULL; + g_autofree char *str = NULL; if (!conf) return -1; @@ -367,7 +366,6 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(str); return ret; } diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c index 2c3d4bfe75..2d503a439e 100644 --- a/tests/vircryptotest.c +++ b/tests/vircryptotest.c @@ -37,7 +37,7 @@ static int testCryptoHash(const void *opaque) { const struct testCryptoHashData *data = opaque; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; if (virCryptoHashString(data->hash, data->input, &actual) < 0) { @@ -53,7 +53,6 @@ testCryptoHash(const void *opaque) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -70,11 +69,11 @@ static int testCryptoEncrypt(const void *opaque) { const struct testCryptoEncryptData *data = opaque; - uint8_t *enckey = NULL; + g_autofree uint8_t *enckey = NULL; size_t enckeylen = 32; - uint8_t *iv = NULL; + g_autofree uint8_t *iv = NULL; size_t ivlen = 16; - uint8_t *ciphertext = NULL; + g_autofree uint8_t *ciphertext = NULL; size_t ciphertextlen = 0; int ret = -1; @@ -110,9 +109,6 @@ testCryptoEncrypt(const void *opaque) ret = 0; cleanup: - VIR_FREE(enckey); - VIR_FREE(iv); - VIR_FREE(ciphertext); return ret; } diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c index 3083aee35d..5730e23b73 100644 --- a/tests/virfilecachetest.c +++ b/tests/virfilecachetest.c @@ -112,14 +112,13 @@ testFileCacheLoadFile(const char *filename, bool *outdated G_GNUC_UNUSED) { testFileCacheObj *obj; - char *data; + g_autofree char *data = NULL; if (virFileReadAll(filename, 20, &data) < 0) return NULL; obj = testFileCacheObjNew(data); - VIR_FREE(data); return obj; } diff --git a/tests/virfilemock.c b/tests/virfilemock.c index bf153ab769..d4863bd12c 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -105,7 +105,7 @@ statfs_mock(const char *mtab, FILE *f; struct mntent mb; char mntbuf[1024]; - char *canonPath = NULL; + g_autofree char *canonPath = NULL; int ret = -1; if (!(f = real_setmntent(mtab, "r"))) { @@ -158,7 +158,6 @@ statfs_mock(const char *mtab, } endmntent(f); - VIR_FREE(canonPath); return ret; } diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 3c1f2ce54e..019c230cea 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -104,7 +104,7 @@ testFileSanitizePath(const void *opaque) { const struct testFileSanitizePathData *data = opaque; int ret = -1; - char *actual; + g_autofree char *actual = NULL; if (!(actual = virFileSanitizePath(data->path))) return -1; @@ -117,7 +117,6 @@ testFileSanitizePath(const void *opaque) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -322,7 +321,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data = opaque; - char *mtabFile = NULL; + g_autofree char *mtabFile = NULL; bool actual; int ret = -1; @@ -343,7 +342,6 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(mtabFile); g_unsetenv("LIBVIRT_MTAB"); return ret; #endif diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 9e329b38b4..f935df0f63 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -31,7 +31,7 @@ linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { int ret = -1; - char *actualData = NULL; + g_autofree char *actualData = NULL; virNodeInfo nodeinfo; FILE *cpuinfo; @@ -68,7 +68,6 @@ linuxTestCompareFiles(const char *cpuinfofile, ret = 0; fail: - VIR_FREE(actualData); return ret; } @@ -109,7 +108,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, const char *outfile) { int ret = -1; - char *actualData = NULL; + g_autofree char *actualData = NULL; FILE *cpustat = NULL; virNodeCPUStatsPtr params = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; @@ -150,7 +149,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, fail: VIR_FORCE_FCLOSE(cpustat); - VIR_FREE(actualData); VIR_FREE(params); return ret; } @@ -165,9 +163,9 @@ static int linuxTestHostCPU(const void *opaque) { int result = -1; - char *cpuinfo = NULL; - char *sysfs_prefix = NULL; - char *output = NULL; + g_autofree char *cpuinfo = NULL; + g_autofree char *sysfs_prefix = NULL; + g_autofree char *output = NULL; struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque; const char *archStr = virArchToString(data->arch); @@ -182,10 +180,6 @@ linuxTestHostCPU(const void *opaque) result = linuxTestCompareFiles(cpuinfo, data->arch, output); virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); - VIR_FREE(cpuinfo); - VIR_FREE(output); - VIR_FREE(sysfs_prefix); - return result; } @@ -232,8 +226,8 @@ linuxTestNodeCPUStats(const void *data) { const struct nodeCPUStatsData *testData = data; int result = -1; - char *cpustatfile = NULL; - char *outfile = NULL; + g_autofree char *cpustatfile = NULL; + g_autofree g_autofree char *outfile = NULL; cpustatfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.stat", abs_srcdir, testData->name); @@ -255,9 +249,6 @@ linuxTestNodeCPUStats(const void *data) } } - - VIR_FREE(cpustatfile); - VIR_FREE(outfile); return result; } diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 37922ba552..7ea761fda6 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -210,7 +210,7 @@ testISCSIGetSession(const void *data) { const struct testSessionInfo *info = data; struct testIscsiadmCbData cbData = { 0 }; - char *actual_session = NULL; + g_autofree char *actual_session = NULL; int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -231,7 +231,6 @@ testISCSIGetSession(const void *data) ret = 0; cleanup: - VIR_FREE(actual_session); return ret; } diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 2a85e0ae6d..2f07757c88 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -35,7 +35,7 @@ static int checkOutput(virBuffer *buf, const char *exp_cmd) { int ret = -1; - char *actual_cmd = NULL; + g_autofree char *actual_cmd = NULL; if (!(actual_cmd = virBufferContentAndReset(buf))) { fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); @@ -50,7 +50,6 @@ checkOutput(virBuffer *buf, const char *exp_cmd) ret = 0; cleanup: - VIR_FREE(actual_cmd); return ret; } @@ -59,7 +58,7 @@ static int testKModLoad(const void *args G_GNUC_UNUSED) { int ret = -1; - char *errbuf = NULL; + g_autofree char *errbuf = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -77,7 +76,6 @@ testKModLoad(const void *args G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(errbuf); return ret; } @@ -86,7 +84,7 @@ static int testKModUnload(const void *args G_GNUC_UNUSED) { int ret = -1; - char *errbuf = NULL; + g_autofree char *errbuf = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -104,7 +102,6 @@ testKModUnload(const void *args G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(errbuf); return ret; } diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 4e78615029..01a3588ed9 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -39,7 +39,7 @@ testMACLookup(const void *opaque) GSList *macs; GSList *next; size_t i, j; - char *file = NULL; + g_autofree char *file = NULL; int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); @@ -78,7 +78,6 @@ testMACLookup(const void *opaque) ret = 0; cleanup: - VIR_FREE(file); return ret; } @@ -90,7 +89,7 @@ testMACRemove(const void *opaque) g_autoptr(virMacMap) mgr = NULL; GSList *macs; size_t i; - char *file = NULL; + g_autofree char *file = NULL; int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); @@ -115,7 +114,6 @@ testMACRemove(const void *opaque) ret = 0; cleanup: - VIR_FREE(file); return ret; } @@ -124,8 +122,8 @@ static int testMACFlush(const void *opaque) { const struct testData *data = opaque; - char *file = NULL; - char *str = NULL; + g_autofree char *file = NULL; + g_autofree char *str = NULL; int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); @@ -138,8 +136,6 @@ testMACFlush(const void *opaque) ret = 0; cleanup: - VIR_FREE(file); - VIR_FREE(str); return ret; } diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index f764268c50..2522a4c8ea 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -270,10 +270,10 @@ static int testExecRestart(const void *opaque) int ret = -1; virNetDaemon *dmn = NULL; const struct testExecRestartData *data = opaque; - char *infile = NULL; - char *outfile = NULL; - char *injsonstr = NULL; - char *outjsonstr = NULL; + g_autofree char *infile = NULL; + g_autofree char *outfile = NULL; + g_autofree char *injsonstr = NULL; + g_autofree char *outjsonstr = NULL; virJSONValue *injson = NULL; virJSONValue *outjson = NULL; int fdclient[2] = { -1, -1 }, fdserver[2] = { -1, -1 }; @@ -352,10 +352,6 @@ static int testExecRestart(const void *opaque) VIR_TEST_DEBUG("Test should have failed"); ret = -1; } - VIR_FREE(infile); - VIR_FREE(outfile); - VIR_FREE(injsonstr); - VIR_FREE(outjsonstr); virJSONValueFree(injson); virJSONValueFree(outjson); virObjectUnref(dmn); diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 8059c6cbb0..8fbbea5d30 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -186,7 +186,7 @@ testSocketAccept(const void *opaque) int ret = -1; char portstr[100]; char *tmpdir = NULL; - char *path = NULL; + g_autofree char *path = NULL; char template[] = "/tmp/libvirt_XXXXXX"; virThread th; struct testClientData cdata = { 0 }; @@ -296,7 +296,6 @@ testSocketAccept(const void *opaque) virObjectUnref(lsock[i]); } VIR_FREE(lsock); - VIR_FREE(path); if (tmpdir) rmdir(tmpdir); return ret; @@ -312,7 +311,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED) virNetSocket *csock = NULL; /* Client socket */ int ret = -1; - char *path = NULL; + g_autofree char *path = NULL; char *tmpdir; char template[] = "/tmp/libvirt_XXXXXX"; @@ -383,7 +382,6 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(path); virObjectUnref(lsock); virObjectUnref(ssock); virObjectUnref(csock); diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xmltest.c index 039da96490..8d29db724f 100644 --- a/tests/virnetworkportxml2xmltest.c +++ b/tests/virnetworkportxml2xmltest.c @@ -36,7 +36,7 @@ static int testCompareXMLToXMLFiles(const char *expected) { - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; g_autoptr(virNetworkPortDef) dev = NULL; @@ -51,7 +51,6 @@ testCompareXMLToXMLFiles(const char *expected) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -64,15 +63,12 @@ testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; int ret = -1; - char *xml = NULL; + g_autofree char *xml = NULL; xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir, info->name); ret = testCompareXMLToXMLFiles(xml); - - VIR_FREE(xml); - return ret; } diff --git a/tests/virnumamock.c b/tests/virnumamock.c index ff9c6e951d..6e0293a49e 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -41,13 +41,11 @@ bool virNumaIsAvailable(void) { if (numa_avail < 0) { - char *sysfs_node_path = NULL; + g_autofree char *sysfs_node_path = NULL; sysfs_node_path = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH); numa_avail = virFileExists(sysfs_node_path); - - VIR_FREE(sysfs_node_path); } /* @@ -165,7 +163,7 @@ int virNumaGetNodeCPUs(int node, virBitmap **cpus) { int ret = -1; - char *cpulist = NULL; + g_autofree char *cpulist = NULL; if (virFileReadValueString(&cpulist, "%s/node/node%u/cpulist", @@ -183,6 +181,5 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus) ret = virBitmapCountBits(*cpus); cleanup: - VIR_FREE(cpulist); return ret; } diff --git a/tests/virnwfilterbindingxml2xmltest.c b/tests/virnwfilterbindingxml2xmltest.c index ba8edcfd05..ccdad3daa5 100644 --- a/tests/virnwfilterbindingxml2xmltest.c +++ b/tests/virnwfilterbindingxml2xmltest.c @@ -38,7 +38,7 @@ static int testCompareXMLToXMLFiles(const char *xml) { - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; virNWFilterBindingDef *dev = NULL; @@ -56,7 +56,6 @@ testCompareXMLToXMLFiles(const char *xml) ret = 0; fail: - VIR_FREE(actual); virNWFilterBindingDefFree(dev); return ret; } @@ -70,15 +69,13 @@ testCompareXMLToXMLHelper(const void *data) { int result = -1; const test_parms *tp = data; - char *xml = NULL; + g_autofree char *xml = NULL; xml = g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir, tp->name); result = testCompareXMLToXMLFiles(xml); - VIR_FREE(xml); - return result; } diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 1cffe6e279..1ff0330b22 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -32,8 +32,8 @@ static int testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected) { - char *path = NULL; - char *driver = NULL; + g_autofree char *path = NULL; + g_autofree char *driver = NULL; int ret = -1; if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0) @@ -49,8 +49,6 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected) ret = 0; cleanup: - VIR_FREE(path); - VIR_FREE(driver); return ret; } @@ -339,7 +337,7 @@ static int mymain(void) { int ret = 0; - char *fakerootdir; + g_autofree char *fakerootdir = NULL; fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); @@ -361,12 +359,11 @@ mymain(void) struct testPCIDevData data = { \ domain, bus, slot, function, NULL \ }; \ - char *label = NULL; \ + g_autofree char *label = NULL; \ label = g_strdup_printf("%s(%04x:%02x:%02x.%x)", \ #fnc, domain, bus, slot, function); \ if (virTestRun(label, fnc, &data) < 0) \ ret = -1; \ - VIR_FREE(label); \ } while (0) # define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \ @@ -374,14 +371,13 @@ mymain(void) struct testPCIDevData data = { \ domain, bus, slot, function, driver \ }; \ - char *label = NULL; \ + g_autofree char *label = NULL; \ label = g_strdup_printf("PCI driver %04x:%02x:%02x.%x is %s", \ domain, bus, slot, function, \ NULLSTR(driver)); \ if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \ &data) < 0) \ ret = -1; \ - VIR_FREE(label); \ } while (0) /* Changes made to individual devices are persistent and the @@ -419,8 +415,6 @@ mymain(void) if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir); - VIR_FREE(fakerootdir); - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index b1dbf66d41..0beb9a4df4 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -18,12 +18,12 @@ static int test_virResctrlGetUnused(const void *opaque) { struct virResctrlData *data = (struct virResctrlData *) opaque; - char *system_dir = NULL; - char *resctrl_dir = NULL; + g_autofree char *system_dir = NULL; + g_autofree char *resctrl_dir = NULL; int ret = -1; g_autoptr(virResctrlAlloc) alloc = NULL; - char *schemata_str = NULL; - char *schemata_file; + g_autofree char *schemata_str = NULL; + g_autofree char *schemata_file = NULL; g_autoptr(virCaps) caps = NULL; system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir, @@ -65,10 +65,6 @@ test_virResctrlGetUnused(const void *opaque) ret = 0; cleanup: - VIR_FREE(system_dir); - VIR_FREE(resctrl_dir); - VIR_FREE(schemata_str); - VIR_FREE(schemata_file); return ret; } diff --git a/tests/virscsitest.c b/tests/virscsitest.c index 1b6a7b9ae9..d67cd23896 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -36,7 +36,7 @@ static char *virscsi_prefix; static int test1(const void *data G_GNUC_UNUSED) { - char *name = NULL; + g_autofree char *name = NULL; int ret = -1; if (!(name = virSCSIDeviceGetDevName(virscsi_prefix, @@ -48,7 +48,6 @@ test1(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(name); return ret; } @@ -66,7 +65,7 @@ test2(const void *data G_GNUC_UNUSED) bool free_dev = true; bool free_dev1 = true; virSCSIDevice *tmp = NULL; - char *sgname = NULL; + g_autofree char *sgname = NULL; int ret = -1; sgname = virSCSIDeviceGetSgName(virscsi_prefix, @@ -152,7 +151,6 @@ test2(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(sgname); if (free_dev) virSCSIDeviceFree(dev); if (free_dev1) @@ -164,8 +162,8 @@ static int create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) { int ret = -1; - char *src_path = NULL; - char *dst_path = NULL; + g_autofree char *src_path = NULL; + g_autofree char *dst_path = NULL; src_path = g_strdup_printf("%s/%s", virscsi_prefix, src_name); @@ -179,9 +177,6 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) ret = 0; cleanup: - VIR_FREE(src_path); - VIR_FREE(dst_path); - return ret; } diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 83b883524d..bbdd17da84 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -222,7 +222,7 @@ static int testStringReplace(const void *opaque G_GNUC_UNUSED) { const struct stringReplaceData *data = opaque; - char *result; + g_autofree char *result = NULL; int ret = -1; result = virStringReplace(data->haystack, @@ -238,7 +238,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(result); return ret; } @@ -402,7 +401,7 @@ static int testStripIPv6Brackets(const void *args) { const struct testStripData *data = args; int ret = -1; - char *res = NULL; + g_autofree char *res = NULL; res = g_strdup(data->string); @@ -417,7 +416,6 @@ static int testStripIPv6Brackets(const void *args) ret = 0; cleanup: - VIR_FREE(res); return ret; } @@ -425,7 +423,7 @@ static int testStripControlChars(const void *args) { const struct testStripData *data = args; int ret = -1; - char *res = NULL; + g_autofree char *res = NULL; res = g_strdup(data->string); @@ -440,7 +438,6 @@ static int testStripControlChars(const void *args) ret = 0; cleanup: - VIR_FREE(res); return ret; } @@ -454,7 +451,7 @@ static int testFilterChars(const void *args) { const struct testFilterData *data = args; int ret = -1; - char *res = NULL; + g_autofree char *res = NULL; res = g_strdup(data->string); @@ -469,7 +466,6 @@ static int testFilterChars(const void *args) ret = 0; cleanup: - VIR_FREE(res); return ret; } diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index a09b428a8a..9cf6bfec43 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -325,7 +325,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_UNUSED) static int testGetMachineName(const void *opaque G_GNUC_UNUSED) { - char *tmp = virSystemdGetMachineNameByPID(1234); + g_autofree char *tmp = virSystemdGetMachineNameByPID(1234); int ret = -1; if (!tmp) { @@ -336,7 +336,6 @@ testGetMachineName(const void *opaque G_GNUC_UNUSED) if (STREQ(tmp, "qemu-demo")) ret = 0; - VIR_FREE(tmp); return ret; } @@ -371,7 +370,7 @@ testScopeName(const void *opaque) { const struct testNameData *data = opaque; int ret = -1; - char *actual = NULL; + g_autofree char *actual = NULL; if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy))) goto cleanup; @@ -385,7 +384,6 @@ testScopeName(const void *opaque) ret = 0; cleanup: - VIR_FREE(actual); return ret; } @@ -394,7 +392,7 @@ testMachineName(const void *opaque) { const struct testNameData *data = opaque; int ret = -1; - char *actual = NULL; + g_autofree char *actual = NULL; if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root, data->id, data->name, true))) @@ -409,7 +407,6 @@ testMachineName(const void *opaque) ret = 0; cleanup: - VIR_FREE(actual); return ret; } diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 0073677b4d..7951f3d00f 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -100,9 +100,9 @@ static void checkPath(const char *path, const char *func) { - char *fullPath = NULL; - char *relPath = NULL; - char *crippledPath = NULL; + g_autofree char *fullPath = NULL; + g_autofree char *relPath = NULL; + g_autofree char *crippledPath = NULL; if (!g_path_is_absolute(path)) relPath = g_strdup_printf("./%s", path); @@ -130,10 +130,6 @@ checkPath(const char *path, printFile(path, func); } - VIR_FREE(crippledPath); - VIR_FREE(relPath); - VIR_FREE(fullPath); - return; } diff --git a/tests/viruritest.c b/tests/viruritest.c index 1962000bc8..96f29aafc0 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -49,7 +49,7 @@ static int testURIParse(const void *args) int ret = -1; virURI *uri = NULL; const struct URIParseData *data = args; - char *uristr = NULL; + g_autofree char *uristr = NULL; size_t i; bool fail = false; @@ -134,7 +134,6 @@ static int testURIParse(const void *args) ret = 0; cleanup: - VIR_FREE(uristr); virURIFree(uri); return ret; } diff --git a/tests/virusbmock.c b/tests/virusbmock.c index 57c9611e54..a1f539b8b1 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -63,7 +63,7 @@ static char *get_fake_path(const char *real_path) DIR *opendir(const char *name) { - char *path; + g_autofree char *path = NULL; DIR* ret; init_syms(); @@ -71,13 +71,12 @@ DIR *opendir(const char *name) path = get_fake_path(name); ret = realopendir(path); - VIR_FREE(path); return ret; } int open(const char *pathname, int flags, ...) { - char *path; + g_autofree char *path = NULL; int ret; va_list ap; mode_t mode = 0; @@ -98,7 +97,5 @@ int open(const char *pathname, int flags, ...) } ret = realopen(path, flags, mode); - - VIR_FREE(path); return ret; } diff --git a/tests/virusbtest.c b/tests/virusbtest.c index 39a8f1a18e..74333f0105 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -49,7 +49,7 @@ static int testDeviceFileActor(virUSBDevice *dev, const char *path, void *opaque G_GNUC_UNUSED) { - char *str = NULL; + g_autofree char *str = NULL; int ret = 0; str = g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev), @@ -61,7 +61,6 @@ static int testDeviceFileActor(virUSBDevice *dev, path, str); ret = -1; } - VIR_FREE(str); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/domaincapstest.c | 15 +++++---------- tests/domainconftest.c | 3 +-- tests/eventtest.c | 3 +-- tests/fchosttest.c | 30 ++++++++++-------------------- tests/fdstreamtest.c | 18 ++++++------------ tests/genericxml2xmltest.c | 6 ++---- tests/interfacexml2xmltest.c | 9 +++------ tests/lxcconf2xmltest.c | 18 ++++++------------ tests/lxcxml2xmltest.c | 6 ++---- tests/metadatatest.c | 9 +++------ tests/nodedevxml2xmltest.c | 9 +++------ tests/nsstest.c | 4 +--- tests/openvzutilstest.c | 9 +++------ tests/scsihosttest.c | 12 ++++-------- tests/secretxml2xmltest.c | 7 ++----- tests/securityselinuxlabeltest.c | 9 +++------ tests/sockettest.c | 4 +--- tests/testutilslxc.c | 4 +--- tests/vboxsnapshotxmltest.c | 12 ++++-------- tests/vmwarevertest.c | 6 ++---- tests/vshtabletest.c | 24 ++++++++---------------- 21 files changed, 71 insertions(+), 146 deletions(-) diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 6ab14a0179..463ff83890 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -74,7 +74,7 @@ fillQemuCaps(virDomainCaps *domCaps, virQEMUDriverConfig *cfg) { int ret = -1; - char *path = NULL; + g_autofree char *path = NULL; g_autoptr(virQEMUCaps) qemuCaps = NULL; virDomainCapsLoader *loader = &domCaps->os.loader; virDomainVirtType virtType; @@ -127,7 +127,6 @@ fillQemuCaps(virDomainCaps *domCaps, ret = 0; cleanup: - VIR_FREE(path); return ret; } #endif /* WITH_QEMU */ @@ -167,7 +166,7 @@ fillXenCaps(virDomainCaps *domCaps) static int fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps) { - virDomainCapsStringValues *firmwares = NULL; + g_autofree virDomainCapsStringValues *firmwares = NULL; int ret = -1; firmwares = g_new0(virDomainCapsStringValues, 1); @@ -180,7 +179,6 @@ fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps) ret = 0; cleanup: - VIR_FREE(firmwares); return ret; } #endif /* WITH_BHYVE */ @@ -208,8 +206,8 @@ test_virDomainCapsFormat(const void *opaque) { const struct testData *data = opaque; g_autoptr(virDomainCaps) domCaps = NULL; - char *path = NULL; - char *domCapsXML = NULL; + g_autofree char *path = NULL; + g_autofree char *domCapsXML = NULL; int ret = -1; path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name); @@ -253,8 +251,6 @@ test_virDomainCapsFormat(const void *opaque) ret = 0; cleanup: - VIR_FREE(domCapsXML); - VIR_FREE(path); return ret; } @@ -400,7 +396,7 @@ mymain(void) #define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \ do { \ - char *name = NULL; \ + g_autofree char *name = NULL; \ name = g_strdup_printf("bhyve_%s.x86_64", Name); \ struct testData data = { \ .name = name, \ @@ -412,7 +408,6 @@ mymain(void) }; \ if (virTestRun(name, test_virDomainCapsFormat, &data) < 0) \ ret = -1; \ - VIR_FREE(name); \ } while (0) DO_TEST("empty", "/bin/emulatorbin", "my-machine-type", diff --git a/tests/domainconftest.c b/tests/domainconftest.c index 66a133c13e..8b77952860 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -42,7 +42,7 @@ static int testGetFilesystem(const void *opaque) { int ret = -1; virDomainDef *def = NULL; - char *filename = NULL; + g_autofree char *filename = NULL; const struct testGetFilesystemData *data = opaque; virDomainFSDef *fsdef; @@ -72,7 +72,6 @@ static int testGetFilesystem(const void *opaque) cleanup: virDomainDefFree(def); - VIR_FREE(filename); return ret; } diff --git a/tests/eventtest.c b/tests/eventtest.c index 7a9c87b8cf..1e93c70e74 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -89,7 +89,7 @@ G_GNUC_PRINTF(3, 4) testEventReport(const char *name, bool failed, const char *msg, ...) { va_list vargs; - char *str = NULL; + g_autofree char *str = NULL; struct testEventResultData data; va_start(vargs, msg); @@ -102,7 +102,6 @@ testEventReport(const char *name, bool failed, const char *msg, ...) ignore_value(virTestRun(name, testEventResultCallback, &data)); va_end(vargs); - VIR_FREE(str); } static void diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 53d02241ca..707dd7e410 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -118,11 +118,11 @@ test3(const void *data G_GNUC_UNUSED) const char *expect_fabric_wwn = "2001000dec9877c1"; const char *expect_max_vports = "127"; const char *expect_vports = "0"; - char *wwnn = NULL; - char *wwpn = NULL; - char *fabric_wwn = NULL; - char *max_vports = NULL; - char *vports = NULL; + g_autofree char *wwnn = NULL; + g_autofree char *wwpn = NULL; + g_autofree char *fabric_wwn = NULL; + g_autofree char *max_vports = NULL; + g_autofree char *vports = NULL; int ret = -1; if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, @@ -155,11 +155,6 @@ test3(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(wwnn); - VIR_FREE(wwpn); - VIR_FREE(fabric_wwn); - VIR_FREE(max_vports); - VIR_FREE(vports); return ret; } @@ -168,7 +163,7 @@ static int test4(const void *data G_GNUC_UNUSED) { const char *expect_hostname = "host5"; - char *hostname = NULL; + g_autofree char *hostname = NULL; int ret = -1; if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX, @@ -181,7 +176,6 @@ test4(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(hostname); return ret; } @@ -193,7 +187,7 @@ static int test5(const void *data G_GNUC_UNUSED) { const char *expect_hostname = "host5"; - char *hostname = NULL; + g_autofree char *hostname = NULL; int ret = -1; if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX))) @@ -204,7 +198,6 @@ test5(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(hostname); return ret; } @@ -214,9 +207,9 @@ test6(const void *data G_GNUC_UNUSED) { const char *expect_wwnn = "2002001b32a9da4e"; const char *expect_wwpn = "2102001b32a9da4e"; - char *wwnn = NULL; - char *wwpn = NULL; - char *fabric_wwn = NULL; + g_autofree char *wwnn = NULL; + g_autofree char *wwpn = NULL; + g_autofree char *fabric_wwn = NULL; int ret = -1; if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, @@ -238,9 +231,6 @@ test6(const void *data G_GNUC_UNUSED) ret = 0; cleanup: - VIR_FREE(wwnn); - VIR_FREE(wwpn); - VIR_FREE(fabric_wwn); return ret; } diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 7a2fe27477..182c853b33 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -39,10 +39,10 @@ VIR_LOG_INIT("tests.fdstreamtest"); static int testFDStreamReadCommon(const char *scratchdir, bool blocking) { int fd = -1; - char *file = NULL; + g_autofree char *file = NULL; int ret = -1; - char *pattern = NULL; - char *buf = NULL; + g_autofree char *pattern = NULL; + g_autofree char *buf = NULL; virStreamPtr st = NULL; size_t i; virConnectPtr conn = NULL; @@ -149,9 +149,6 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking) unlink(file); if (conn) virConnectClose(conn); - VIR_FREE(file); - VIR_FREE(pattern); - VIR_FREE(buf); return ret; } @@ -169,10 +166,10 @@ static int testFDStreamReadNonblock(const void *data) static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) { int fd = -1; - char *file = NULL; + g_autofree char *file = NULL; int ret = -1; - char *pattern = NULL; - char *buf = NULL; + g_autofree char *pattern = NULL; + g_autofree char *buf = NULL; virStreamPtr st = NULL; size_t i; virConnectPtr conn = NULL; @@ -292,9 +289,6 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) unlink(file); if (conn) virConnectClose(conn); - VIR_FREE(file); - VIR_FREE(pattern); - VIR_FREE(buf); return ret; } diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 39fd6d403a..a6f974e758 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -26,8 +26,8 @@ static int testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; - char *xml_in = NULL; - char *xml_out = NULL; + g_autofree char *xml_in = NULL; + g_autofree char *xml_out = NULL; int ret = -1; xml_in = g_strdup_printf("%s/genericxml2xmlindata/%s.xml", @@ -39,8 +39,6 @@ testCompareXMLToXMLHelper(const void *data) info->different ? xml_out : xml_in, info->active_only, 0, info->expectResult); - VIR_FREE(xml_in); - VIR_FREE(xml_out); return ret; } diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c index 3785467f84..8235e701a9 100644 --- a/tests/interfacexml2xmltest.c +++ b/tests/interfacexml2xmltest.c @@ -16,8 +16,8 @@ static int testCompareXMLToXMLFiles(const char *xml) { - char *xmlData = NULL; - char *actual = NULL; + g_autofree char *xmlData = NULL; + g_autofree char *actual = NULL; int ret = -1; virInterfaceDef *dev = NULL; @@ -38,8 +38,6 @@ testCompareXMLToXMLFiles(const char *xml) ret = 0; fail: - VIR_FREE(xmlData); - VIR_FREE(actual); virInterfaceDefFree(dev); return ret; } @@ -48,14 +46,13 @@ static int testCompareXMLToXMLHelper(const void *data) { int result = -1; - char *xml = NULL; + g_autofree char *xml = NULL; xml = g_strdup_printf("%s/interfaceschemadata/%s.xml", abs_srcdir, (const char *)data); result = testCompareXMLToXMLFiles(xml); - VIR_FREE(xml); return result; } diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index df7756c931..99473a0b89 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -26,8 +26,8 @@ testCompareXMLToConfigFiles(const char *xmlfile, bool expectError) { int ret = -1; - char *config = NULL; - char *actualxml = NULL; + g_autofree char *config = NULL; + g_autofree char *actualxml = NULL; virDomainDef *vmdef = NULL; if (virTestLoadFile(configfile, &config) < 0) @@ -51,8 +51,6 @@ testCompareXMLToConfigFiles(const char *xmlfile, ret = 0; fail: - VIR_FREE(actualxml); - VIR_FREE(config); virDomainDefFree(vmdef); return ret; } @@ -67,8 +65,8 @@ testCompareXMLToConfigHelperLegacy(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *config = NULL; + g_autofree char *xml = NULL; + g_autofree char *config = NULL; xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml", abs_srcdir, info->name); @@ -77,8 +75,6 @@ testCompareXMLToConfigHelperLegacy(const void *data) result = testCompareXMLToConfigFiles(xml, config, info->expectError); - VIR_FREE(xml); - VIR_FREE(config); return result; } @@ -87,8 +83,8 @@ testCompareXMLToConfigHelperV3(const void *data) { int result = -1; const struct testInfo *info = data; - char *xml = NULL; - char *config = NULL; + g_autofree char *xml = NULL; + g_autofree char *config = NULL; xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml", abs_srcdir, info->name); @@ -97,8 +93,6 @@ testCompareXMLToConfigHelperV3(const void *data) result = testCompareXMLToConfigFiles(xml, config, info->expectError); - VIR_FREE(xml); - VIR_FREE(config); return result; } diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 69c333b9b5..8ab32acf42 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -29,8 +29,8 @@ static int testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; - char *xml_in = NULL; - char *xml_out = NULL; + g_autofree char *xml_in = NULL; + g_autofree char *xml_out = NULL; int ret = -1; xml_in = g_strdup_printf("%s/lxcxml2xmldata/lxc-%s.xml", @@ -43,8 +43,6 @@ testCompareXMLToXMLHelper(const void *data) info->active_only, info->parse_flags, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); - VIR_FREE(xml_in); - VIR_FREE(xml_out); return ret; } diff --git a/tests/metadatatest.c b/tests/metadatatest.c index e565383ce2..5112912161 100644 --- a/tests/metadatatest.c +++ b/tests/metadatatest.c @@ -92,8 +92,8 @@ verifyMetadata(virDomainPtr dom, const char *uri) { bool ret = false; - char *metadataXML = NULL; - char *metadataAPI = NULL; + g_autofree char *metadataXML = NULL; + g_autofree char *metadataAPI = NULL; if (!expectAPI) { if ((metadataAPI = virDomainGetMetadata(dom, @@ -147,8 +147,6 @@ verifyMetadata(virDomainPtr dom, ret = true; cleanup: - VIR_FREE(metadataXML); - VIR_FREE(metadataAPI); return ret; } @@ -214,7 +212,7 @@ static int testTextMetadata(const void *data) { const struct metadataTest *test = data; - char *actual = NULL; + g_autofree char *actual = NULL; int ret = -1; if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) { @@ -236,7 +234,6 @@ testTextMetadata(const void *data) ret = 0; cleanup: - VIR_FREE(actual); return ret; } diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index d8f81456ee..9e32e7d553 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -16,8 +16,8 @@ static int testCompareXMLToXMLFiles(const char *xml, const char *outfile) { - char *xmlData = NULL; - char *actual = NULL; + g_autofree char *xmlData = NULL; + g_autofree char *actual = NULL; int ret = -1; virNodeDeviceDef *dev = NULL; virNodeDevCapsDef *caps; @@ -59,8 +59,6 @@ testCompareXMLToXMLFiles(const char *xml, const char *outfile) ret = 0; fail: - VIR_FREE(xmlData); - VIR_FREE(actual); virNodeDeviceDefFree(dev); return ret; } @@ -69,7 +67,7 @@ static int testCompareXMLToXMLHelper(const void *data) { int result = -1; - char *xml = NULL; + g_autofree char *xml = NULL; g_autofree char *outfile = NULL; xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, @@ -80,7 +78,6 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(xml, outfile); - VIR_FREE(xml); return result; } diff --git a/tests/nsstest.c b/tests/nsstest.c index a4e8a4a37f..2c2e57769b 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -118,7 +118,7 @@ testGetHostByName(const void *opaque) i = 0; while (*addrList) { virSocketAddr sa; - char *ipAddr; + g_autofree char *ipAddr = NULL; void *address = *addrList; memset(&sa, 0, sizeof(sa)); @@ -138,10 +138,8 @@ testGetHostByName(const void *opaque) virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected address %s, expecting %s", ipAddr, NULLSTR(data->ipAddr[i])); - VIR_FREE(ipAddr); return -1; } - VIR_FREE(ipAddr); addrList++; i++; diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index ddb2fcbe6c..10cf307d61 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -38,8 +38,8 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) { int result = -1; size_t i; - char *conf = NULL; - char *value = NULL; + g_autofree char *conf = NULL; + g_autofree char *value = NULL; conf = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir); @@ -61,8 +61,6 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) result = 0; cleanup: - VIR_FREE(conf); - VIR_FREE(value); return result; } @@ -72,7 +70,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) { int result = -1; virDomainDef *def = NULL; - char *actual = NULL; + g_autofree char *actual = NULL; const char *expected = "<domain type='openvz'>\n" " <uuid>00000000-0000-0000-0000-000000000000</uuid>\n" @@ -133,7 +131,6 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) cleanup: virObjectUnref(driver.xmlopt); virObjectUnref(driver.caps); - VIR_FREE(actual); virDomainDefFree(def); return result; diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c index 7508ac37a3..336b3cc496 100644 --- a/tests/scsihosttest.c +++ b/tests/scsihosttest.c @@ -67,8 +67,8 @@ static int create_scsihost(const char *fakesysfsdir, const char *devicepath, const char *unique_id, const char *hostname) { - char *unique_id_path = NULL; - char *link_path = NULL; + g_autofree char *unique_id_path = NULL; + g_autofree char *link_path = NULL; char *spot; int ret = -1; int fd = -1; @@ -137,8 +137,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(unique_id_path); - VIR_FREE(link_path); return ret; } @@ -242,8 +240,8 @@ static int mymain(void) { int ret = -1; - char *fakerootdir = NULL; - char *fakesysfsdir = NULL; + g_autofree char *fakerootdir = NULL; + g_autofree char *fakesysfsdir = NULL; fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); @@ -279,8 +277,6 @@ mymain(void) cleanup: if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir); - VIR_FREE(fakerootdir); - VIR_FREE(fakesysfsdir); VIR_FREE(scsihost_class_path); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/secretxml2xmltest.c b/tests/secretxml2xmltest.c index 48f48416b5..62b82b4a24 100644 --- a/tests/secretxml2xmltest.c +++ b/tests/secretxml2xmltest.c @@ -40,8 +40,8 @@ static int testCompareXMLToXMLHelper(const void *data) { int result = -1; - char *inxml = NULL; - char *outxml = NULL; + g_autofree char *inxml = NULL; + g_autofree char *outxml = NULL; const struct testInfo *info = data; inxml = g_strdup_printf("%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name); @@ -52,9 +52,6 @@ testCompareXMLToXMLHelper(const void *data) result = testCompareXMLToXMLFiles(inxml, outxml); - VIR_FREE(inxml); - VIR_FREE(outxml); - return result; } diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index f7dd3c866a..cd604eda31 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -59,7 +59,7 @@ testUserXattrEnabled(void) int ret = -1; ssize_t len; const char *con_value = "system_u:object_r:svirt_image_t:s0:c41,c264"; - char *path = NULL; + g_autofree char *path = NULL; path = g_strdup_printf("%s/securityselinuxlabeldata/testxattr", abs_builddir); if (g_mkdir_with_parents(abs_builddir "/securityselinuxlabeldata", 0777) < 0 || @@ -79,7 +79,6 @@ testUserXattrEnabled(void) cleanup: unlink(path); rmdir(abs_builddir "/securityselinuxlabeldata"); - VIR_FREE(path); return ret; } @@ -101,9 +100,9 @@ testSELinuxLoadFileList(const char *testname, size_t *nfiles) { int ret = -1; - char *path = NULL; + g_autofree char *path = NULL; FILE *fp = NULL; - char *line = NULL; + g_autofree char *line = NULL; *files = NULL; *nfiles = 0; @@ -153,8 +152,6 @@ testSELinuxLoadFileList(const char *testname, cleanup: VIR_FORCE_FCLOSE(fp); - VIR_FREE(path); - VIR_FREE(line); return ret; } diff --git a/tests/sockettest.c b/tests/sockettest.c index e9654fcebb..332def2c93 100644 --- a/tests/sockettest.c +++ b/tests/sockettest.c @@ -43,7 +43,7 @@ static int testParse(virSocketAddr *addr, const char *addrstr, int family, bool static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass) { - char *newaddrstr; + g_autofree char *newaddrstr = NULL; newaddrstr = virSocketAddrFormat(addr); if (!newaddrstr) @@ -51,10 +51,8 @@ static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass) if (STRNEQ(newaddrstr, addrstr)) { virTestDifference(stderr, addrstr, newaddrstr); - VIR_FREE(newaddrstr); return pass ? -1 : 0; } else { - VIR_FREE(newaddrstr); return pass ? 0 : -1; } } diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c index 9ab57f7ccb..0139de7437 100644 --- a/tests/testutilslxc.c +++ b/tests/testutilslxc.c @@ -39,15 +39,13 @@ testLXCCapsInit(void) if (virTestGetDebug()) { - char *caps_str; + g_autofree char *caps_str = NULL; caps_str = virCapabilitiesFormatXML(caps); if (!caps_str) goto error; VIR_TEST_DEBUG("LXC driver capabilities:\n%s", caps_str); - - VIR_FREE(caps_str); } return caps; diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index f5f8fe36b9..da39561456 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -46,9 +46,9 @@ testFilterXML(char *xml) static int testCompareXMLtoXMLFiles(const char *xml) { - char *xmlData = NULL; - char *actual = NULL; - char *pathResult = NULL; + g_autofree char *xmlData = NULL; + g_autofree char *actual = NULL; + g_autofree char *pathResult = NULL; int ret = -1; virVBoxSnapshotConfMachine *machine = NULL; @@ -84,10 +84,7 @@ testCompareXMLtoXMLFiles(const char *xml) cleanup: unlink(pathResult); rmdir(abs_builddir "/vboxsnapshotxmldata"); - VIR_FREE(xmlData); - VIR_FREE(actual); virVBoxSnapshotConfMachineFree(machine); - VIR_FREE(pathResult); return ret; } @@ -96,14 +93,13 @@ static int testCompareXMLToXMLHelper(const void *data) { int result = -1; - char *xml = NULL; + g_autofree char *xml = NULL; xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir, (const char *)data); result = testCompareXMLtoXMLFiles(xml); - VIR_FREE(xml); return result; } diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c index fa909ad022..7cb358795f 100644 --- a/tests/vmwarevertest.c +++ b/tests/vmwarevertest.c @@ -38,8 +38,8 @@ testVerStrParse(const void *data) { const struct testInfo *info = data; int ret = -1; - char *path = NULL; - char *databuf = NULL; + g_autofree char *path = NULL; + g_autofree char *databuf = NULL; unsigned long version; int vmware_type; @@ -63,8 +63,6 @@ testVerStrParse(const void *data) ret = 0; cleanup: - VIR_FREE(path); - VIR_FREE(databuf); return ret; } diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index 41c33b1701..804aaf4d9c 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -119,7 +119,7 @@ static int testUnicode(const void *opaque G_GNUC_UNUSED) { int ret = 0; - char *act = NULL; + g_autofree char *act = NULL; const char *exp = " Id 名稱 государство\n" @@ -141,7 +141,6 @@ testUnicode(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act); vshTableFree(table); return ret; } @@ -151,7 +150,7 @@ static int testUnicodeArabic(const void *opaque G_GNUC_UNUSED) { int ret = 0; - char *act = NULL; + g_autofree char *act = NULL; const char *exp = " ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ ﺓ ﺎﻠﺼﻋ ﺍﻸﺜﻧﺎﻧ\n" @@ -184,7 +183,6 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act); vshTableFree(table); return ret; } @@ -200,7 +198,7 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) "--------------------------\n" " 1\u200B fedora28 run\u200Bning\n" " 2 rhel7.5 running\n"; - char *act = NULL; + g_autofree char *act = NULL; wchar_t wc; /* If this char is not classed as printable, the actual @@ -222,7 +220,6 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act); vshTableFree(table); return ret; } @@ -237,7 +234,7 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) "--------------------------\n" " 1 fědora28 running\n" " 2 rhel running\n"; - char *act = NULL; + g_autofree char *act = NULL; table = vshTableNew("Id", "Náme", "Ⓢtatus", NULL); if (!table) @@ -250,7 +247,6 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act); vshTableFree(table); return ret; } @@ -266,7 +262,7 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) "----------------------------------\n" " 1 f\\x07edora28 running\n" " 2 rhel7.5 running\n"; - char *act = NULL; + g_autofree char *act = NULL; table = vshTableNew("I\td", "Name", "Status", NULL); if (!table) @@ -279,7 +275,6 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act); vshTableFree(table); return ret; } @@ -307,9 +302,9 @@ testNTables(const void *opaque G_GNUC_UNUSED) " 2\n" " 3\n" " 4\n"; - char *act1 = NULL; - char *act2 = NULL; - char *act3 = NULL; + g_autofree char *act1 = NULL; + g_autofree char *act2 = NULL; + g_autofree char *act3 = NULL; table1 = vshTableNew("Id", "Name", "Status", NULL); if (!table1) @@ -341,9 +336,6 @@ testNTables(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - VIR_FREE(act1); - VIR_FREE(act2); - VIR_FREE(act3); vshTableFree(table1); vshTableFree(table2); vshTableFree(table3); -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemucapsprobemock.c | 3 +-- tests/qemucommandutiltest.c | 3 +-- tests/qemumonitorjsontest.c | 12 ++++-------- tests/virnetdaemontest.c | 3 +-- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c index 00670101ce..27539d04a1 100644 --- a/tests/qemucapsprobemock.c +++ b/tests/qemucapsprobemock.c @@ -87,7 +87,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, const char *line, qemuMonitorMessage *msg) { - virJSONValue *value = NULL; + g_autoptr(virJSONValue) value = NULL; g_autofree char *json = NULL; int ret; @@ -115,6 +115,5 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, } cleanup: - virJSONValueFree(value); return ret; } diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index 6b5e477849..e1cab0be90 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -37,7 +37,7 @@ static int testQemuCommandBuildFromJSON(const void *opaque) { const testQemuCommandBuildObjectFromJSONData *data = opaque; - virJSONValue *val = NULL; + g_autoptr(virJSONValue) val = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autofree char *result = NULL; int ret = -1; @@ -65,7 +65,6 @@ testQemuCommandBuildFromJSON(const void *opaque) ret = 0; cleanup: - virJSONValueFree(val); return ret; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index c64c5c6b6f..542b35850e 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2507,8 +2507,8 @@ testBlockNodeNameDetect(const void *opaque) const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-"; g_autofree char *resultFile = NULL; g_autofree char *actual = NULL; - virJSONValue *namedNodesJson = NULL; - virJSONValue *blockstatsJson = NULL; + g_autoptr(virJSONValue) namedNodesJson = NULL; + g_autoptr(virJSONValue) blockstatsJson = NULL; GHashTable *nodedata = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; int ret = -1; @@ -2541,8 +2541,6 @@ testBlockNodeNameDetect(const void *opaque) cleanup: virHashFree(nodedata); - virJSONValueFree(namedNodesJson); - virJSONValueFree(blockstatsJson); return ret; } @@ -2584,7 +2582,7 @@ testQAPISchemaValidate(const void *opaque) const struct testQAPISchemaData *data = opaque; g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER; virJSONValue *schemaroot; - virJSONValue *json = NULL; + g_autoptr(virJSONValue) json = NULL; int ret = -1; if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0) @@ -2610,7 +2608,6 @@ testQAPISchemaValidate(const void *opaque) cleanup: - virJSONValueFree(json); return ret; } @@ -2927,7 +2924,7 @@ mymain(void) virQEMUDriver driver; testQemuMonitorJSONSimpleFuncData simpleFunc; struct testQAPISchemaData qapiData; - virJSONValue *metaschema = NULL; + g_autoptr(virJSONValue) metaschema = NULL; g_autofree char *metaschemastr = NULL; if (qemuTestDriverInit(&driver) < 0) @@ -3220,7 +3217,6 @@ mymain(void) DO_TEST(qemuMonitorJSONGetCPUModelBaseline); cleanup: - virJSONValueFree(metaschema); virHashFree(qapiData.schema); qemuTestDriverFree(&driver); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 2522a4c8ea..70af1480df 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -188,7 +188,7 @@ static char *testGenerateJSON(const char *server_name) { virNetDaemon *dmn = NULL; virNetServer *srv = NULL; - virJSONValue *json = NULL; + g_autoptr(virJSONValue) json = NULL; char *jsonstr = NULL; bool has_ipv4, has_ipv6; @@ -226,7 +226,6 @@ static char *testGenerateJSON(const char *server_name) virNetServerClose(srv); virObjectUnref(srv); virObjectUnref(dmn); - virJSONValueFree(json); if (!jsonstr) virDispatchError(NULL); return jsonstr; -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemumonitorjsontest.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 542b35850e..b68351d9d8 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2158,7 +2158,7 @@ static int testQemuMonitorJSONGetCPUData(const void *opaque) { const struct testCPUData *data = opaque; - virCPUData *cpuData = NULL; + g_autoptr(virCPUData) cpuData = NULL; g_autofree char *jsonFile = NULL; g_autofree char *dataFile = NULL; g_autofree char *jsonStr = NULL; @@ -2208,7 +2208,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque) ret = 0; cleanup: - virCPUDataFree(cpuData); return ret; } @@ -2217,7 +2216,7 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - virCPUData *cpuData = NULL; + g_autoptr(virCPUData) cpuData = NULL; int rv, ret = -1; g_autoptr(qemuMonitorTest) test = NULL; @@ -2251,7 +2250,6 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque) ret = 0; cleanup: - virCPUDataFree(cpuData); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/securityselinuxlabeltest.c | 3 +-- tests/testutils.c | 5 +---- tests/virhostcputest.c | 7 ++----- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index cd604eda31..2fb6e0c6b7 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -101,7 +101,7 @@ testSELinuxLoadFileList(const char *testname, { int ret = -1; g_autofree char *path = NULL; - FILE *fp = NULL; + g_autoptr(FILE) fp = NULL; g_autofree char *line = NULL; *files = NULL; @@ -151,7 +151,6 @@ testSELinuxLoadFileList(const char *testname, ret = 0; cleanup: - VIR_FORCE_FCLOSE(fp); return ret; } diff --git a/tests/testutils.c b/tests/testutils.c index 5e9835ee89..d98246ec75 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -223,7 +223,7 @@ virTestRunLog(int *ret, int virTestLoadFile(const char *file, char **buf) { - FILE *fp = fopen(file, "r"); + g_autoptr(FILE) fp = fopen(file, "r"); struct stat st; char *tmp; int len, tmplen, buflen; @@ -235,7 +235,6 @@ virTestLoadFile(const char *file, char **buf) if (fstat(fileno(fp), &st) < 0) { fprintf(stderr, "%s: failed to fstat: %s\n", file, g_strerror(errno)); - VIR_FORCE_FCLOSE(fp); return -1; } @@ -263,13 +262,11 @@ virTestLoadFile(const char *file, char **buf) } if (ferror(fp)) { fprintf(stderr, "%s: read failed: %s\n", file, g_strerror(errno)); - VIR_FORCE_FCLOSE(fp); VIR_FREE(*buf); return -1; } } - VIR_FORCE_FCLOSE(fp); return 0; } diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index f935df0f63..c80cd1581c 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -33,7 +33,7 @@ linuxTestCompareFiles(const char *cpuinfofile, int ret = -1; g_autofree char *actualData = NULL; virNodeInfo nodeinfo; - FILE *cpuinfo; + g_autoptr(FILE) cpuinfo = NULL; cpuinfo = fopen(cpuinfofile, "r"); if (!cpuinfo) { @@ -51,10 +51,8 @@ linuxTestCompareFiles(const char *cpuinfofile, if (virGetLastErrorCode()) VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage()); } - VIR_FORCE_FCLOSE(cpuinfo); goto fail; } - VIR_FORCE_FCLOSE(cpuinfo); actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " "Cores: %u, Threads: %u\n", @@ -109,7 +107,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, { int ret = -1; g_autofree char *actualData = NULL; - FILE *cpustat = NULL; + g_autoptr(FILE) cpustat = NULL; virNodeCPUStatsPtr params = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; size_t i; @@ -148,7 +146,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, ret = 0; fail: - VIR_FORCE_FCLOSE(cpustat); VIR_FREE(params); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/fdstreamtest.c | 6 ++---- tests/scsihosttest.c | 3 +-- tests/virfiletest.c | 6 ++---- tests/virnettlshelpers.c | 4 +--- tests/virpcimock.c | 4 +--- tests/virrotatingfiletest.c | 4 +--- 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 182c853b33..96519e91c2 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -38,7 +38,7 @@ VIR_LOG_INIT("tests.fdstreamtest"); static int testFDStreamReadCommon(const char *scratchdir, bool blocking) { - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autofree char *file = NULL; int ret = -1; g_autofree char *pattern = NULL; @@ -144,7 +144,6 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking) cleanup: if (st) virStreamFree(st); - VIR_FORCE_CLOSE(fd); if (file != NULL) unlink(file); if (conn) @@ -165,7 +164,7 @@ static int testFDStreamReadNonblock(const void *data) static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) { - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autofree char *file = NULL; int ret = -1; g_autofree char *pattern = NULL; @@ -284,7 +283,6 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) cleanup: if (st) virStreamFree(st); - VIR_FORCE_CLOSE(fd); if (file != NULL) unlink(file); if (conn) diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c index 336b3cc496..aeb91da691 100644 --- a/tests/scsihosttest.c +++ b/tests/scsihosttest.c @@ -71,7 +71,7 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, g_autofree char *link_path = NULL; char *spot; int ret = -1; - int fd = -1; + VIR_AUTOCLOSE fd = -1; unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id", fakesysfsdir, devicepath); @@ -136,7 +136,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, ret = 0; cleanup: - VIR_FORCE_CLOSE(fd); return ret; } diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 019c230cea..a6e722b4d2 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -194,7 +194,7 @@ holesSupported(void) { off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1}; off_t tmp; - int fd; + VIR_AUTOCLOSE fd = -1; bool ret = false; if ((fd = makeSparseFile(offsets, true)) < 0) @@ -229,7 +229,6 @@ holesSupported(void) ret = true; cleanup: - VIR_FORCE_CLOSE(fd); return ret; } @@ -261,7 +260,7 @@ static int testFileInData(const void *opaque) { const struct testFileInData *data = opaque; - int fd = -1; + VIR_AUTOCLOSE fd = -1; int ret = -1; size_t i; @@ -303,7 +302,6 @@ testFileInData(const void *opaque) ret = 0; cleanup: - VIR_FORCE_CLOSE(fd); return ret; } diff --git a/tests/virnettlshelpers.c b/tests/virnettlshelpers.c index 905e633e60..c9e2b372bb 100644 --- a/tests/virnettlshelpers.c +++ b/tests/virnettlshelpers.c @@ -396,7 +396,7 @@ void testTLSWriteCertChain(const char *filename, size_t ncerts) { size_t i; - int fd; + VIR_AUTOCLOSE fd = -1; int err; static char buffer[1024*1024]; size_t size; @@ -420,8 +420,6 @@ void testTLSWriteCertChain(const char *filename, abort(); } } - - VIR_FORCE_CLOSE(fd); } diff --git a/tests/virpcimock.c b/tests/virpcimock.c index ead810d412..d4d43aac51 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -177,7 +177,7 @@ make_file(const char *path, const char *value, ssize_t len) { - int fd = -1; + VIR_AUTOCLOSE fd = -1; g_autofree char *filepath = NULL; if (value && len == -1) len = strlen(value); @@ -189,8 +189,6 @@ make_file(const char *path, if (value && safewrite(fd, value, len) != len) ABORT("Unable to write: %s", filepath); - - VIR_FORCE_CLOSE(fd); } static void diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c index 87699936cb..ede65848ea 100644 --- a/tests/virrotatingfiletest.c +++ b/tests/virrotatingfiletest.c @@ -125,7 +125,7 @@ static int testRotatingFileInitOne(const char *filename, unlink(filename); } else { char buf[1024]; - int fd; + VIR_AUTOCLOSE fd = -1; VIR_DEBUG("Creating %s size %zu", filename, (size_t)size); @@ -142,12 +142,10 @@ static int testRotatingFileInitOne(const char *filename, if (safewrite(fd, buf, towrite) != towrite) { fprintf(stderr, "Cannot write to %s\n", filename); - VIR_FORCE_CLOSE(fd); return -1; } size -= towrite; } - VIR_FORCE_CLOSE(fd); } return 0; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vshtabletest.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index 804aaf4d9c..569d7a852f 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -55,7 +55,7 @@ testVshTableHeader(const void *opaque G_GNUC_UNUSED) " 1 fedora28 running\n" " 2 rhel7.5 running\n"; - vshTable *table = vshTableNew("Id", "Name", "State", + g_autoptr(vshTable) table = vshTableNew("Id", "Name", "State", NULL); //to ask about return if (!table) goto cleanup; @@ -75,7 +75,6 @@ testVshTableHeader(const void *opaque G_GNUC_UNUSED) cleanup: VIR_FREE(act); - vshTableFree(table); return ret; } @@ -84,7 +83,7 @@ testVshTableRowAppend(const void *opaque G_GNUC_UNUSED) { int ret = 0; - vshTable *table = vshTableNew("Id", "Name", NULL); + g_autoptr(vshTable) table = vshTableNew("Id", "Name", NULL); if (!table) goto cleanup; @@ -111,7 +110,6 @@ testVshTableRowAppend(const void *opaque G_GNUC_UNUSED) } cleanup: - vshTableFree(table); return ret; } @@ -126,7 +124,7 @@ testUnicode(const void *opaque G_GNUC_UNUSED) "-----------------------------------------\n" " 1 fedora28 running\n" " 2 つへソrhel7.5つへソ running\n"; - vshTable *table; + g_autoptr(vshTable) table = NULL; table = vshTableNew("Id", "名稱", "государство", NULL); if (!table) @@ -141,7 +139,6 @@ testUnicode(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table); return ret; } @@ -157,7 +154,7 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) "-------------------------------------------------------------------------------------------\n" " 1 ﻉﺪﻴﻟ ﺎﻠﺜﻘﻴﻟ ﻕﺎﻣ ﻊﻧ, ٣٠ ﻎﻴﻨﻳﺍ ﻮﺘﻧﺎﻤﺗ ﺎﻠﺛﺎﻠﺛ، ﺄﺳﺭ, ﺩﻮﻟ ﺩﻮﻟ. ﺄﻣﺎﻣ ﺍ ﺎﻧ ﻲﻜﻧ\n" " ﺺﻔﺣﺓ ﺖﻜﺘﻴﻛﺍً ﻊﻟ, ﺎﻠﺠﻧﻭﺩ ﻭﺎﻠﻌﺗﺍﺩ ﺵﺭ\n"; - vshTable *table; + g_autoptr(vshTable) table = NULL; wchar_t wc; /* If this char is not classed as printable, the actual @@ -183,7 +180,6 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table); return ret; } @@ -192,7 +188,7 @@ static int testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) { int ret = 0; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; const char *exp = " I\u200Bd Name \u200BStatus\n" "--------------------------\n" @@ -220,7 +216,6 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table); return ret; } @@ -228,7 +223,7 @@ static int testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) { int ret = 0; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; const char *exp = " Id Náme Ⓢtatus\n" "--------------------------\n" @@ -247,7 +242,6 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table); return ret; } @@ -256,7 +250,7 @@ static int testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) { int ret = 0; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; const char *exp = " I\\x09d Name Status\n" "----------------------------------\n" @@ -275,7 +269,6 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table); return ret; } @@ -283,9 +276,9 @@ static int testNTables(const void *opaque G_GNUC_UNUSED) { int ret = 0; - vshTable *table1 = NULL; - vshTable *table2 = NULL; - vshTable *table3 = NULL; + g_autoptr(vshTable) table1 = NULL; + g_autoptr(vshTable) table2 = NULL; + g_autoptr(vshTable) table3 = NULL; const char *exp1 = " Id Name Status\n" "--------------------------\n" @@ -336,9 +329,6 @@ testNTables(const void *opaque G_GNUC_UNUSED) ret = -1; cleanup: - vshTableFree(table1); - vshTableFree(table2); - vshTableFree(table3); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/domainconftest.c | 3 +-- tests/libxlxml2domconfigtest.c | 3 +-- tests/lxcconf2xmltest.c | 3 +-- tests/openvzutilstest.c | 3 +-- tests/qemuagenttest.c | 3 +-- tests/securityselinuxlabeltest.c | 3 +-- tests/testutils.c | 3 +-- tests/vmx2xmltest.c | 3 +-- tests/xlconfigtest.c | 6 ++---- tests/xmconfigtest.c | 6 ++---- tests/xml2vmxtest.c | 3 +-- 11 files changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/domainconftest.c b/tests/domainconftest.c index 8b77952860..aaf58bcf93 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -41,7 +41,7 @@ struct testGetFilesystemData { static int testGetFilesystem(const void *opaque) { int ret = -1; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; g_autofree char *filename = NULL; const struct testGetFilesystemData *data = opaque; virDomainFSDef *fsdef; @@ -71,7 +71,6 @@ static int testGetFilesystem(const void *opaque) ret = 0; cleanup: - virDomainDefFree(def); return ret; } diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 2bc5c26223..015597eb44 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -52,7 +52,7 @@ testCompareXMLToDomConfig(const char *xmlfile, libxl_domain_config expectconfig; xentoollog_logger *log = NULL; virPortAllocatorRange *gports = NULL; - virDomainDef *vmdef = NULL; + g_autoptr(virDomainDef) vmdef = NULL; g_autofree char *actualjson = NULL; g_autofree char *tempjson = NULL; g_autofree char *expectjson = NULL; @@ -128,7 +128,6 @@ testCompareXMLToDomConfig(const char *xmlfile, vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); - virDomainDefFree(vmdef); virPortAllocatorRangeFree(gports); libxl_domain_config_dispose(&actualconfig); libxl_domain_config_dispose(&expectconfig); diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 99473a0b89..be70671d68 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -28,7 +28,7 @@ testCompareXMLToConfigFiles(const char *xmlfile, int ret = -1; g_autofree char *config = NULL; g_autofree char *actualxml = NULL; - virDomainDef *vmdef = NULL; + g_autoptr(virDomainDef) vmdef = NULL; if (virTestLoadFile(configfile, &config) < 0) goto fail; @@ -51,7 +51,6 @@ testCompareXMLToConfigFiles(const char *xmlfile, ret = 0; fail: - virDomainDefFree(vmdef); return ret; } diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 10cf307d61..3ebf38f104 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -69,7 +69,7 @@ static int testReadNetworkConf(const void *data G_GNUC_UNUSED) { int result = -1; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; g_autofree char *actual = NULL; const char *expected = "<domain type='openvz'>\n" @@ -131,7 +131,6 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) cleanup: virObjectUnref(driver.xmlopt); virObjectUnref(driver.caps); - virDomainDefFree(def); return result; } diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index a447c93494..10d02bd1b4 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -313,7 +313,7 @@ testQemuAgentGetFSInfo(const void *data) { virDomainXMLOption *xmlopt = (virDomainXMLOption *)data; qemuMonitorTest *test = NULL; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; qemuAgentFSInfo **info = NULL; int ret = -1, ninfo = 0, i; @@ -405,7 +405,6 @@ testQemuAgentGetFSInfo(const void *data) for (i = 0; i < ninfo; i++) qemuAgentFSInfoFree(info[i]); VIR_FREE(info); - virDomainDefFree(def); qemuMonitorTestFree(test); return ret; } diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 2fb6e0c6b7..2e5941d7ef 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -278,7 +278,7 @@ testSELinuxLabeling(const void *opaque) testSELinuxFile *files = NULL; size_t nfiles = 0; size_t i; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; if (testSELinuxLoadFileList(testname, &files, &nfiles) < 0) goto cleanup; @@ -301,7 +301,6 @@ testSELinuxLabeling(const void *opaque) if (testSELinuxDeleteDisks(files, nfiles) < 0) VIR_WARN("unable to fully clean up"); - virDomainDefFree(def); for (i = 0; i < nfiles; i++) { VIR_FREE(files[i].file); VIR_FREE(files[i].context); diff --git a/tests/testutils.c b/tests/testutils.c index d98246ec75..7e0d273ed4 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1009,7 +1009,7 @@ testCompareDomXML2XMLFiles(virCaps *caps G_GNUC_UNUSED, g_autofree char *actual = NULL; int ret = -1; testCompareDomXML2XMLResult result; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; @@ -1059,7 +1059,6 @@ testCompareDomXML2XMLFiles(virCaps *caps G_GNUC_UNUSED, expectResult, result); } - virDomainDefFree(def); return ret; } diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index cd44a84a07..b7f232eb77 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -71,7 +71,7 @@ testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) int ret = -1; g_autofree char *vmxData = NULL; g_autofree char *formatted = NULL; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; if (virTestLoadFile(vmx, &vmxData) < 0) return -1; @@ -102,7 +102,6 @@ testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) ret = 0; cleanup: - virDomainDefFree(def); return ret; } diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 95ee670b00..6717377982 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -69,7 +69,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) g_autoptr(virConnect) conn = NULL; int wrote = 4096; int ret = -1; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; g_autofree char *replacedXML = NULL; gotxlcfgData = g_new0(char, wrote); @@ -107,7 +107,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) ret = 0; fail: - virDomainDefFree(def); return ret; } @@ -124,7 +123,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) g_autoptr(virConf) conf = NULL; int ret = -1; g_autoptr(virConnect) conn = NULL; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; g_autofree char *replacedXML = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); @@ -158,7 +157,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) ret = 0; fail: - virDomainDefFree(def); return ret; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index a756f752f8..bd23e5fd5d 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -44,7 +44,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) int ret = -1; g_autoptr(virConnect) conn = NULL; int wrote = 4096; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; gotxmcfgData = g_new0(char, wrote); @@ -73,7 +73,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) ret = 0; fail: - virDomainDefFree(def); return ret; } @@ -85,7 +84,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml) g_autofree char *gotxml = NULL; g_autoptr(virConf) conf = NULL; int ret = -1; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); if (virTestLoadFile(xmcfg, &xmcfgData) < 0) @@ -106,7 +105,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml) ret = 0; fail: - virDomainDefFree(def); return ret; } diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index cb70f70f4f..8a03237b16 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -72,7 +72,7 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) { int result = -1; g_autofree char *formatted = NULL; - virDomainDef *def = NULL; + g_autoptr(virDomainDef) def = NULL; def = virDomainDefParseFile(xml, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE); @@ -95,7 +95,6 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) result = 0; failure: - virDomainDefFree(def); return result; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemuagenttest.c | 28 ++++++-------------- tests/qemucapsprobemock.c | 3 +-- tests/qemucommandutiltest.c | 9 +++---- tests/qemumonitorjsontest.c | 50 +++++++++++++++--------------------- tests/qemumonitortestutils.c | 45 ++++++++++---------------------- tests/qemuxml2argvtest.c | 21 ++++----------- 6 files changed, 51 insertions(+), 105 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 10d02bd1b4..bef6dfd152 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -471,51 +471,39 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTest *test, virJSONValue *args; const char *cmdname; const char *mode; - int ret = -1; data = qemuMonitorTestItemGetPrivateData(item); if (!(val = virJSONValueFromString(cmdstr))) return -1; - if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr); - goto cleanup; - } + if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) + return qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr); if (STRNEQ(cmdname, "guest-shutdown")) { - ret = qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown", + return qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown", cmdname); - goto cleanup; } if (!(args = virJSONValueObjectGet(val, "arguments"))) { - ret = qemuMonitorTestAddErrorResponse(test, + return qemuMonitorTestAddErrorResponse(test, "Missing arguments section"); - goto cleanup; } - if (!(mode = virJSONValueObjectGetString(args, "mode"))) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing shutdown mode"); - goto cleanup; - } + if (!(mode = virJSONValueObjectGetString(args, "mode"))) + return qemuMonitorTestAddErrorResponse(test, "Missing shutdown mode"); if (STRNEQ(mode, data->mode)) { - ret = qemuMonitorTestAddErrorResponse(test, + return qemuMonitorTestAddErrorResponse(test, "expected shutdown mode '%s' got '%s'", data->mode, mode); - goto cleanup; } /* now don't reply but return a qemu agent event */ qemuAgentNotifyEvent(qemuMonitorTestGetAgent(test), data->event); - ret = 0; - - cleanup: - return ret; - + return 0; } diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c index 27539d04a1..915036d178 100644 --- a/tests/qemucapsprobemock.c +++ b/tests/qemucapsprobemock.c @@ -104,7 +104,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, /* Ignore QMP greeting */ if (virJSONValueObjectHasKey(value, "QMP")) - goto cleanup; + return 0; if (first) first = false; @@ -114,6 +114,5 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, printLineSkipEmpty(json, stdout); } - cleanup: return ret; } diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index e1cab0be90..ae86ef9ea0 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -40,7 +40,6 @@ testQemuCommandBuildFromJSON(const void *opaque) g_autoptr(virJSONValue) val = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autofree char *result = NULL; - int ret = -1; if (!(val = virJSONValueFromString(data->props))) { fprintf(stderr, "Failed to parse JSON string '%s'", data->props); @@ -51,7 +50,7 @@ testQemuCommandBuildFromJSON(const void *opaque) fprintf(stderr, "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n", data->props); - goto cleanup; + return -1; } result = virBufferContentAndReset(&buf); @@ -60,12 +59,10 @@ testQemuCommandBuildFromJSON(const void *opaque) fprintf(stderr, "\nFailed to create object string. " "\nExpected:\n'%s'\nGot:\n'%s'", NULLSTR(data->expectprops), NULLSTR(result)); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static int diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index b68351d9d8..1e4c2fd14e 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1719,7 +1719,6 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; - int ret = -1; qemuMonitorMigrationStats stats, expectedStats; g_autofree char *error = NULL; g_autoptr(qemuMonitorTest) test = NULL; @@ -1756,33 +1755,31 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque) " }," " \"id\": \"libvirt-14\"" "}") < 0) - goto cleanup; + return -1; if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test), &stats, &error) < 0) - goto cleanup; + return -1; if (memcmp(&stats, &expectedStats, sizeof(stats)) != 0 || error) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Invalid migration statistics"); - goto cleanup; + return -1; } memset(&stats, 0, sizeof(stats)); if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test), &stats, &error) < 0) - goto cleanup; + return -1; if (stats.status != QEMU_MONITOR_MIGRATION_STATUS_ERROR || STRNEQ_NULLABLE(error, "It's broken")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Invalid failed migration status"); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -2163,7 +2160,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque) g_autofree char *dataFile = NULL; g_autofree char *jsonStr = NULL; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) @@ -2175,7 +2171,7 @@ testQemuMonitorJSONGetCPUData(const void *opaque) abs_srcdir, data->name); if (virTestLoadFile(jsonFile, &jsonStr) < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddItem(test, "qom-list", "{" @@ -2191,24 +2187,22 @@ testQemuMonitorJSONGetCPUData(const void *opaque) " ]," " \"id\": \"libvirt-19\"" "}") < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddItem(test, "qom-get", jsonStr) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test), &cpuData, NULL) < 0) - goto cleanup; + return -1; if (!(actual = virCPUDataFormat(cpuData))) - goto cleanup; + return -1; if (virTestCompareToFile(actual, dataFile) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -2217,7 +2211,7 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque) const testGenericData *data = opaque; virDomainXMLOption *xmlopt = data->xmlopt; g_autoptr(virCPUData) cpuData = NULL; - int rv, ret = -1; + int rv; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -2231,26 +2225,24 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque) " \"desc\": \"The command qom-list has not been found\"" " }" "}") < 0) - goto cleanup; + return -1; rv = qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test), &cpuData, NULL); if (rv != -2) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected return value %d, expecting -2", rv); - goto cleanup; + return -1; } if (cpuData) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected allocation of data = %p, expecting NULL", cpuData); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -2584,10 +2576,10 @@ testQAPISchemaValidate(const void *opaque) int ret = -1; if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0) - goto cleanup; + return -1; if (!(json = virJSONValueFromString(data->json))) - goto cleanup; + return -1; if ((testQEMUSchemaValidate(json, schemaroot, data->schema, false, &debug) == 0) != data->success) { @@ -2604,8 +2596,6 @@ testQAPISchemaValidate(const void *opaque) VIR_FREE(debugstr); } - - cleanup: return ret; } diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 8618e6bbef..71b26c326e 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -708,38 +708,25 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTest *test, unsigned long long id; const char *cmdname; g_autofree char *retmsg = NULL; - int ret = -1; if (!(val = virJSONValueFromString(cmdstr))) return -1; - if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing guest-sync command name"); - goto cleanup; - } + if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) + return qemuMonitorTestAddErrorResponse(test, "Missing guest-sync command name"); - if (STRNEQ(cmdname, "guest-sync")) { - ret = qemuMonitorTestAddInvalidCommandResponse(test, "guest-sync", cmdname); - goto cleanup; - } + if (STRNEQ(cmdname, "guest-sync")) + return qemuMonitorTestAddInvalidCommandResponse(test, "guest-sync", cmdname); - if (!(args = virJSONValueObjectGet(val, "arguments"))) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing arguments for guest-sync"); - goto cleanup; - } + if (!(args = virJSONValueObjectGet(val, "arguments"))) + return qemuMonitorTestAddErrorResponse(test, "Missing arguments for guest-sync"); - if (virJSONValueObjectGetNumberUlong(args, "id", &id)) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing id for guest sync"); - goto cleanup; - } + if (virJSONValueObjectGetNumberUlong(args, "id", &id)) + return qemuMonitorTestAddErrorResponse(test, "Missing id for guest sync"); retmsg = g_strdup_printf("{\"return\":%llu}", id); - - ret = qemuMonitorTestAddResponse(test, retmsg); - - cleanup: - return ret; + return qemuMonitorTestAddResponse(test, retmsg); } @@ -1194,10 +1181,10 @@ qemuMonitorTestNewFromFile(const char *fileName, char *singleReply; if (virTestLoadFile(fileName, &json) < 0) - goto cleanup; + return NULL; if (simple && !(test = qemuMonitorTestNewSimple(xmlopt))) - goto cleanup; + return NULL; /* Our JSON parser expects replies to be separated by a newline character. * Hence we must preprocess the file a bit. */ @@ -1237,13 +1224,11 @@ qemuMonitorTestNewFromFile(const char *fileName, if (test && qemuMonitorTestAddItem(test, NULL, singleReply) < 0) goto error; - cleanup: return test; error: qemuMonitorTestFree(test); - test = NULL; - goto cleanup; + return NULL; } @@ -1341,7 +1326,7 @@ qemuMonitorTestNewFromFileFull(const char *fileName, if (!(ret = qemuMonitorTestNew(driver->xmlopt, vm, driver, NULL, qmpschema))) - goto cleanup; + return NULL; tmp = jsonstr; command = tmp; @@ -1393,13 +1378,11 @@ qemuMonitorTestNewFromFileFull(const char *fileName, goto error; } - cleanup: return ret; error: qemuMonitorTestFree(ret); - ret = NULL; - goto cleanup; + return NULL; } diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 90b7da8055..4cc9fccd4f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -107,7 +107,6 @@ fakeStoragePoolLookupByName(virConnectPtr conn, const char *name) { g_autofree char *xmlpath = NULL; - virStoragePoolPtr ret = NULL; if (STRNEQ(name, "inactive")) { xmlpath = g_strdup_printf("%s/%s%s.xml", abs_srcdir, @@ -116,14 +115,11 @@ fakeStoragePoolLookupByName(virConnectPtr conn, if (!virFileExists(xmlpath)) { virReportError(VIR_ERR_NO_STORAGE_POOL, "File '%s' not found", xmlpath); - goto cleanup; + return NULL; } } - ret = virGetStoragePool(conn, name, fakeUUID, NULL, NULL); - - cleanup: - return ret; + return virGetStoragePool(conn, name, fakeUUID, NULL, NULL); } @@ -132,7 +128,6 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool, const char *name) { g_auto(GStrv) volinfo = NULL; - virStorageVolPtr ret = NULL; if (STREQ(pool->name, "inactive")) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -155,15 +150,11 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool, if (!volinfo[1]) goto fallback; - ret = virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0], + return virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0], NULL, NULL); - cleanup: - return ret; - fallback: - ret = virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL); - goto cleanup; + return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL); } static int @@ -210,11 +201,9 @@ fakeStoragePoolGetXMLDesc(virStoragePoolPtr pool, virReportError(VIR_ERR_INTERNAL_ERROR, "failed to load XML file '%s'", xmlpath); - goto cleanup; + return NULL; } - cleanup: - return xmlbuf; } -- 2.31.1

On 9/4/21 4:44 PM, Ján Tomko wrote: 6 files changed, 51 insertions(+), 105 deletions(-)
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 10d02bd1b4..bef6dfd152 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -471,51 +471,39 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTest *test, virJSONValue *args; const char *cmdname; const char *mode; - int ret = -1;
data = qemuMonitorTestItemGetPrivateData(item);
if (!(val = virJSONValueFromString(cmdstr))) return -1;
- if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) { - ret = qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr); - goto cleanup; - } + if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) + return qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr);
if (STRNEQ(cmdname, "guest-shutdown")) { - ret = qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown", + return qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown", cmdname);
I would have moved that up to the previous line so I could get rid of the braces - you lost out on 2 points in the "reducing line count" battle :-P
- goto cleanup; }
if (!(args = virJSONValueObjectGet(val, "arguments"))) { - ret = qemuMonitorTestAddErrorResponse(test, + return qemuMonitorTestAddErrorResponse(test, "Missing arguments section");
Same here.

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vmx2xmltest.c | 19 +++++++------------ tests/xml2vmxtest.c | 15 +++++---------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index b7f232eb77..0974168cb4 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -68,7 +68,6 @@ testCapsInit(void) static int testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) { - int ret = -1; g_autofree char *vmxData = NULL; g_autofree char *formatted = NULL; g_autoptr(virDomainDef) def = NULL; @@ -79,31 +78,27 @@ testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) def = virVMXParseConfig(&ctx, xmlopt, caps, vmxData); if (should_fail_parse) { if (!def) - ret = 0; + return 0; else VIR_TEST_DEBUG("passed instead of expected failure"); - goto cleanup; + return -1; } if (!def) - goto cleanup; + return -1; if (!virDomainDefCheckABIStability(def, def, xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", vmx); - goto cleanup; + return -1; } if (!(formatted = virDomainDefFormat(def, xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto cleanup; + return -1; if (virTestCompareToFile(formatted, xml) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - - return ret; + return 0; } struct testInfo { diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 8a03237b16..60185746a8 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -70,7 +70,6 @@ testCapsInit(void) static int testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) { - int result = -1; g_autofree char *formatted = NULL; g_autoptr(virDomainDef) def = NULL; @@ -78,25 +77,21 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) VIR_DOMAIN_DEF_PARSE_INACTIVE); if (def == NULL) - goto failure; + return -1; if (!virDomainDefCheckABIStability(def, def, xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); - goto failure; + return -1; } formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version); if (formatted == NULL) - goto failure; + return -1; if (virTestCompareToFile(formatted, vmx) < 0) - goto failure; + return -1; - result = 0; - - failure: - - return result; + return 0; } struct testInfo { -- 2.31.1

On 9/4/21 4:44 PM, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vmx2xmltest.c | 19 +++++++------------ tests/xml2vmxtest.c | 15 +++++---------- 2 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index b7f232eb77..0974168cb4 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -68,7 +68,6 @@ testCapsInit(void) static int testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) { - int ret = -1; g_autofree char *vmxData = NULL; g_autofree char *formatted = NULL; g_autoptr(virDomainDef) def = NULL; @@ -79,31 +78,27 @@ testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse) def = virVMXParseConfig(&ctx, xmlopt, caps, vmxData); if (should_fail_parse) { if (!def) - ret = 0; + return 0; else VIR_TEST_DEBUG("passed instead of expected failure"); - goto cleanup; + return -1;
The else there is unnecessary (pre-existing condition).

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/xlconfigtest.c | 48 ++++++++++++++++++-------------------------- tests/xmconfigtest.c | 37 +++++++++++++--------------------- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 6717377982..d6505f9e12 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -68,47 +68,43 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) g_autoptr(virConf) conf = NULL; g_autoptr(virConnect) conn = NULL; int wrote = 4096; - int ret = -1; g_autoptr(virDomainDef) def = NULL; g_autofree char *replacedXML = NULL; gotxlcfgData = g_new0(char, wrote); conn = virGetConnect(); - if (!conn) goto fail; + if (!conn) + return -1; if (replaceVars) { if (!(replacedXML = testReplaceVarsXML(xml))) - goto fail; + return -1; if (!(def = virDomainDefParseString(replacedXML, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) - goto fail; + return -1; } else { if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL, VIR_DOMAIN_XML_INACTIVE))) - goto fail; + return -1; } if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); - goto fail; + return -1; } if (!(conf = xenFormatXL(def, conn))) - goto fail; + return -1; if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0) - goto fail; + return -1; gotxlcfgData[wrote] = '\0'; if (virTestCompareToFile(gotxlcfgData, xlcfg) < 0) - goto fail; + return -1; - ret = 0; - - fail: - - return ret; + return 0; } /* @@ -121,44 +117,40 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars) g_autofree char *xlcfgData = NULL; g_autofree char *gotxml = NULL; g_autoptr(virConf) conf = NULL; - int ret = -1; g_autoptr(virConnect) conn = NULL; g_autoptr(virDomainDef) def = NULL; g_autofree char *replacedXML = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); conn = virGetConnect(); - if (!conn) goto fail; + if (!conn) + return -1; if (virTestLoadFile(xlcfg, &xlcfgData) < 0) - goto fail; + return -1; if (!(conf = virConfReadString(xlcfgData, 0))) - goto fail; + return -1; if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt))) - goto fail; + return -1; if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) - goto fail; + return -1; if (replaceVars) { if (!(replacedXML = testReplaceVarsXML(xml))) - goto fail; + return -1; if (virTestCompareToString(gotxml, replacedXML) < 0) - goto fail; + return -1; } else { if (virTestCompareToFile(gotxml, xml) < 0) - goto fail; + return -1; } - ret = 0; - - fail: - - return ret; + return 0; } diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index bd23e5fd5d..c99d1f2bd9 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -41,7 +41,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) { g_autofree char *gotxmcfgData = NULL; g_autoptr(virConf) conf = NULL; - int ret = -1; g_autoptr(virConnect) conn = NULL; int wrote = 4096; g_autoptr(virDomainDef) def = NULL; @@ -49,32 +48,29 @@ testCompareParseXML(const char *xmcfg, const char *xml) gotxmcfgData = g_new0(char, wrote); conn = virGetConnect(); - if (!conn) goto fail; + if (!conn) + return -1; if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; + return -1; if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); - goto fail; + return -1; } if (!(conf = xenFormatXM(conn, def))) - goto fail; + return -1; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0) - goto fail; + return -1; gotxmcfgData[wrote] = '\0'; if (virTestCompareToFile(gotxmcfgData, xmcfg) < 0) - goto fail; + return -1; - ret = 0; - - fail: - - return ret; + return 0; } static int @@ -83,30 +79,25 @@ testCompareFormatXML(const char *xmcfg, const char *xml) g_autofree char *xmcfgData = NULL; g_autofree char *gotxml = NULL; g_autoptr(virConf) conf = NULL; - int ret = -1; g_autoptr(virDomainDef) def = NULL; g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); if (virTestLoadFile(xmcfg, &xmcfgData) < 0) - goto fail; + return -1; if (!(conf = virConfReadString(xmcfgData, 0))) - goto fail; + return -1; if (!(def = xenParseXM(conf, cfg->caps, driver->xmlopt))) - goto fail; + return -1; if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto fail; + return -1; if (virTestCompareToFile(gotxml, xml) < 0) - goto fail; + return -1; - ret = 0; - - fail: - - return ret; + return 0; } -- 2.31.1

On 9/4/21 4:44 PM, Ján Tomko wrote:
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index bd23e5fd5d..c99d1f2bd9 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -41,7 +41,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) { g_autofree char *gotxmcfgData = NULL; g_autoptr(virConf) conf = NULL; - int ret = -1; g_autoptr(virConnect) conn = NULL; int wrote = 4096; g_autoptr(virDomainDef) def = NULL; @@ -49,32 +48,29 @@ testCompareParseXML(const char *xmcfg, const char *xml) gotxmcfgData = g_new0(char, wrote);
conn = virGetConnect(); - if (!conn) goto fail;
What is (was) this? perl?? :-P
+ if (!conn) + return -1;

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/nwfilterebiptablestest.c | 63 ++++++++++++---------------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c index 7b32e90d19..9307a10229 100644 --- a/tests/nwfilterebiptablestest.c +++ b/tests/nwfilterebiptablestest.c @@ -102,24 +102,21 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -F libvirt-O-vnet0\n" "ebtables --concurrent -t nat -X libvirt-O-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.allTeardown("vnet0") < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -167,24 +164,21 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.tearOldRules("vnet0") < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -210,24 +204,21 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -F libvirt-P-vnet0\n" "ebtables --concurrent -t nat -X libvirt-P-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.removeBasicRules("vnet0") < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -238,24 +229,21 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED) const char *expected = VIR_NWFILTER_NEW_RULES_TEARDOWN; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.tearNewRules("vnet0") < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -303,25 +291,22 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -A PREROUTING -i vnet0 -j libvirt-J-vnet0\n" "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } }; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.applyBasicRules("vnet0", &mac) < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -377,7 +362,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; virMacAddr mac = { .addr = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } }; const char *servers[] = { "192.168.122.1", "10.0.0.1", "10.0.0.2" }; virNWFilterVarValue val = { @@ -394,18 +378,16 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED) virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.applyDHCPOnlyRules("vnet0", &mac, &val, false) < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -455,24 +437,21 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED) "ebtables --concurrent -t nat -E libvirt-J-vnet0 libvirt-I-vnet0\n" "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n"; g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, &buf, false, true, NULL, NULL); if (ebiptables_driver.applyDropAllRules("vnet0") < 0) - goto cleanup; + return -1; actual = virBufferContentAndReset(&buf); if (STRNEQ_NULLABLE(actual, expected)) { virTestDifference(stderr, expected, actual); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vshtabletest.c | 71 +++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index 569d7a852f..716b11dbc0 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -81,42 +81,38 @@ testVshTableHeader(const void *opaque G_GNUC_UNUSED) static int testVshTableRowAppend(const void *opaque G_GNUC_UNUSED) { - int ret = 0; - g_autoptr(vshTable) table = vshTableNew("Id", "Name", NULL); if (!table) - goto cleanup; + return -1; if (vshTableRowAppend(table, NULL) >= 0) { fprintf(stderr, "Appending NULL shouldn't work\n"); - ret = -1; + return -1; } if (vshTableRowAppend(table, "2", NULL) >= 0) { fprintf(stderr, "Appending less items than in header\n"); - ret = -1; + return -1; } if (vshTableRowAppend(table, "2", "rhel7.5", "running", NULL) >= 0) { fprintf(stderr, "Appending more items than in header\n"); - ret = -1; + return -1; } if (vshTableRowAppend(table, "2", "rhel7.5", NULL) < 0) { fprintf(stderr, "Appending same number of items as in header" " should not return NULL\n"); - ret = -1; + return -1; } - cleanup: - return ret; + return 0; } static int testUnicode(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autofree char *act = NULL; const char *exp = @@ -128,7 +124,7 @@ testUnicode(const void *opaque G_GNUC_UNUSED) table = vshTableNew("Id", "名稱", "государство", NULL); if (!table) - goto cleanup; + return -1; vshTableRowAppend(table, "1", "fedora28", "running", NULL); vshTableRowAppend(table, "2", "つへソrhel7.5つへソ", "running", @@ -136,17 +132,15 @@ testUnicode(const void *opaque G_GNUC_UNUSED) act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } /* Point of this test is to see how table behaves with right to left writing */ static int testUnicodeArabic(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autofree char *act = NULL; const char *exp = @@ -167,7 +161,7 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) table = vshTableNew("ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ", "ﺓ ﺎﻠﺼﻋ", "ﺍﻸﺜﻧﺎﻧ", NULL); if (!table) - goto cleanup; + return -1; vshTableRowAppend(table, "1", "ﻉﺪﻴﻟ ﺎﻠﺜﻘﻴﻟ ﻕﺎﻣ ﻊﻧ, ٣٠ ﻎﻴﻨﻳﺍ ﻮﺘﻧﺎﻤﺗ ﺎﻠﺛﺎﻠﺛ، ﺄﺳﺭ, ﺩﻮﻟ", @@ -177,17 +171,15 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) NULL); act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } /* Testing zero-width characters by inserting few zero-width spaces */ static int testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autoptr(vshTable) table = NULL; const char *exp = " I\u200Bd Name \u200BStatus\n" @@ -207,22 +199,20 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) table = vshTableNew("I\u200Bd", "Name", "\u200BStatus", NULL); if (!table) - goto cleanup; + return -1; vshTableRowAppend(table, "1\u200B", "fedora28", "run\u200Bning", NULL); vshTableRowAppend(table, "2", "rhel7.5", "running", NULL); act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } static int testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autoptr(vshTable) table = NULL; const char *exp = " Id Náme Ⓢtatus\n" @@ -233,23 +223,21 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED) table = vshTableNew("Id", "Náme", "Ⓢtatus", NULL); if (!table) - goto cleanup; + return -1; vshTableRowAppend(table, "1", "fědora28", "running", NULL); vshTableRowAppend(table, "2", "rhel", "running", NULL); act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } /* Testing zero-width characters by inserting few zero-width spaces */ static int testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autoptr(vshTable) table = NULL; const char *exp = " I\\x09d Name Status\n" @@ -260,22 +248,20 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED) table = vshTableNew("I\td", "Name", "Status", NULL); if (!table) - goto cleanup; + return -1; vshTableRowAppend(table, "1", "f\aedora28", "running", NULL); vshTableRowAppend(table, "2", "rhel7.5", "running", NULL); act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } static int testNTables(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autoptr(vshTable) table1 = NULL; g_autoptr(vshTable) table2 = NULL; g_autoptr(vshTable) table3 = NULL; @@ -301,7 +287,7 @@ testNTables(const void *opaque G_GNUC_UNUSED) table1 = vshTableNew("Id", "Name", "Status", NULL); if (!table1) - goto cleanup; + return -1; vshTableRowAppend(table1, "1", "fedora28", "running", NULL); vshTableRowAppend(table1, "2", "rhel7.5", "running", NULL); vshTableRowAppend(table1, "3", "gazpacho", "", NULL); @@ -309,12 +295,12 @@ testNTables(const void *opaque G_GNUC_UNUSED) table2 = vshTableNew("Id", "Name", "Status", NULL); if (!table2) - goto cleanup; + return -1; act2 = vshTablePrintToString(table2, true); table3 = vshTableNew("Id", NULL); if (!table3) - goto cleanup; + return -1; vshTableRowAppend(table3, "1", NULL); vshTableRowAppend(table3, "2", NULL); vshTableRowAppend(table3, "3", NULL); @@ -322,14 +308,13 @@ testNTables(const void *opaque G_GNUC_UNUSED) act3 = vshTablePrintToString(table3, true); if (virTestCompareToString(exp1, act1) < 0) - ret = -1; + return -1; if (virTestCompareToString(exp2, act2) < 0) - ret = -1; + return -1; if (virTestCompareToString(exp3, act3) < 0) - ret = -1; + return -1; - cleanup: - return ret; + return 0; } static int -- 2.31.1

On 9/4/21 4:44 PM, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vshtabletest.c | 71 +++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 43 deletions(-)
diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index 569d7a852f..716b11dbc0 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -81,42 +81,38 @@ testVshTableHeader(const void *opaque G_GNUC_UNUSED) static int testVshTableRowAppend(const void *opaque G_GNUC_UNUSED) { - int ret = 0; - g_autoptr(vshTable) table = vshTableNew("Id", "Name", NULL); if (!table) - goto cleanup; + return -1;
if (vshTableRowAppend(table, NULL) >= 0) { fprintf(stderr, "Appending NULL shouldn't work\n"); - ret = -1; + return -1; }
if (vshTableRowAppend(table, "2", NULL) >= 0) { fprintf(stderr, "Appending less items than in header\n"); - ret = -1; + return -1; }
if (vshTableRowAppend(table, "2", "rhel7.5", "running", NULL) >= 0) { fprintf(stderr, "Appending more items than in header\n"); - ret = -1; + return -1; }
if (vshTableRowAppend(table, "2", "rhel7.5", NULL) < 0) { fprintf(stderr, "Appending same number of items as in header" " should not return NULL\n"); - ret = -1; + return -1; }
- cleanup: - return ret; + return 0; }
static int testUnicode(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autofree char *act = NULL;
const char *exp = @@ -128,7 +124,7 @@ testUnicode(const void *opaque G_GNUC_UNUSED)
table = vshTableNew("Id", "名稱", "государство", NULL); if (!table) - goto cleanup; + return -1;
This failure used to return 0, now returns -1. The new behavior is correct, and fortunately it's mostly just a theoretical condition unless the test system is actually out of memory, in which case it would have aborted by now anyway (or possibly vshTableNew() could fail in some strange way due to the Unicode characters, I haven't looked, and don't feel like looking :-)). (Really I'm just pointing it (and the things in the other mails) out so you'll know that I really am looking at the diffs, and not just blindly rubberstamping it :-) :-) Have I included enough text smiley emojis yet?
vshTableRowAppend(table, "1", "fedora28", "running", NULL); vshTableRowAppend(table, "2", "つへソrhel7.5つへソ", "running", @@ -136,17 +132,15 @@ testUnicode(const void *opaque G_GNUC_UNUSED)
act = vshTablePrintToString(table, true); if (virTestCompareToString(exp, act) < 0) - ret = -1; + return -1;
- cleanup: - return ret; + return 0; }
/* Point of this test is to see how table behaves with right to left writing */ static int testUnicodeArabic(const void *opaque G_GNUC_UNUSED) { - int ret = 0; g_autofree char *act = NULL;
const char *exp = @@ -167,7 +161,7 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED)
table = vshTableNew("ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ", "ﺓ ﺎﻠﺼﻋ", "ﺍﻸﺜﻧﺎﻧ", NULL); if (!table) - goto cleanup; + return -1;
Same thing here. And there's probably others further down, but I'll shut up now.

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/vircapstest.c | 14 +++------ tests/virconftest.c | 38 ++++++++++-------------- tests/vircryptotest.c | 23 +++++---------- tests/virfiletest.c | 49 ++++++++++++------------------- tests/virhostcputest.c | 12 +++----- tests/viriscsitest.c | 15 +++------- tests/virkmodtest.c | 30 ++++++------------- tests/virmacmaptest.c | 31 +++++++------------ tests/virnetworkportxml2xmltest.c | 15 ++++------ tests/virnumamock.c | 7 ++--- tests/virpcitest.c | 22 ++++++-------- tests/virresctrltest.c | 16 ++++------ tests/virscsitest.c | 15 +++------- tests/virstringtest.c | 32 +++++--------------- tests/virsystemdtest.c | 20 ++++--------- 15 files changed, 115 insertions(+), 224 deletions(-) diff --git a/tests/vircapstest.c b/tests/vircapstest.c index ebabbbb9a0..d1b5033844 100644 --- a/tests/vircapstest.c +++ b/tests/vircapstest.c @@ -153,10 +153,8 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED) int ret = 0; g_autoptr(virCaps) caps = NULL; - if (!(caps = testQemuCapsInit())) { - ret = -1; - goto out; - } + if (!(caps = testQemuCapsInit())) + return -1; /* Checking each parameter individually */ CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL, @@ -195,7 +193,6 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED) "/usr/bin/qemu-system-aarch64", "pc"); CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc"); - out: return ret; } #endif /* WITH_QEMU */ @@ -207,10 +204,8 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED) int ret = 0; g_autoptr(virCaps) caps = NULL; - if (!(caps = testLXCCapsInit())) { - ret = -1; - goto out; - } + if (!(caps = testLXCCapsInit())) + return -1; CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL, VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64, @@ -219,7 +214,6 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED) VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64, VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL); - out: return ret; } #endif /* WITH_LXC */ diff --git a/tests/virconftest.c b/tests/virconftest.c index a7189579d3..5d1ad8a612 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -67,7 +67,6 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED) "uint = 12345"; g_autoptr(virConf) conf = virConfReadString(srcdata, 0); - int ret = -1; virConfValue *val; unsigned long long llvalue; g_autofree char *str = NULL; @@ -77,49 +76,47 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED) return -1; if (!(val = virConfGetValue(conf, "ullong"))) - goto cleanup; + return -1; if (val->type != VIR_CONF_STRING) - goto cleanup; + return -1; if (virStrToLong_ull(val->str, NULL, 10, &llvalue) < 0) - goto cleanup; + return -1; if (llvalue != 123456789) { fprintf(stderr, "Expected '123' got '%llu'\n", llvalue); - goto cleanup; + return -1; } if (virConfGetValueType(conf, "string") != VIR_CONF_STRING) { fprintf(stderr, "expected a string for 'string'\n"); - goto cleanup; + return -1; } if (virConfGetValueString(conf, "string", &str) < 0) - goto cleanup; + return -1; if (STRNEQ_NULLABLE(str, "foo")) { fprintf(stderr, "Expected 'foo' got '%s'\n", str); - goto cleanup; + return -1; } if (virConfGetValueType(conf, "uint") != VIR_CONF_ULLONG) { fprintf(stderr, "expected an unsigned long for 'uint'\n"); - goto cleanup; + return -1; } if (virConfGetValueInt(conf, "uint", &uintvalue) < 0) - goto cleanup; + return -1; if (uintvalue != 12345) { fprintf(stderr, "Expected 12345 got %ud\n", uintvalue); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -338,7 +335,6 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED) "int = 6963472309248\n" \ "string = \"foo\"\n"; - int ret = -1; g_autoptr(virConf) conf = virConfReadString(srcdata, 0); g_autofree char *str = NULL; @@ -348,25 +344,23 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED) if (virConfGetValueType(conf, "string") != VIR_CONF_STRING) { fprintf(stderr, "expected a string for 'string'\n"); - goto cleanup; + return -1; } if (virConfGetValueString(conf, "string", &str) < 0) - goto cleanup; + return -1; if (STRNEQ_NULLABLE(str, "foo")) { fprintf(stderr, "Expected 'foo' got '%s'\n", str); - goto cleanup; + return -1; } if (virConfGetValueString(conf, "int", &str) != -1) { fprintf(stderr, "Expected error for 'int'\n"); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c index 2d503a439e..98af476156 100644 --- a/tests/vircryptotest.c +++ b/tests/vircryptotest.c @@ -38,22 +38,19 @@ testCryptoHash(const void *opaque) { const struct testCryptoHashData *data = opaque; g_autofree char *actual = NULL; - int ret = -1; if (virCryptoHashString(data->hash, data->input, &actual) < 0) { fprintf(stderr, "Failed to generate crypto hash\n"); - goto cleanup; + return -1; } if (STRNEQ_NULLABLE(data->output, actual)) { fprintf(stderr, "Expected hash '%s' but got '%s'\n", data->output, NULLSTR(actual)); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -75,7 +72,6 @@ testCryptoEncrypt(const void *opaque) size_t ivlen = 16; g_autofree uint8_t *ciphertext = NULL; size_t ciphertextlen = 0; - int ret = -1; if (!virCryptoHaveCipher(data->algorithm)) { fprintf(stderr, "cipher algorithm=%d unavailable\n", data->algorithm); @@ -88,29 +84,26 @@ testCryptoEncrypt(const void *opaque) if (virRandomBytes(enckey, enckeylen) < 0 || virRandomBytes(iv, ivlen) < 0) { fprintf(stderr, "Failed to generate random bytes\n"); - goto cleanup; + return -1; } if (virCryptoEncryptData(data->algorithm, enckey, enckeylen, iv, ivlen, data->input, data->inputlen, &ciphertext, &ciphertextlen) < 0) - goto cleanup; + return -1; if (data->ciphertextlen != ciphertextlen) { fprintf(stderr, "Expected ciphertextlen(%zu) doesn't match (%zu)\n", data->ciphertextlen, ciphertextlen); - goto cleanup; + return -1; } if (memcmp(data->ciphertext, ciphertext, ciphertextlen)) { fprintf(stderr, "Expected ciphertext doesn't match\n"); - goto cleanup; + return -1; } - ret = 0; - cleanup: - - return ret; + return 0; } diff --git a/tests/virfiletest.c b/tests/virfiletest.c index a6e722b4d2..4b69ea1b69 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -103,7 +103,6 @@ static int testFileSanitizePath(const void *opaque) { const struct testFileSanitizePathData *data = opaque; - int ret = -1; g_autofree char *actual = NULL; if (!(actual = virFileSanitizePath(data->path))) @@ -111,13 +110,10 @@ testFileSanitizePath(const void *opaque) if (STRNEQ(actual, data->expect)) { fprintf(stderr, "\nexpect: '%s'\nactual: '%s'\n", data->expect, actual); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -195,41 +191,38 @@ holesSupported(void) off_t offsets[] = {EXTENT, EXTENT, EXTENT, -1}; off_t tmp; VIR_AUTOCLOSE fd = -1; - bool ret = false; if ((fd = makeSparseFile(offsets, true)) < 0) - goto cleanup; + return false; /* The way this works is: there are 4K of data followed by 4K hole followed * by 4K hole again. Check if the filesystem we are running the test suite * on supports holes. */ if ((tmp = lseek(fd, 0, SEEK_DATA)) == (off_t) -1) - goto cleanup; + return false; if (tmp != 0) - goto cleanup; + return false; if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1) - goto cleanup; + return false; if (tmp != EXTENT * 1024) - goto cleanup; + return false; if ((tmp = lseek(fd, tmp, SEEK_DATA)) == (off_t) -1) - goto cleanup; + return false; if (tmp != 2 * EXTENT * 1024) - goto cleanup; + return false; if ((tmp = lseek(fd, tmp, SEEK_HOLE)) == (off_t) -1) - goto cleanup; + return false; if (tmp != 3 * EXTENT * 1024) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } #else /* !WITH_DECL_SEEK_HOLE || !defined(__linux__)*/ @@ -261,11 +254,10 @@ testFileInData(const void *opaque) { const struct testFileInData *data = opaque; VIR_AUTOCLOSE fd = -1; - int ret = -1; size_t i; if ((fd = makeSparseFile(data->offsets, data->startData)) < 0) - goto cleanup; + return -1; for (i = 0; data->offsets[i] != (off_t) -1; i++) { bool shouldInData = data->startData; @@ -277,32 +269,29 @@ testFileInData(const void *opaque) shouldInData = !shouldInData; if (virFileInData(fd, &realInData, &realLen) < 0) - goto cleanup; + return -1; if (realInData != shouldInData) { fprintf(stderr, "Unexpected data/hole. Expected %s got %s\n", shouldInData ? "data" : "hole", realInData ? "data" : "hole"); - goto cleanup; + return -1; } shouldLen = data->offsets[i] * 1024; if (realLen != shouldLen) { fprintf(stderr, "Unexpected section length. Expected %lld got %lld\n", shouldLen, realLen); - goto cleanup; + return -1; } if (lseek(fd, shouldLen, SEEK_CUR) < 0) { fprintf(stderr, "Unable to seek\n"); - goto cleanup; + return -1; } } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -319,9 +308,9 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data = opaque; + int ret = -1; g_autofree char *mtabFile = NULL; bool actual; - int ret = -1; mtabFile = g_strdup_printf(abs_srcdir "/virfiledata/%s", data->mtabFile); diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index c80cd1581c..746e65727f 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -30,7 +30,6 @@ linuxTestCompareFiles(const char *cpuinfofile, virArch arch, const char *outputfile) { - int ret = -1; g_autofree char *actualData = NULL; virNodeInfo nodeinfo; g_autoptr(FILE) cpuinfo = NULL; @@ -39,7 +38,7 @@ linuxTestCompareFiles(const char *cpuinfofile, if (!cpuinfo) { fprintf(stderr, "unable to open: %s : %s\n", cpuinfofile, g_strerror(errno)); - goto fail; + return -1; } memset(&nodeinfo, 0, sizeof(nodeinfo)); @@ -51,7 +50,7 @@ linuxTestCompareFiles(const char *cpuinfofile, if (virGetLastErrorCode()) VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage()); } - goto fail; + return -1; } actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " @@ -61,12 +60,9 @@ linuxTestCompareFiles(const char *cpuinfofile, nodeinfo.cores, nodeinfo.threads); if (virTestCompareToFile(actualData, outputfile) < 0) - goto fail; + return -1; - ret = 0; - - fail: - return ret; + return 0; } diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 7ea761fda6..f2539e47b0 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -211,7 +211,6 @@ testISCSIGetSession(const void *data) const struct testSessionInfo *info = data; struct testIscsiadmCbData cbData = { 0 }; g_autofree char *actual_session = NULL; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); cbData.output_version = info->output_version; @@ -225,13 +224,10 @@ testISCSIGetSession(const void *data) "Expected session: '%s' got: '%s'", NULLSTR(info->expected_session), NULLSTR(actual_session)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } struct testScanTargetsInfo { @@ -295,17 +291,14 @@ testISCSIConnectionLogin(const void *data) { const struct testConnectionInfoLogin *info = data; struct testIscsiadmCbData cbData = { 0 }; - int ret = -1; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); virCommandSetDryRun(dryRunToken, NULL, false, false, testIscsiadmCb, &cbData); if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->target) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 2f07757c88..d2df3bdb04 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -34,30 +34,25 @@ static int checkOutput(virBuffer *buf, const char *exp_cmd) { - int ret = -1; g_autofree char *actual_cmd = NULL; if (!(actual_cmd = virBufferContentAndReset(buf))) { fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); - goto cleanup; + return -1; } if (STRNEQ(exp_cmd, actual_cmd)) { virTestDifference(stderr, exp_cmd, actual_cmd); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int testKModLoad(const void *args G_GNUC_UNUSED) { - int ret = -1; g_autofree char *errbuf = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -67,23 +62,19 @@ testKModLoad(const void *args G_GNUC_UNUSED) errbuf = virKModLoad(MODNAME); if (errbuf) { fprintf(stderr, "Failed to load, error: %s\n", errbuf); - goto cleanup; + return -1; } if (checkOutput(&buf, MODPROBE " -b " MODNAME "\n") < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } static int testKModUnload(const void *args G_GNUC_UNUSED) { - int ret = -1; g_autofree char *errbuf = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); @@ -93,16 +84,13 @@ testKModUnload(const void *args G_GNUC_UNUSED) errbuf = virKModUnload(MODNAME); if (errbuf) { fprintf(stderr, "Failed to unload, error: %s\n", errbuf); - goto cleanup; + return -1; } if (checkOutput(&buf, RMMOD " " MODNAME "\n") < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 01a3588ed9..9a28c1bed0 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -40,12 +40,11 @@ testMACLookup(const void *opaque) GSList *next; size_t i, j; g_autofree char *file = NULL; - int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (!(mgr = virMacMapNew(file))) - goto cleanup; + return -1; macs = virMacMapLookup(mgr, data->domain); @@ -59,7 +58,7 @@ testMACLookup(const void *opaque) fprintf(stderr, "Unexpected %s in the returned list of MACs\n", (const char *) next->data); - goto cleanup; + return -1; } } @@ -72,13 +71,11 @@ testMACLookup(const void *opaque) if (!next) { fprintf(stderr, "Expected %s in the returned list of MACs\n", data->macs[i]); - goto cleanup; + return -1; } } - ret = 0; - cleanup: - return ret; + return 0; } @@ -90,18 +87,17 @@ testMACRemove(const void *opaque) GSList *macs; size_t i; g_autofree char *file = NULL; - int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (!(mgr = virMacMapNew(file))) - goto cleanup; + return -1; for (i = 0; data->macs && data->macs[i]; i++) { if (virMacMapRemove(mgr, data->domain, data->macs[i]) < 0) { fprintf(stderr, "Error when removing %s from the list of MACs\n", data->macs[i]); - goto cleanup; + return -1; } } @@ -109,12 +105,10 @@ testMACRemove(const void *opaque) fprintf(stderr, "Not removed all MACs for domain %s: %s\n", data->domain, (const char *) macs->data); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -124,19 +118,16 @@ testMACFlush(const void *opaque) const struct testData *data = opaque; g_autofree char *file = NULL; g_autofree char *str = NULL; - int ret = -1; file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); if (virMacMapDumpStr(data->mgr, &str) < 0) - goto cleanup; + return -1; if (virTestCompareToFile(str, file) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xmltest.c index 8d29db724f..093d855633 100644 --- a/tests/virnetworkportxml2xmltest.c +++ b/tests/virnetworkportxml2xmltest.c @@ -37,21 +37,18 @@ static int testCompareXMLToXMLFiles(const char *expected) { g_autofree char *actual = NULL; - int ret = -1; g_autoptr(virNetworkPortDef) dev = NULL; if (!(dev = virNetworkPortDefParseFile(expected))) - goto cleanup; + return -1; if (!(actual = virNetworkPortDefFormat(dev))) - goto cleanup; + return -1; if (virTestCompareToFile(actual, expected) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } struct testInfo { @@ -62,14 +59,12 @@ static int testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info = data; - int ret = -1; g_autofree char *xml = NULL; xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir, info->name); - ret = testCompareXMLToXMLFiles(xml); - return ret; + return testCompareXMLToXMLFiles(xml); } static int diff --git a/tests/virnumamock.c b/tests/virnumamock.c index 6e0293a49e..19c26d1e37 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -162,7 +162,6 @@ virNumaGetPages(int node, int virNumaGetNodeCPUs(int node, virBitmap **cpus) { - int ret = -1; g_autofree char *cpulist = NULL; if (virFileReadValueString(&cpulist, @@ -177,9 +176,7 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus) *cpus = virBitmapParseUnlimited(cpulist); } if (!*cpus) - goto cleanup; + return -1; - ret = virBitmapCountBits(*cpus); - cleanup: - return ret; + return virBitmapCountBits(*cpus); } diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 1ff0330b22..08e137756f 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -34,22 +34,19 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected) { g_autofree char *path = NULL; g_autofree char *driver = NULL; - int ret = -1; if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0) - goto cleanup; + return -1; if (STRNEQ_NULLABLE(driver, expected)) { virReportError(VIR_ERR_INTERNAL_ERROR, "PCI device %s driver mismatch: %s, expecting %s", virPCIDeviceGetName(dev), NULLSTR(driver), NULLSTR(expected)); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -166,7 +163,6 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) static int testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) { - int ret = -1; virPCIDevice *dev[] = {NULL, NULL, NULL}; size_t i, nDev = G_N_ELEMENTS(dev); g_autoptr(virPCIDeviceList) activeDevs = NULL; @@ -175,17 +171,17 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) if (!(activeDevs = virPCIDeviceListNew()) || !(inactiveDevs = virPCIDeviceListNew())) - goto cleanup; + return -1; for (i = 0; i < nDev; i++) { virPCIDeviceAddress devAddr = {.domain = 0, .bus = 0, .slot = i + 1, .function = 0}; if (!(dev[i] = virPCIDeviceNew(&devAddr))) - goto cleanup; + return -1; if (virPCIDeviceListAdd(inactiveDevs, dev[i]) < 0) { virPCIDeviceFree(dev[i]); - goto cleanup; + return -1; } CHECK_LIST_COUNT(activeDevs, 0); @@ -199,15 +195,15 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) for (i = 0; i < nDev; i++) { if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0) - goto cleanup; + return -1; CHECK_LIST_COUNT(activeDevs, 0); CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1); } - ret = 0; + return 0; cleanup: - return ret; + return -1; } struct testPCIDevData { diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index 0beb9a4df4..c5733a7972 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -20,7 +20,6 @@ test_virResctrlGetUnused(const void *opaque) struct virResctrlData *data = (struct virResctrlData *) opaque; g_autofree char *system_dir = NULL; g_autofree char *resctrl_dir = NULL; - int ret = -1; g_autoptr(virResctrlAlloc) alloc = NULL; g_autofree char *schemata_str = NULL; g_autofree char *schemata_file = NULL; @@ -41,7 +40,7 @@ test_virResctrlGetUnused(const void *opaque) caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false); if (!caps || virCapabilitiesInitCaches(caps) < 0) { fprintf(stderr, "Could not initialize capabilities"); - goto cleanup; + return -1; } alloc = virResctrlAllocGetUnused(caps->host.resctrl); @@ -50,22 +49,19 @@ test_virResctrlGetUnused(const void *opaque) if (!alloc) { if (data->fail) - ret = 0; - goto cleanup; + return 0; + return -1; } else if (data->fail) { VIR_TEST_DEBUG("Error expected but there wasn't any."); - ret = -1; - goto cleanup; + return -1; } schemata_str = virResctrlAllocFormat(alloc); if (virTestCompareToFile(schemata_str, schemata_file) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/virscsitest.c b/tests/virscsitest.c index d67cd23896..c96699e157 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -37,18 +37,15 @@ static int test1(const void *data G_GNUC_UNUSED) { g_autofree char *name = NULL; - int ret = -1; if (!(name = virSCSIDeviceGetDevName(virscsi_prefix, "scsi_host1", 0, 0, 0))) return -1; if (STRNEQ(name, "sdh")) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } /* @@ -161,7 +158,6 @@ test2(const void *data G_GNUC_UNUSED) static int create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) { - int ret = -1; g_autofree char *src_path = NULL; g_autofree char *dst_path = NULL; @@ -171,13 +167,10 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) if (symlink(src_path, dst_path) < 0) { VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int diff --git a/tests/virstringtest.c b/tests/virstringtest.c index bbdd17da84..277deca934 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -223,7 +223,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED) { const struct stringReplaceData *data = opaque; g_autofree char *result = NULL; - int ret = -1; result = virStringReplace(data->haystack, data->oldneedle, @@ -232,13 +231,10 @@ testStringReplace(const void *opaque G_GNUC_UNUSED) if (STRNEQ_NULLABLE(data->result, result)) { fprintf(stderr, "Expected '%s' but got '%s'\n", data->result, NULLSTR(result)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -400,7 +396,6 @@ struct testStripData { static int testStripIPv6Brackets(const void *args) { const struct testStripData *data = args; - int ret = -1; g_autofree char *res = NULL; res = g_strdup(data->string); @@ -410,19 +405,15 @@ static int testStripIPv6Brackets(const void *args) if (STRNEQ_NULLABLE(res, data->result)) { fprintf(stderr, "Returned '%s', expected '%s'\n", NULLSTR(res), NULLSTR(data->result)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int testStripControlChars(const void *args) { const struct testStripData *data = args; - int ret = -1; g_autofree char *res = NULL; res = g_strdup(data->string); @@ -432,13 +423,10 @@ static int testStripControlChars(const void *args) if (STRNEQ_NULLABLE(res, data->result)) { fprintf(stderr, "Returned '%s', expected '%s'\n", NULLSTR(res), NULLSTR(data->result)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } struct testFilterData { @@ -450,7 +438,6 @@ struct testFilterData { static int testFilterChars(const void *args) { const struct testFilterData *data = args; - int ret = -1; g_autofree char *res = NULL; res = g_strdup(data->string); @@ -460,13 +447,10 @@ static int testFilterChars(const void *args) if (STRNEQ_NULLABLE(res, data->result)) { fprintf(stderr, "Returned '%s', expected '%s'\n", NULLSTR(res), NULLSTR(data->result)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 9cf6bfec43..9a063dd1fc 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -369,45 +369,37 @@ static int testScopeName(const void *opaque) { const struct testNameData *data = opaque; - int ret = -1; g_autofree char *actual = NULL; if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy))) - goto cleanup; + return -1; if (STRNEQ(actual, data->expected)) { fprintf(stderr, "Expected '%s' but got '%s'\n", data->expected, actual); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int testMachineName(const void *opaque) { const struct testNameData *data = opaque; - int ret = -1; g_autofree char *actual = NULL; if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root, data->id, data->name, true))) - goto cleanup; + return -1; if (STRNEQ(actual, data->expected)) { fprintf(stderr, "Expected '%s' but got '%s'\n", data->expected, actual); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } typedef int (*virSystemdCanHelper)(bool * result); -- 2.31.1

On 9/4/21 4:44 PM, Ján Tomko wrote:
@@ -319,9 +308,9 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data = opaque; + int ret = -1; g_autofree char *mtabFile = NULL; bool actual; - int ret = -1;
unrelated (well, only peripherally related) code movement. [...]
@@ -199,15 +195,15 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED)
for (i = 0; i < nDev; i++) { if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0) - goto cleanup; + return -1;
CHECK_LIST_COUNT(activeDevs, 0); CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1); }
- ret = 0; + return 0; cleanup: - return ret; + return -1; }
Oops. You forgot one! cleanup is no longer referenced, but you didn't remove it (or the dead code "return -1;" following it)

On a Monday in 2021, Laine Stump wrote:
On 9/4/21 4:44 PM, Ján Tomko wrote:
@@ -319,9 +308,9 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data = opaque; + int ret = -1; g_autofree char *mtabFile = NULL; bool actual; - int ret = -1;
unrelated (well, only peripherally related) code movement.
[...]
@@ -199,15 +195,15 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) for (i = 0; i < nDev; i++) { if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0) - goto cleanup; + return -1; CHECK_LIST_COUNT(activeDevs, 0); CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1); } - ret = 0; + return 0; cleanup: - return ret; + return -1; }
Oops. You forgot one! cleanup is no longer referenced, but you didn't remove it (or the dead code "return -1;" following it)
'cleanup' is still referenced inside the 'CHECK_LIST_COUNT' macro, which is also used by testVirPCIDeviceReset and testVirPCIDeviceDetach. On second thought, mixing returns with cleanups does not seem like a good idea and I will drop this partial conversion before pushing. Jano

On 9/9/21 10:28 AM, Ján Tomko wrote:
On a Monday in 2021, Laine Stump wrote:
On 9/4/21 4:44 PM, Ján Tomko wrote:
@@ -319,9 +308,9 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data = opaque; + int ret = -1; g_autofree char *mtabFile = NULL; bool actual; - int ret = -1;
unrelated (well, only peripherally related) code movement.
[...]
@@ -199,15 +195,15 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED) for (i = 0; i < nDev; i++) { if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0) - goto cleanup; + return -1; CHECK_LIST_COUNT(activeDevs, 0); CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1); } - ret = 0; + return 0; cleanup: - return ret; + return -1; }
Oops. You forgot one! cleanup is no longer referenced, but you didn't remove it (or the dead code "return -1;" following it)
'cleanup' is still referenced inside the 'CHECK_LIST_COUNT' macro, which is also used by testVirPCIDeviceReset and testVirPCIDeviceDetach.
Ewww, ... er, I mean "Oh. Interesting." Well at least that explains why it still compiled, so I don't have to lose sleep over that any more :-)
On second thought, mixing returns with cleanups does not seem like a good idea and I will drop this partial conversion before pushing.
Jano

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/cputest.c | 42 ++++++++++++-------------------- tests/domaincapstest.c | 39 ++++++++++++----------------- tests/domainconftest.c | 12 +++------ tests/fchosttest.c | 40 +++++++++++------------------- tests/lxcconf2xmltest.c | 16 +++++------- tests/metadatatest.c | 28 +++++++-------------- tests/openvzutilstest.c | 11 +++------ tests/scsihosttest.c | 22 +++++++---------- tests/securityselinuxlabeltest.c | 12 +++------ tests/vmwarevertest.c | 14 ++++------- 10 files changed, 84 insertions(+), 152 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index 11305d56c5..0f0621292a 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -520,7 +520,6 @@ static int cpuTestCPUID(bool guest, const void *arg) { const struct data *data = arg; - int ret = -1; g_autoptr(virCPUData) hostData = NULL; g_autofree char *hostFile = NULL; g_autofree char *host = NULL; @@ -533,7 +532,7 @@ cpuTestCPUID(bool guest, const void *arg) if (virTestLoadFile(hostFile, &host) < 0 || !(hostData = virCPUDataParse(host))) - goto cleanup; + return -1; cpu = virCPUDefNew(); cpu->arch = hostData->arch; @@ -549,21 +548,16 @@ cpuTestCPUID(bool guest, const void *arg) int rc; rc = cpuTestGetCPUModels(data, &models); - if (rc != 0) { - ret = rc; - goto cleanup; - } + if (rc != 0) + return rc; } if (cpuDecode(cpu, hostData, models) < 0) - goto cleanup; + return -1; result = g_strdup_printf("cpuid-%s-%s", data->host, guest ? "guest" : "host"); - ret = cpuTestCompareXML(data->arch, cpu, result); - - cleanup: - return ret; + return cpuTestCompareXML(data->arch, cpu, result); } @@ -729,27 +723,26 @@ cpuTestUpdateLive(const void *arg) g_autoptr(virCPUDef) expected = NULL; g_autoptr(virDomainCapsCPUModels) hvModels = NULL; g_autoptr(virDomainCapsCPUModels) models = NULL; - int ret = -1; cpuFile = g_strdup_printf("cpuid-%s-guest", data->host); if (!(cpu = cpuTestLoadXML(data->arch, cpuFile))) - goto cleanup; + return -1; enabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-enabled.xml", abs_srcdir, virArchToString(data->arch), data->host); if (virTestLoadFile(enabledFile, &enabled) < 0 || !(enabledData = virCPUDataParse(enabled))) - goto cleanup; + return -1; disabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-disabled.xml", abs_srcdir, virArchToString(data->arch), data->host); if (virTestLoadFile(disabledFile, &disabled) < 0 || !(disabledData = virCPUDataParse(disabled))) - goto cleanup; + return -1; expectedFile = g_strdup_printf("cpuid-%s-json", data->host); if (!(expected = cpuTestLoadXML(data->arch, expectedFile))) - goto cleanup; + return -1; /* In case the host CPU signature does not exactly match any CPU model in * src/cpu_map, the CPU model we detect from CPUID may differ from the one @@ -764,13 +757,11 @@ cpuTestUpdateLive(const void *arg) int rc; if (!(models = virDomainCapsCPUModelsNew(0))) - goto cleanup; + return -1; rc = cpuTestGetCPUModels(data, &hvModels); - if (rc != 0) { - ret = rc; - goto cleanup; - } + if (rc != 0) + return rc; hvModel = virDomainCapsCPUModelsGet(hvModels, expected->model); @@ -781,7 +772,7 @@ cpuTestUpdateLive(const void *arg) if (virDomainCapsCPUModelsAdd(models, expected->model, usable, blockers, false) < 0) - goto cleanup; + return -1; cpu->fallback = VIR_CPU_FALLBACK_ALLOW; ignore_value(virCPUTranslate(data->arch, cpu, models)); @@ -789,12 +780,9 @@ cpuTestUpdateLive(const void *arg) } if (virCPUUpdateLive(data->arch, cpu, enabledData, disabledData) < 0) - goto cleanup; + return -1; - ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected); - - cleanup: - return ret; + return cpuTestUpdateLiveCompare(data->arch, cpu, expected); } diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 463ff83890..9ea5bed5c2 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -73,18 +73,17 @@ fillQemuCaps(virDomainCaps *domCaps, const char *machine, virQEMUDriverConfig *cfg) { - int ret = -1; g_autofree char *path = NULL; g_autoptr(virQEMUCaps) qemuCaps = NULL; virDomainCapsLoader *loader = &domCaps->os.loader; virDomainVirtType virtType; if (fakeHostCPU(domCaps->arch) < 0) - goto cleanup; + return -1; path = g_strdup_printf("%s/%s.%s.xml", TEST_QEMU_CAPS_PATH, name, arch); if (!(qemuCaps = qemuTestParseCapabilitiesArch(domCaps->arch, path))) - goto cleanup; + return -1; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) virtType = VIR_DOMAIN_VIRT_KVM; @@ -103,7 +102,7 @@ fillQemuCaps(virDomainCaps *domCaps, false, cfg->firmwares, cfg->nfirmwares) < 0) - goto cleanup; + return -1; /* The function above tries to query host's VFIO capabilities by calling * qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be @@ -123,11 +122,9 @@ fillQemuCaps(virDomainCaps *domCaps, "/usr/share/AAVMF/AAVMF32_CODE.fd", "/usr/share/OVMF/OVMF_CODE.fd", NULL) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } #endif /* WITH_QEMU */ @@ -167,19 +164,16 @@ static int fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps) { g_autofree virDomainCapsStringValues *firmwares = NULL; - int ret = -1; firmwares = g_new0(virDomainCapsStringValues, 1); if (fillStringValues(firmwares, "/foo/bar", "/foo/baz", NULL) < 0) - goto cleanup; + return -1; if (virBhyveDomainCapsFill(domCaps, *bhyve_caps, firmwares) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } #endif /* WITH_BHYVE */ @@ -208,14 +202,13 @@ test_virDomainCapsFormat(const void *opaque) g_autoptr(virDomainCaps) domCaps = NULL; g_autofree char *path = NULL; g_autofree char *domCapsXML = NULL; - int ret = -1; path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name); if (!(domCaps = virDomainCapsNew(data->emulator, data->machine, virArchFromString(data->arch), data->type))) - goto cleanup; + return -1; switch (data->capsType) { case CAPS_NONE: @@ -225,33 +218,31 @@ test_virDomainCapsFormat(const void *opaque) #if WITH_QEMU if (fillQemuCaps(domCaps, data->capsName, data->arch, data->machine, data->capsOpaque) < 0) - goto cleanup; + return -1; #endif break; case CAPS_LIBXL: #if WITH_LIBXL if (fillXenCaps(domCaps) < 0) - goto cleanup; + return -1; #endif break; case CAPS_BHYVE: #if WITH_BHYVE if (fillBhyveCaps(domCaps, data->capsOpaque) < 0) - goto cleanup; + return -1; #endif break; } if (!(domCapsXML = virDomainCapsFormat(domCaps))) - goto cleanup; + return -1; if (virTestCompareToFile(domCapsXML, path) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/domainconftest.c b/tests/domainconftest.c index aaf58bcf93..71fd1f7b73 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -40,7 +40,6 @@ struct testGetFilesystemData { static int testGetFilesystem(const void *opaque) { - int ret = -1; g_autoptr(virDomainDef) def = NULL; g_autofree char *filename = NULL; const struct testGetFilesystemData *data = opaque; @@ -50,7 +49,7 @@ static int testGetFilesystem(const void *opaque) data->filename); if (!(def = virDomainDefParseFile(filename, xmlopt, NULL, 0))) - goto cleanup; + return -1; fsdef = virDomainGetFilesystemForTarget(def, data->path); @@ -58,20 +57,17 @@ static int testGetFilesystem(const void *opaque) if (data->expectEntry) { fprintf(stderr, "Expected FS for path '%s' in '%s'\n", data->path, filename); - goto cleanup; + return -1; } } else { if (!data->expectEntry) { fprintf(stderr, "Unexpected FS for path '%s' in '%s'\n", data->path, filename); - goto cleanup; + return -1; } } - ret = 0; - - cleanup: - return ret; + return 0; } static int diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 707dd7e410..dc1503e9a7 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -123,7 +123,6 @@ test3(const void *data G_GNUC_UNUSED) g_autofree char *fabric_wwn = NULL; g_autofree char *max_vports = NULL; g_autofree char *vports = NULL; - int ret = -1; if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, "node_name"))) @@ -131,31 +130,29 @@ test3(const void *data G_GNUC_UNUSED) if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, "port_name"))) - goto cleanup; + return -1; if (!(fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, "fabric_name"))) - goto cleanup; + return -1; if (!(max_vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, "max_npiv_vports"))) - goto cleanup; + return -1; if (!(vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, "npiv_vports_inuse"))) - goto cleanup; + return -1; if (STRNEQ(expect_wwnn, wwnn) || STRNEQ(expect_wwpn, wwpn) || STRNEQ(expect_fabric_wwn, fabric_wwn) || STRNEQ(expect_max_vports, max_vports) || STRNEQ(expect_vports, vports)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } /* Test virVHBAGetHostByWWN */ @@ -164,7 +161,6 @@ test4(const void *data G_GNUC_UNUSED) { const char *expect_hostname = "host5"; g_autofree char *hostname = NULL; - int ret = -1; if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX, "2001001b32a9da4e", @@ -172,11 +168,9 @@ test4(const void *data G_GNUC_UNUSED) return -1; if (STRNEQ(hostname, expect_hostname)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } /* Test virVHBAFindVportHost @@ -188,17 +182,14 @@ test5(const void *data G_GNUC_UNUSED) { const char *expect_hostname = "host5"; g_autofree char *hostname = NULL; - int ret = -1; if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX))) return -1; if (STRNEQ(hostname, expect_hostname)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } /* Test virVHBAGetConfig fabric name optional */ @@ -210,7 +201,6 @@ test6(const void *data G_GNUC_UNUSED) g_autofree char *wwnn = NULL; g_autofree char *wwpn = NULL; g_autofree char *fabric_wwn = NULL; - int ret = -1; if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, "node_name"))) @@ -218,20 +208,18 @@ test6(const void *data G_GNUC_UNUSED) if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, "port_name"))) - goto cleanup; + return -1; if ((fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, "fabric_name"))) - goto cleanup; + return -1; if (STRNEQ(expect_wwnn, wwnn) || STRNEQ(expect_wwpn, wwpn)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index be70671d68..09f6465567 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -25,33 +25,29 @@ testCompareXMLToConfigFiles(const char *xmlfile, const char *configfile, bool expectError) { - int ret = -1; g_autofree char *config = NULL; g_autofree char *actualxml = NULL; g_autoptr(virDomainDef) vmdef = NULL; if (virTestLoadFile(configfile, &config) < 0) - goto fail; + return -1; vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt); if ((vmdef && expectError) || (!vmdef && !expectError)) - goto fail; + return -1; if (vmdef) { if (testSanitizeDef(vmdef) < 0) - goto fail; + return -1; if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, 0))) - goto fail; + return -1; if (virTestCompareToFile(actualxml, xmlfile) < 0) - goto fail; + return -1; } - ret = 0; - - fail: - return ret; + return 0; } struct testInfo { diff --git a/tests/metadatatest.c b/tests/metadatatest.c index 5112912161..b56428fde5 100644 --- a/tests/metadatatest.c +++ b/tests/metadatatest.c @@ -91,7 +91,6 @@ verifyMetadata(virDomainPtr dom, const char *expectAPI, const char *uri) { - bool ret = false; g_autofree char *metadataXML = NULL; g_autofree char *metadataAPI = NULL; @@ -102,13 +101,13 @@ verifyMetadata(virDomainPtr dom, virReportError(VIR_ERR_INTERNAL_ERROR, "expected no metadata in API, but got:\n[%s]", metadataAPI); - goto cleanup; + return false; } } else { if (!(metadataAPI = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, 0))) - goto cleanup; + return false; metadataXMLConvertApostrophe(metadataAPI); @@ -117,7 +116,7 @@ verifyMetadata(virDomainPtr dom, "XML metadata in API doesn't match expected metadata: " "expected:\n[%s]\ngot:\n[%s]", expectAPI, metadataAPI); - goto cleanup; + return false; } } @@ -127,11 +126,11 @@ verifyMetadata(virDomainPtr dom, virReportError(VIR_ERR_INTERNAL_ERROR, "expected no metadata in XML, but got:\n[%s]", metadataXML); - goto cleanup; + return false; } } else { if (!(metadataXML = getMetadataFromXML(dom))) - goto cleanup; + return false; metadataXMLConvertApostrophe(metadataXML); @@ -140,15 +139,11 @@ verifyMetadata(virDomainPtr dom, "XML in dump doesn't match expected metadata: " "expected:\n[%s]\ngot:\n[%s]", expectXML, metadataXML); - goto cleanup; + return false; } } - ret = true; - - cleanup: - - return ret; + return true; } @@ -213,7 +208,6 @@ testTextMetadata(const void *data) { const struct metadataTest *test = data; g_autofree char *actual = NULL; - int ret = -1; if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) { if (test->fail) @@ -228,14 +222,10 @@ testTextMetadata(const void *data) "expected metadata doesn't match actual: " "expected:'%s'\ngot: '%s'", NULLSTR(test->data), NULLSTR(actual)); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - - return ret; + return 0; } #define TEST_TEXT_METADATA(INDEX, TYPE, DATA, EXPECT, FAIL) \ diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 3ebf38f104..7e6c0b60bb 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -36,7 +36,6 @@ static struct testConfigParam configParams[] = { static int testReadConfigParam(const void *data G_GNUC_UNUSED) { - int result = -1; size_t i; g_autofree char *conf = NULL; g_autofree char *value = NULL; @@ -46,7 +45,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) for (i = 0; i < G_N_ELEMENTS(configParams); ++i) { if (openvzReadConfigParam(conf, configParams[i].param, &value) != configParams[i].ret) { - goto cleanup; + return -1; } if (configParams[i].ret != 1) @@ -54,15 +53,11 @@ testReadConfigParam(const void *data G_GNUC_UNUSED) if (STRNEQ(configParams[i].value, value)) { virTestDifference(stderr, configParams[i].value, value); - goto cleanup; + return -1; } } - result = 0; - - cleanup: - - return result; + return 0; } static int diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c index aeb91da691..cb66a479e3 100644 --- a/tests/scsihosttest.c +++ b/tests/scsihosttest.c @@ -70,7 +70,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, g_autofree char *unique_id_path = NULL; g_autofree char *link_path = NULL; char *spot; - int ret = -1; VIR_AUTOCLOSE fd = -1; unique_id_path = g_strdup_printf("%s/devices/pci0000:00/%s/unique_id", @@ -83,13 +82,13 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, */ if (!(spot = strstr(unique_id_path, "unique_id"))) { fprintf(stderr, "Did not find unique_id in path\n"); - goto cleanup; + return -1; } spot--; *spot = '\0'; if (g_mkdir_with_parents(unique_id_path, 0755) < 0) { fprintf(stderr, "Unable to make path to '%s'\n", unique_id_path); - goto cleanup; + return -1; } *spot = '/'; @@ -98,45 +97,42 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath, */ if (!(spot = strstr(link_path, hostname))) { fprintf(stderr, "Did not find hostname in path\n"); - goto cleanup; + return -1; } spot--; *spot = '\0'; if (g_mkdir_with_parents(link_path, 0755) < 0) { fprintf(stderr, "Unable to make path to '%s'\n", link_path); - goto cleanup; + return -1; } *spot = '/'; if ((fd = open(unique_id_path, O_CREAT|O_WRONLY, 0444)) < 0) { fprintf(stderr, "Unable to create '%s'\n", unique_id_path); - goto cleanup; + return -1; } if (safewrite(fd, unique_id, 1) != 1) { fprintf(stderr, "Unable to write '%s'\n", unique_id); - goto cleanup; + return -1; } VIR_DEBUG("Created unique_id '%s'", unique_id_path); /* The link is to the path not the file - so remove the file */ if (!(spot = strstr(unique_id_path, "unique_id"))) { fprintf(stderr, "Did not find unique_id in path\n"); - goto cleanup; + return -1; } spot--; *spot = '\0'; if (symlink(unique_id_path, link_path) < 0) { fprintf(stderr, "Unable to create symlink '%s' to '%s'\n", link_path, unique_id_path); - goto cleanup; + return -1; } VIR_DEBUG("Created symlink '%s'", link_path); - ret = 0; - - cleanup: - return ret; + return 0; } static int diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 2e5941d7ef..87b2fc738a 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -99,7 +99,6 @@ testSELinuxLoadFileList(const char *testname, testSELinuxFile **files, size_t *nfiles) { - int ret = -1; g_autofree char *path = NULL; g_autoptr(FILE) fp = NULL; g_autofree char *line = NULL; @@ -111,7 +110,7 @@ testSELinuxLoadFileList(const char *testname, testname); if (!(fp = fopen(path, "r"))) - goto cleanup; + return -1; line = g_new0(char, 1024); @@ -119,7 +118,7 @@ testSELinuxLoadFileList(const char *testname, char *file = NULL, *context = NULL, *tmp; if (!fgets(line, 1024, fp)) { if (!feof(fp)) - goto cleanup; + return -1; break; } @@ -128,7 +127,7 @@ testSELinuxLoadFileList(const char *testname, virReportError(VIR_ERR_INTERNAL_ERROR, "unexpected format for line '%s'", line); - goto cleanup; + return -1; } *tmp = '\0'; tmp++; @@ -148,10 +147,7 @@ testSELinuxLoadFileList(const char *testname, (*files)[(*nfiles)-1].context = context; } - ret = 0; - - cleanup: - return ret; + return 0; } diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c index 7cb358795f..cdbd58fb4f 100644 --- a/tests/vmwarevertest.c +++ b/tests/vmwarevertest.c @@ -37,7 +37,6 @@ static int testVerStrParse(const void *data) { const struct testInfo *info = data; - int ret = -1; g_autofree char *path = NULL; g_autofree char *databuf = NULL; unsigned long version; @@ -46,24 +45,21 @@ testVerStrParse(const void *data) path = g_strdup_printf("%s/vmwareverdata/%s.txt", abs_srcdir, info->name); if (virTestLoadFile(path, &databuf) < 0) - goto cleanup; + return -1; if ((vmware_type = vmwareDriverTypeFromString(info->vmware_type)) < 0) - goto cleanup; + return -1; if (vmwareParseVersionStr(vmware_type, databuf, &version) < 0) - goto cleanup; + return -1; if (version != info->version) { fprintf(stderr, "%s: parsed versions do not match: got %lu, " "expected %lu\n", info->name, version, info->version); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int -- 2.31.1

On 9/4/21 4:43 PM, Ján Tomko wrote:
Ján Tomko (24): tests: virnetdaemontest: split variable declarations conf: add cleanup func for virNetworkXMLOption conf: add cleanup func for virMacMap tests: use g_autoptr instead of virObjectUnref tests: qemu: use g_autofree tests: network: use g_autofree tests: libxl: use g_autofree tests: nwfilter: use g_autofree tests: vmx: use g_autofree tests: vir: use g_autofree tests: use g_autofree tests: use g_autoptr instead of virJSONValueFree tests: use g_auto for virCPUDataFree tests: use g_auto instead of VIR_FORCE_FCLOSE tests: use VIR_AUTOCLOSE tests: use g_auto instead of vshTableFree tests: use g_auto instead of virDomainFree tests: qemu: remove pointless labels tests: vmx: remove pointless labels tests: libxl: remove pointless labels tests: nwfilter: remove pointless labels tests: vshtabletest: remove pointless labels tests: vir: remove pointless labels
You missed removal of one cleanup: label in 23/24 (I had assumed it would give a compile warning in that case, but the CI pipeline passed it, so...)
tests: remove pointless labels
71 files changed, 628 insertions(+), 1226 deletions(-)
Beer-worthy statistics! I had a couple random comments beyond the one up above, but that's the only one that needs any action. Once you've fixed that, series: Reviewed-by: Laine Stump <laine@redhat.com>
participants (2)
-
Ján Tomko
-
Laine Stump