[libvirt PATCH 0/4] tests: switch to g_new0 (glib chronicles)

With the exception of viralloctest. Ján Tomko (4): tests: virNumaGetPages: use g_new0 instead of VIR_ALLOC_N tests: cpuTestLoadMultiXML: use g_new0 instead of VIR_ALLOC_N tests: use g_new0 instead of VIR_ALLOC_N tests: use g_new0 instead of VIR_ALLOC tests/commandtest.c | 7 +++---- tests/cputest.c | 4 +++- tests/domaincapstest.c | 10 ++++------ tests/fdstreamtest.c | 10 ++++------ tests/nodedevmdevctltest.c | 16 +++++----------- tests/nwfilterxml2firewalltest.c | 3 +-- tests/qemublocktest.c | 9 +++------ tests/qemuhotplugtest.c | 3 +-- tests/qemumonitorjsontest.c | 12 ++++-------- tests/qemumonitortestutils.c | 22 ++++++---------------- tests/qemusecuritymock.c | 3 +-- tests/qemuxml2argvtest.c | 3 +-- tests/securityselinuxhelper.c | 3 +-- tests/securityselinuxlabeltest.c | 3 +-- tests/securityselinuxtest.c | 6 ++---- tests/testutils.c | 8 ++------ tests/testutilsqemu.c | 6 ++---- tests/vircgrouptest.c | 3 +-- tests/vircryptotest.c | 5 ++--- tests/virhostcputest.c | 3 +-- tests/virhostdevtest.c | 3 +-- tests/virnetdaemontest.c | 3 +-- tests/virnetmessagetest.c | 15 ++++++--------- tests/virnetserverclienttest.c | 3 +-- tests/virnetsockettest.c | 6 +----- tests/virnettlshelpers.c | 3 +-- tests/virnumamock.c | 16 +++------------- tests/virstringtest.c | 8 +++----- tests/xlconfigtest.c | 3 +-- tests/xmconfigtest.c | 3 +-- 30 files changed, 67 insertions(+), 135 deletions(-) -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virnumamock.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/virnumamock.c b/tests/virnumamock.c index e6282c7f33..40e18e646e 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -133,23 +133,13 @@ virNumaGetPages(int node, size_t i = 0; if (pages_size) - *pages_size = NULL; + *pages_size = g_new0(unsigned int, npages_def); if (pages_avail) - *pages_avail = NULL; + *pages_avail = g_new0(unsigned long long, npages_def); if (pages_free) - *pages_free = NULL; - - *npages = 0; - - if ((pages_size && VIR_ALLOC_N(*pages_size, npages_def) < 0) || - (pages_avail && VIR_ALLOC_N(*pages_avail, npages_def) < 0) || - (pages_free && VIR_ALLOC_N(*pages_free, npages_def) < 0)) { - VIR_FREE(*pages_size); - VIR_FREE(*pages_avail); - return -1; - } + *pages_free = g_new0(unsigned long long, npages_def); *npages = npages_def; if (pages_size) -- 2.26.2

On Wed, Sep 23, 2020 at 01:04:15 +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virnumamock.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/cputest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cputest.c b/tests/cputest.c index 83d63bf495..383da94938 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -111,11 +111,13 @@ cpuTestLoadMultiXML(virArch arch, goto cleanup; n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes); - if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) { + if (n <= 0) { fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml); goto cleanup; } + cpus = g_new0(virCPUDefPtr, n); + for (i = 0; i < n; i++) { ctxt->node = nodes[i]; if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_HOST, &cpus[i]) < 0) -- 2.26.2

On Wed, Sep 23, 2020 at 01:04:16 +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/cputest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/commandtest.c | 7 +++---- tests/domaincapstest.c | 3 +-- tests/fdstreamtest.c | 10 ++++------ tests/qemuxml2argvtest.c | 3 +-- tests/securityselinuxlabeltest.c | 3 +-- tests/securityselinuxtest.c | 3 +-- tests/testutils.c | 8 ++------ tests/testutilsqemu.c | 6 ++---- tests/vircgrouptest.c | 3 +-- tests/vircryptotest.c | 5 ++--- tests/virhostcputest.c | 3 +-- tests/virnetmessagetest.c | 6 ++---- tests/virnetsockettest.c | 6 +----- tests/virnettlshelpers.c | 3 +-- tests/virstringtest.c | 3 +-- tests/xlconfigtest.c | 3 +-- tests/xmconfigtest.c | 3 +-- 17 files changed, 26 insertions(+), 52 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index cbbcda4e5f..df86725f0e 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1057,10 +1057,9 @@ static int test27(const void *unused G_GNUC_UNUSED) "%s%s%s" \ "END STDERR\n" - if (VIR_ALLOC_N(buffer0, buflen) < 0 || - VIR_ALLOC_N(buffer1, buflen) < 0 || - VIR_ALLOC_N(buffer2, buflen) < 0) - goto cleanup; + buffer0 = g_new0(char, buflen); + buffer1 = g_new0(char, buflen); + buffer2 = g_new0(char, buflen); memset(buffer0, 'H', buflen - 2); buffer0[buflen - 2] = '\n'; diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index d2ed820cf9..b3d36f55fc 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -147,8 +147,7 @@ fillXenCaps(virDomainCapsPtr domCaps) virFirmwarePtr *firmwares; int ret = -1; - if (VIR_ALLOC_N(firmwares, 2) < 0) - return ret; + firmwares = g_new0(virFirmwarePtr, 2); if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0) goto cleanup; diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 83973137e7..7a2fe27477 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -54,9 +54,8 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking) if (!(conn = virConnectOpen("test:///default"))) goto cleanup; - if (VIR_ALLOC_N(pattern, PATTERN_LEN) < 0 || - VIR_ALLOC_N(buf, PATTERN_LEN) < 0) - goto cleanup; + pattern = g_new0(char, PATTERN_LEN); + buf = g_new0(char, PATTERN_LEN); for (i = 0; i < PATTERN_LEN; i++) pattern[i] = i; @@ -185,9 +184,8 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) if (!(conn = virConnectOpen("test:///default"))) goto cleanup; - if (VIR_ALLOC_N(pattern, PATTERN_LEN) < 0 || - VIR_ALLOC_N(buf, PATTERN_LEN) < 0) - goto cleanup; + pattern = g_new0(char, PATTERN_LEN); + buf = g_new0(char, PATTERN_LEN); for (i = 0; i < PATTERN_LEN; i++) pattern[i] = i; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e93948e3fc..463e4c003d 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -753,8 +753,7 @@ mymain(void) driver.config->nbdTLSx509certdir = g_strdup("/etc/pki/libvirt-nbd/dummy,path"); VIR_FREE(driver.config->hugetlbfs); - if (VIR_ALLOC_N(driver.config->hugetlbfs, 2) < 0) - return EXIT_FAILURE; + driver.config->hugetlbfs = g_new0(virHugeTLBFS, 2); driver.config->nhugetlbfs = 2; driver.config->hugetlbfs[0].mnt_dir = g_strdup("/dev/hugepages2M"); driver.config->hugetlbfs[1].mnt_dir = g_strdup("/dev/hugepages1G"); diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 2989a668b7..168acc2bdf 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -114,8 +114,7 @@ testSELinuxLoadFileList(const char *testname, if (!(fp = fopen(path, "r"))) goto cleanup; - if (VIR_ALLOC_N(line, 1024) < 0) - goto cleanup; + line = g_new0(char, 1024); while (!feof(fp)) { char *file = NULL, *context = NULL, *tmp; diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index ae4b08b9d8..fd746d1ca1 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -71,8 +71,7 @@ testBuildDomainDef(bool dynamic, goto error; def->virtType = VIR_DOMAIN_VIRT_KVM; - if (VIR_ALLOC_N(def->seclabels, 1) < 0) - goto error; + def->seclabels = g_new0(char, 1); if (VIR_ALLOC(secdef) < 0) goto error; diff --git a/tests/testutils.c b/tests/testutils.c index 3f53f635fc..b747f65eea 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -211,10 +211,7 @@ virTestLoadFile(const char *file, char **buf) tmplen = buflen = st.st_size + 1; - if (VIR_ALLOC_N(*buf, buflen) < 0) { - VIR_FORCE_FCLOSE(fp); - return -1; - } + *buf = g_new0(char, buflen); tmp = *buf; (*buf)[0] = '\0'; @@ -977,8 +974,7 @@ virTestCapsBuildNUMATopology(int seq) id = 0; for (cell_id = 0; cell_id < MAX_CELLS; cell_id++) { - if (VIR_ALLOC_N(cell_cpus, MAX_CPUS_IN_CELL) < 0) - goto error; + cell_cpus = g_new0(virCapsHostNUMACellCPU, MAX_CPUS_IN_CELL); for (core_id = 0; core_id < MAX_CPUS_IN_CELL; core_id++) { cell_cpus[core_id].id = id + core_id; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 51ac59bade..eb37bbfdad 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -204,8 +204,7 @@ virCapsPtr testQemuCapsInit(void) /* Add dummy 'none' security_driver. This is equal to setting * security_driver = "none" in qemu.conf. */ - if (VIR_ALLOC_N(caps->host.secModels, 1) < 0) - goto cleanup; + caps->host.secModels = g_new0(virCapsHostSecModel, 1); caps->host.nsecModels = 1; caps->host.secModels[0].model = g_strdup("none"); @@ -459,8 +458,7 @@ testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps, virGICCapability *gicCapabilities = NULL; size_t ngicCapabilities = 0; - if (VIR_ALLOC_N(gicCapabilities, 2) < 0) - return -1; + gicCapabilities = g_new0(virGICCapability, 2); # define IMPL_BOTH \ VIR_GIC_IMPLEMENTATION_KERNEL|VIR_GIC_IMPLEMENTATION_EMULATED diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 44e72cbfa9..e5be556104 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -708,8 +708,7 @@ static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED) 635751356ULL, 0, 0, 0, 0, 0, 0, 0, }; - if (VIR_ALLOC_N(params, EXPECTED_NCPUS) < 0) - goto cleanup; + params = g_new0(virTypedParameter, EXPECTED_NCPUS); if ((rv = virCgroupNewPartition("/virtualmachines", true, (1 << VIR_CGROUP_CONTROLLER_CPU) | diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c index 42ef0b8900..90140077cf 100644 --- a/tests/vircryptotest.c +++ b/tests/vircryptotest.c @@ -83,9 +83,8 @@ testCryptoEncrypt(const void *opaque) return EXIT_AM_SKIP; } - if (VIR_ALLOC_N(enckey, enckeylen) < 0 || - VIR_ALLOC_N(iv, ivlen) < 0) - goto cleanup; + enckey = g_new0(uint8_t, enckeylen); + iv = g_new0(uint8_t, ivlen); if (virRandomBytes(enckey, enckeylen) < 0 || virRandomBytes(iv, ivlen) < 0) { diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 7b83c7ae5d..786a363e48 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -124,8 +124,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, if (virHostCPUGetStatsLinux(NULL, 0, NULL, &nparams) < 0) goto fail; - if (VIR_ALLOC_N(params, nparams) < 0) - goto fail; + params = g_new0(virNodeCPUStats, nparams); if (virHostCPUGetStatsLinux(cpustat, VIR_NODE_CPU_STATS_ALL_CPUS, params, &nparams) < 0) diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index a207f2d85f..89fadc346a 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -102,8 +102,7 @@ static int testMessageHeaderDecode(const void *args G_GNUC_UNUSED) return -1; msg->bufferLength = 4; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) - goto cleanup; + msg->buffer = g_new0(char, msg->bufferLength); memcpy(msg->buffer, input_buf, msg->bufferLength); msg->header.prog = 0x11223344; @@ -333,8 +332,7 @@ static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED) return -1; msg->bufferLength = 4; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) - goto cleanup; + msg->buffer = g_new0(char, msg->bufferLength); memcpy(msg->buffer, input_buffer, msg->bufferLength); if (virNetMessageDecodeLength(msg) < 0) { diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index d6b461cbc8..5216b98424 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -206,11 +206,7 @@ testSocketAccept(const void *opaque) if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &usock) < 0) goto cleanup; - if (VIR_ALLOC_N(lsock, 1) < 0) { - virObjectUnref(usock); - goto cleanup; - } - + lsock = g_new0(virNetSocketPtr, 1); lsock[0] = usock; nlsock = 1; diff --git a/tests/virnettlshelpers.c b/tests/virnettlshelpers.c index e0a4771894..ce38571b0a 100644 --- a/tests/virnettlshelpers.c +++ b/tests/virnettlshelpers.c @@ -117,8 +117,7 @@ static void testTLSDerEncode(ASN1_TYPE src, size = 0; asn1_der_coding(src, src_name, NULL, &size, NULL); - if (VIR_ALLOC_N(data, size) < 0) - abort(); + data = g_new0(char, size); asn1_der_coding(src, src_name, data, &size, NULL); diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 704686ac10..e48e4057fd 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -556,8 +556,7 @@ testVirStringListFreeCount(const void *opaque G_GNUC_UNUSED) { char **list; - if (VIR_ALLOC_N(list, 4) < 0) - return -1; + list = g_new0(char *, 4); list[0] = g_strdup("test1"); list[2] = g_strdup("test2"); diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index 3ad66ccfa1..ab1a834f1b 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -73,8 +73,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) virDomainDefPtr def = NULL; char *replacedXML = NULL; - if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0) - goto fail; + gotxlcfgData = g_new0(char, wrote); conn = virGetConnect(); if (!conn) goto fail; diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 43949fe3b5..8d6b2378fd 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -46,8 +46,7 @@ testCompareParseXML(const char *xmcfg, const char *xml) int wrote = 4096; virDomainDefPtr def = NULL; - if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) - goto fail; + gotxmcfgData = g_new0(char, wrote); conn = virGetConnect(); if (!conn) goto fail; -- 2.26.2

On Wed, Sep 23, 2020 at 01:04:17 +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> ---
[...]
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index ae4b08b9d8..fd746d1ca1 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -71,8 +71,7 @@ testBuildDomainDef(bool dynamic, goto error;
def->virtType = VIR_DOMAIN_VIRT_KVM; - if (VIR_ALLOC_N(def->seclabels, 1) < 0) - goto error; + def->seclabels = g_new0(char, 1);
'def' is virDomainDefPtr thus 'def->seclabels' is not char but 'virSecurityLabelDefPtr *' The compiler didn't moan because it's a double pointer, but it certainly doens't have enough size nor the correct type.
if (VIR_ALLOC(secdef) < 0) goto error;

On a Wednesday in 2020, Peter Krempa wrote:
On Wed, Sep 23, 2020 at 01:04:17 +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> ---
[...]
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index ae4b08b9d8..fd746d1ca1 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -71,8 +71,7 @@ testBuildDomainDef(bool dynamic, goto error;
def->virtType = VIR_DOMAIN_VIRT_KVM; - if (VIR_ALLOC_N(def->seclabels, 1) < 0) - goto error; + def->seclabels = g_new0(char, 1);
'def' is virDomainDefPtr thus 'def->seclabels' is not char but 'virSecurityLabelDefPtr *'
:neutral_face: :palm_tree:
The compiler didn't moan because it's a double pointer, but it certainly doens't have enough size nor the correct type.
Actually, the compiler did not even open this file. v2 coming up Jano
if (VIR_ALLOC(secdef) < 0) goto error;

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/domaincapstest.c | 7 +++---- tests/nodedevmdevctltest.c | 16 +++++----------- tests/nwfilterxml2firewalltest.c | 3 +-- tests/qemublocktest.c | 9 +++------ tests/qemuhotplugtest.c | 3 +-- tests/qemumonitorjsontest.c | 12 ++++-------- tests/qemumonitortestutils.c | 22 ++++++---------------- tests/qemusecuritymock.c | 3 +-- tests/securityselinuxhelper.c | 3 +-- tests/securityselinuxtest.c | 3 +-- tests/virhostdevtest.c | 3 +-- tests/virnetdaemontest.c | 3 +-- tests/virnetmessagetest.c | 9 ++++----- tests/virnetserverclienttest.c | 3 +-- tests/virstringtest.c | 5 ++--- 15 files changed, 35 insertions(+), 69 deletions(-) diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index b3d36f55fc..9b0a0c5758 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -148,9 +148,9 @@ fillXenCaps(virDomainCapsPtr domCaps) int ret = -1; firmwares = g_new0(virFirmwarePtr, 2); + firmwares[0] = g_new0(virFirmware, 1); + firmwares[1] = g_new0(virFirmware, 1); - if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0) - goto cleanup; firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader"); firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin"); @@ -174,8 +174,7 @@ fillBhyveCaps(virDomainCapsPtr domCaps, unsigned int *bhyve_caps) virDomainCapsStringValuesPtr firmwares = NULL; int ret = -1; - if (VIR_ALLOC(firmwares) < 0) - return -1; + firmwares = g_new0(virDomainCapsStringValues, 1); if (fillStringValues(firmwares, "/foo/bar", "/foo/baz", NULL) < 0) goto cleanup; diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 57c1ad4f46..dab4b487b9 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -162,11 +162,8 @@ fakeRootDevice(void) { virNodeDeviceDefPtr def = NULL; - if (VIR_ALLOC(def) != 0 || VIR_ALLOC(def->caps) != 0) { - virNodeDeviceDefFree(def); - return NULL; - } - + def = g_new0(virNodeDeviceDef, 1); + def->caps = g_new0(virNodeDevCapsDef, 1); def->name = g_strdup("computer"); return def; @@ -182,10 +179,8 @@ fakeParentDevice(void) virNodeDeviceDefPtr def = NULL; virNodeDevCapPCIDevPtr pci_dev; - if (VIR_ALLOC(def) != 0 || VIR_ALLOC(def->caps) != 0) { - virNodeDeviceDefFree(def); - return NULL; - } + def = g_new0(virNodeDeviceDef, 1); + def->caps = g_new0(virNodeDevCapsDef, 1); def->name = g_strdup("pci_0000_00_02_0"); def->parent = g_strdup("computer"); @@ -233,8 +228,7 @@ static int nodedevTestDriverInit(void) { int ret = -1; - if (VIR_ALLOC(driver) < 0) - return -1; + driver = g_new0(virNodeDeviceDriverState, 1); driver->lockFD = -1; if (virMutexInit(&driver->lock) < 0 || diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index dff2b62028..755732487a 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -209,8 +209,7 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, virNWFilterRuleInstPtr ruleinst; int ret = -1; - if (VIR_ALLOC(ruleinst) < 0) - goto cleanup; + ruleinst = g_new0(virNWFilterRuleInst, 1); ruleinst->chainSuffix = def->chainsuffix; ruleinst->chainPriority = def->chainPriority; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 0685b703a1..2489b883ff 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -234,8 +234,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); if (src->auth) { - if (VIR_ALLOC(srcpriv->secinfo) < 0) - return -1; + srcpriv->secinfo = g_new0(qemuDomainSecretInfo, 1); srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username); @@ -245,8 +244,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src) } if (src->encryption) { - if (VIR_ALLOC(srcpriv->encinfo) < 0) - return -1; + srcpriv->encinfo = g_new0(qemuDomainSecretInfo, 1); srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; srcpriv->encinfo->s.aes.alias = g_strdup_printf("%s-encalias", @@ -493,8 +491,7 @@ testQemuImageCreateLoadDiskXML(const char *name, return NULL; } - if (VIR_ALLOC(diskdef) < 0) - return NULL; + diskdef = g_new0(virDomainSnapshotDiskDef, 1); if (virDomainSnapshotDiskDefParseXML(node, ctxt, diskdef, VIR_DOMAIN_DEF_PARSE_STATUS, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index b023c49a69..2d12cacf28 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -413,8 +413,7 @@ testQemuHotplugCpuPrepare(const char *test, prefix = g_strdup_printf("%s/qemuhotplugtestcpus/%s", abs_srcdir, test); - if (VIR_ALLOC(data) < 0) - goto error; + data = g_new0(struct testQemuHotplugCpuData, 1); data->modern = modern; diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index bc25958e70..a0dcbba07b 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1653,8 +1653,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque) !(expectedBlockDevices = virHashCreate(32, virHashValueFree))) goto cleanup; - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(struct qemuDomainDiskInfo, 1); if (virHashAddEntry(expectedBlockDevices, "virtio-disk0", info) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1662,8 +1661,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque) goto cleanup; } - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(struct qemuDomainDiskInfo, 1); if (virHashAddEntry(expectedBlockDevices, "virtio-disk1", info) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1671,8 +1669,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque) goto cleanup; } - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(struct qemuDomainDiskInfo, 1); info->removable = true; info->tray = true; @@ -1683,8 +1680,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque) goto cleanup; } - if (VIR_ALLOC(info) < 0) - goto cleanup; + info = g_new0(struct qemuDomainDiskInfo, 1); info->removable = true; info->tray = true; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index d74df15966..2fc26577a7 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -461,8 +461,7 @@ qemuMonitorTestAddHandler(qemuMonitorTestPtr test, { qemuMonitorTestItemPtr item; - if (VIR_ALLOC(item) < 0) - goto error; + item = g_new0(qemuMonitorTestItem, 1); item->identifier = g_strdup(identifier); item->cb = cb; @@ -619,8 +618,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, { struct qemuMonitorTestHandlerData *data; - if (VIR_ALLOC(data) < 0) - return -1; + data = g_new0(struct qemuMonitorTestHandlerData, 1); data->command_name = g_strdup(command_name); data->response = g_strdup(response); @@ -694,8 +692,7 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test, { struct qemuMonitorTestHandlerData *data; - if (VIR_ALLOC(data) < 0) - return -1; + data = g_new0(struct qemuMonitorTestHandlerData, 1); data->response = g_strdup(response); data->cmderr = g_strdup(cmderr); @@ -856,8 +853,7 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test, va_start(args, response); - if (VIR_ALLOC(data) < 0) - goto error; + data = g_new0(struct qemuMonitorTestHandlerData, 1); data->command_name = g_strdup(cmdname); data->response = g_strdup(response); @@ -962,8 +958,7 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test, { struct qemuMonitorTestHandlerData *data; - if (VIR_ALLOC(data) < 0) - goto error; + data = g_new0(struct qemuMonitorTestHandlerData, 1); data->command_name = g_strdup(cmdname); data->response = g_strdup(response); @@ -984,10 +979,6 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test, cmdname, qemuMonitorTestProcessCommandWithArgStr, data, qemuMonitorTestHandlerDataFree); - - error: - qemuMonitorTestHandlerDataFree(data); - return -1; } @@ -1036,8 +1027,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt, char *path = NULL; char *tmpdir_template = NULL; - if (VIR_ALLOC(test) < 0) - goto error; + test = g_new0(qemuMonitorTest, 1); if (virMutexInit(&test->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 6da8a91a9e..2eb714cc2e 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -270,8 +270,7 @@ mock_chown(const char *path, abort(); } - if (VIR_ALLOC(val) < 0) - return -1; + val = g_new0(uint32_t, 1); *val = (gid << 16) + uid; diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index 14355d2166..b308ef5095 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -292,8 +292,7 @@ selabel_open(unsigned int backend, return real_selabel_open(backend, opts, nopts); /* struct selabel_handle is opaque; fake it */ - if (VIR_ALLOC(fake_handle) < 0) - return NULL; + fake_handle = g_new0(char, 1); return (struct selabel_handle *)fake_handle; } diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index fd746d1ca1..976c737cc2 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -73,8 +73,7 @@ testBuildDomainDef(bool dynamic, def->virtType = VIR_DOMAIN_VIRT_KVM; def->seclabels = g_new0(char, 1); - if (VIR_ALLOC(secdef) < 0) - goto error; + secdef = g_new0(virSecurityLabelDef, 1); secdef->model = g_strdup("selinux"); diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index b0bad683a8..385db0849a 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -149,8 +149,7 @@ myInit(void) goto cleanup; } - if (VIR_ALLOC(mgr) < 0) - goto cleanup; + mgr = g_new0(virHostdevManager, 1); if ((mgr->activePCIHostdevs = virPCIDeviceListNew()) == NULL) goto cleanup; if ((mgr->activeUSBHostdevs = virUSBDeviceListNew()) == NULL) diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 09d268627c..a20f351f93 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -38,8 +38,7 @@ testClientNew(virNetServerClientPtr client G_GNUC_UNUSED, { struct testClientPriv *priv; - if (VIR_ALLOC(priv) < 0) - return NULL; + priv = g_new0(struct testClientPriv, 1); priv->magic = 1729; diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index 89fadc346a..9f6115f226 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -226,11 +226,10 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED) err.domain = VIR_FROM_RPC; err.level = VIR_ERR_ERROR; - if (VIR_ALLOC(err.message) < 0 || - VIR_ALLOC(err.str1) < 0 || - VIR_ALLOC(err.str2) < 0 || - VIR_ALLOC(err.str3) < 0) - goto cleanup; + err.message = g_new0(char *, 1); + err.str1 = g_new0(char *, 1); + err.str2 = g_new0(char *, 1); + err.str3 = g_new0(char *, 1); *err.message = g_strdup("Hello World"); *err.str1 = g_strdup("One"); diff --git a/tests/virnetserverclienttest.c b/tests/virnetserverclienttest.c index 668fd02a1e..a4341c1641 100644 --- a/tests/virnetserverclienttest.c +++ b/tests/virnetserverclienttest.c @@ -32,8 +32,7 @@ testClientNew(virNetServerClientPtr client G_GNUC_UNUSED, { char *dummy; - if (VIR_ALLOC(dummy) < 0) - return NULL; + dummy = g_new0(char, 1); return dummy; } diff --git a/tests/virstringtest.c b/tests/virstringtest.c index e48e4057fd..7305190691 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -176,9 +176,8 @@ static int testAdd(const void *args) goto cleanup; } - if (!list && - VIR_ALLOC(list) < 0) - goto cleanup; + if (!list) + list = g_new0(char *, 1); if (!(got = virStringListJoin((const char **)list, data->delim))) { VIR_DEBUG("Got no result"); -- 2.26.2
participants (2)
-
Ján Tomko
-
Peter Krempa