]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use g_new0 instead of VIR_ALLOC
authorJán Tomko <jtomko@redhat.com>
Tue, 22 Sep 2020 22:42:45 +0000 (00:42 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 23 Sep 2020 12:54:38 +0000 (14:54 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
15 files changed:
tests/domaincapstest.c
tests/nodedevmdevctltest.c
tests/nwfilterxml2firewalltest.c
tests/qemublocktest.c
tests/qemuhotplugtest.c
tests/qemumonitorjsontest.c
tests/qemumonitortestutils.c
tests/qemusecuritymock.c
tests/securityselinuxhelper.c
tests/securityselinuxtest.c
tests/virhostdevtest.c
tests/virnetdaemontest.c
tests/virnetmessagetest.c
tests/virnetserverclienttest.c
tests/virstringtest.c

index d2ed820cf97a943378af525cb61880f61d11f66e..f817ed5452c15192adfccab90ec3eaaf786a8249 100644 (file)
@@ -150,8 +150,9 @@ fillXenCaps(virDomainCapsPtr domCaps)
     if (VIR_ALLOC_N(firmwares, 2) < 0)
         return ret;
 
-    if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0)
-        goto cleanup;
+    firmwares[0] = g_new0(virFirmware, 1);
+    firmwares[1] = g_new0(virFirmware, 1);
+
     firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader");
     firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin");
 
@@ -175,8 +176,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;
index 57c1ad4f46a0f1e59dc4c8f0b157f05819bba1c2..dab4b487b96c039c64f29fab950586b1495dfa64 100644 (file)
@@ -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 ||
index dff2b62028ebc29872f0619f6ec78a2493f58603..755732487a4e0fd9ed30b8d8259aec738312c675 100644 (file)
@@ -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;
index 0685b703a1e9dc0f82e6f7474e12653c4f999bf8..2489b883ff170baf6f26166dba07f16b1351a50d 100644 (file)
@@ -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,
index b023c49a69a36c9ae57de0eb65c4350d4ed454a6..2d12cacf28e2ed04e47344f57b7a94dca9487ffb 100644 (file)
@@ -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;
 
index bc25958e70f01f0001716fa0f72b1d0770493ab6..a0dcbba07b4d41e548561506e0cc01cc18eab590 100644 (file)
@@ -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;
index d74df15966c4b8a464f540e4fd5440ba9dac457c..2fc26577a7268cbe36192b75fa437f20eeeac301 100644 (file)
@@ -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",
index d544ae56cddcab5088c8039a30713db0981b59cb..6366432dd48fe60914dcf07295e8f6a7bda1e73c 100644 (file)
@@ -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;
 
index 14355d21662173ffe9b4242935ec853876cbb33c..b308ef5095fada700e0d513f6bcdf632abc47dd5 100644 (file)
@@ -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;
 }
 
index ae4b08b9d8a531090bbf79fa8189220e9cbcb05b..297cc0e53d1997a4e8937d18beb71320c14aee47 100644 (file)
@@ -74,8 +74,7 @@ testBuildDomainDef(bool dynamic,
     if (VIR_ALLOC_N(def->seclabels, 1) < 0)
         goto error;
 
-    if (VIR_ALLOC(secdef) < 0)
-        goto error;
+    secdef = g_new0(virSecurityLabelDef, 1);
 
     secdef->model = g_strdup("selinux");
 
index b0bad683a8687443a443f46a5b16bc598e905b1f..385db0849a728d264c4cdd69692be98c33d4bbc6 100644 (file)
@@ -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)
index 09d268627ce9f5a6ef7a88260db6ea6fcd7d1b7b..a20f351f93205eba301691e694bae5a9dd15df36 100644 (file)
@@ -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;
 
index a207f2d85fe9c15c2350ce7ad7e68c8b10bff3c1..76cc3d182f17929dfc9488596abc0865eab5a13a 100644 (file)
@@ -227,11 +227,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");
index 668fd02a1eff16d9c609a0ec9c572f2b965643b0..a4341c1641d7267ce8cf2aaac108ddd9fa9ca9a8 100644 (file)
@@ -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;
 }
index 704686ac10300f1d7bc4d319c55550a830de924e..b2ef57c3389efb55e9f02c54ddf33903c4eb07bb 100644 (file)
@@ -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");