mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
tests: use g_new0 instead of VIR_ALLOC
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
cc9674c318
commit
a037ae8614
@ -150,8 +150,9 @@ fillXenCaps(virDomainCapsPtr domCaps)
|
|||||||
if (VIR_ALLOC_N(firmwares, 2) < 0)
|
if (VIR_ALLOC_N(firmwares, 2) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0)
|
firmwares[0] = g_new0(virFirmware, 1);
|
||||||
goto cleanup;
|
firmwares[1] = g_new0(virFirmware, 1);
|
||||||
|
|
||||||
firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader");
|
firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader");
|
||||||
firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin");
|
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;
|
virDomainCapsStringValuesPtr firmwares = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(firmwares) < 0)
|
firmwares = g_new0(virDomainCapsStringValues, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (fillStringValues(firmwares, "/foo/bar", "/foo/baz", NULL) < 0)
|
if (fillStringValues(firmwares, "/foo/bar", "/foo/baz", NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -162,11 +162,8 @@ fakeRootDevice(void)
|
|||||||
{
|
{
|
||||||
virNodeDeviceDefPtr def = NULL;
|
virNodeDeviceDefPtr def = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) != 0 || VIR_ALLOC(def->caps) != 0) {
|
def = g_new0(virNodeDeviceDef, 1);
|
||||||
virNodeDeviceDefFree(def);
|
def->caps = g_new0(virNodeDevCapsDef, 1);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
def->name = g_strdup("computer");
|
def->name = g_strdup("computer");
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
@ -182,10 +179,8 @@ fakeParentDevice(void)
|
|||||||
virNodeDeviceDefPtr def = NULL;
|
virNodeDeviceDefPtr def = NULL;
|
||||||
virNodeDevCapPCIDevPtr pci_dev;
|
virNodeDevCapPCIDevPtr pci_dev;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) != 0 || VIR_ALLOC(def->caps) != 0) {
|
def = g_new0(virNodeDeviceDef, 1);
|
||||||
virNodeDeviceDefFree(def);
|
def->caps = g_new0(virNodeDevCapsDef, 1);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
def->name = g_strdup("pci_0000_00_02_0");
|
def->name = g_strdup("pci_0000_00_02_0");
|
||||||
def->parent = g_strdup("computer");
|
def->parent = g_strdup("computer");
|
||||||
@ -233,8 +228,7 @@ static int
|
|||||||
nodedevTestDriverInit(void)
|
nodedevTestDriverInit(void)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (VIR_ALLOC(driver) < 0)
|
driver = g_new0(virNodeDeviceDriverState, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
driver->lockFD = -1;
|
driver->lockFD = -1;
|
||||||
if (virMutexInit(&driver->lock) < 0 ||
|
if (virMutexInit(&driver->lock) < 0 ||
|
||||||
|
@ -209,8 +209,7 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def,
|
|||||||
virNWFilterRuleInstPtr ruleinst;
|
virNWFilterRuleInstPtr ruleinst;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(ruleinst) < 0)
|
ruleinst = g_new0(virNWFilterRuleInst, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ruleinst->chainSuffix = def->chainsuffix;
|
ruleinst->chainSuffix = def->chainsuffix;
|
||||||
ruleinst->chainPriority = def->chainPriority;
|
ruleinst->chainPriority = def->chainPriority;
|
||||||
|
@ -234,8 +234,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
|
|||||||
srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
||||||
|
|
||||||
if (src->auth) {
|
if (src->auth) {
|
||||||
if (VIR_ALLOC(srcpriv->secinfo) < 0)
|
srcpriv->secinfo = g_new0(qemuDomainSecretInfo, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
||||||
srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
|
srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
|
||||||
@ -245,8 +244,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (src->encryption) {
|
if (src->encryption) {
|
||||||
if (VIR_ALLOC(srcpriv->encinfo) < 0)
|
srcpriv->encinfo = g_new0(qemuDomainSecretInfo, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
srcpriv->encinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
|
||||||
srcpriv->encinfo->s.aes.alias = g_strdup_printf("%s-encalias",
|
srcpriv->encinfo->s.aes.alias = g_strdup_printf("%s-encalias",
|
||||||
@ -493,8 +491,7 @@ testQemuImageCreateLoadDiskXML(const char *name,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(diskdef) < 0)
|
diskdef = g_new0(virDomainSnapshotDiskDef, 1);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (virDomainSnapshotDiskDefParseXML(node, ctxt, diskdef,
|
if (virDomainSnapshotDiskDefParseXML(node, ctxt, diskdef,
|
||||||
VIR_DOMAIN_DEF_PARSE_STATUS,
|
VIR_DOMAIN_DEF_PARSE_STATUS,
|
||||||
|
@ -413,8 +413,7 @@ testQemuHotplugCpuPrepare(const char *test,
|
|||||||
|
|
||||||
prefix = g_strdup_printf("%s/qemuhotplugtestcpus/%s", abs_srcdir, test);
|
prefix = g_strdup_printf("%s/qemuhotplugtestcpus/%s", abs_srcdir, test);
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
data = g_new0(struct testQemuHotplugCpuData, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
data->modern = modern;
|
data->modern = modern;
|
||||||
|
|
||||||
|
@ -1653,8 +1653,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque)
|
|||||||
!(expectedBlockDevices = virHashCreate(32, virHashValueFree)))
|
!(expectedBlockDevices = virHashCreate(32, virHashValueFree)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC(info) < 0)
|
info = g_new0(struct qemuDomainDiskInfo, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virHashAddEntry(expectedBlockDevices, "virtio-disk0", info) < 0) {
|
if (virHashAddEntry(expectedBlockDevices, "virtio-disk0", info) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -1662,8 +1661,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(info) < 0)
|
info = g_new0(struct qemuDomainDiskInfo, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virHashAddEntry(expectedBlockDevices, "virtio-disk1", info) < 0) {
|
if (virHashAddEntry(expectedBlockDevices, "virtio-disk1", info) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -1671,8 +1669,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(info) < 0)
|
info = g_new0(struct qemuDomainDiskInfo, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
info->removable = true;
|
info->removable = true;
|
||||||
info->tray = true;
|
info->tray = true;
|
||||||
@ -1683,8 +1680,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(info) < 0)
|
info = g_new0(struct qemuDomainDiskInfo, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
info->removable = true;
|
info->removable = true;
|
||||||
info->tray = true;
|
info->tray = true;
|
||||||
|
@ -461,8 +461,7 @@ qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
|
|||||||
{
|
{
|
||||||
qemuMonitorTestItemPtr item;
|
qemuMonitorTestItemPtr item;
|
||||||
|
|
||||||
if (VIR_ALLOC(item) < 0)
|
item = g_new0(qemuMonitorTestItem, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
item->identifier = g_strdup(identifier);
|
item->identifier = g_strdup(identifier);
|
||||||
item->cb = cb;
|
item->cb = cb;
|
||||||
@ -619,8 +618,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
|
|||||||
{
|
{
|
||||||
struct qemuMonitorTestHandlerData *data;
|
struct qemuMonitorTestHandlerData *data;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
data = g_new0(struct qemuMonitorTestHandlerData, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
data->command_name = g_strdup(command_name);
|
data->command_name = g_strdup(command_name);
|
||||||
data->response = g_strdup(response);
|
data->response = g_strdup(response);
|
||||||
@ -694,8 +692,7 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
|
|||||||
{
|
{
|
||||||
struct qemuMonitorTestHandlerData *data;
|
struct qemuMonitorTestHandlerData *data;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
data = g_new0(struct qemuMonitorTestHandlerData, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
data->response = g_strdup(response);
|
data->response = g_strdup(response);
|
||||||
data->cmderr = g_strdup(cmderr);
|
data->cmderr = g_strdup(cmderr);
|
||||||
@ -856,8 +853,7 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
|
|||||||
|
|
||||||
va_start(args, response);
|
va_start(args, response);
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
data = g_new0(struct qemuMonitorTestHandlerData, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
data->command_name = g_strdup(cmdname);
|
data->command_name = g_strdup(cmdname);
|
||||||
data->response = g_strdup(response);
|
data->response = g_strdup(response);
|
||||||
@ -962,8 +958,7 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
|
|||||||
{
|
{
|
||||||
struct qemuMonitorTestHandlerData *data;
|
struct qemuMonitorTestHandlerData *data;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
data = g_new0(struct qemuMonitorTestHandlerData, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
data->command_name = g_strdup(cmdname);
|
data->command_name = g_strdup(cmdname);
|
||||||
data->response = g_strdup(response);
|
data->response = g_strdup(response);
|
||||||
@ -984,10 +979,6 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
|
|||||||
cmdname,
|
cmdname,
|
||||||
qemuMonitorTestProcessCommandWithArgStr,
|
qemuMonitorTestProcessCommandWithArgStr,
|
||||||
data, qemuMonitorTestHandlerDataFree);
|
data, qemuMonitorTestHandlerDataFree);
|
||||||
|
|
||||||
error:
|
|
||||||
qemuMonitorTestHandlerDataFree(data);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1036,8 +1027,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
|
|||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char *tmpdir_template = NULL;
|
char *tmpdir_template = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(test) < 0)
|
test = g_new0(qemuMonitorTest, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (virMutexInit(&test->lock) < 0) {
|
if (virMutexInit(&test->lock) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
@ -270,8 +270,7 @@ mock_chown(const char *path,
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(val) < 0)
|
val = g_new0(uint32_t, 1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
*val = (gid << 16) + uid;
|
*val = (gid << 16) + uid;
|
||||||
|
|
||||||
|
@ -292,8 +292,7 @@ selabel_open(unsigned int backend,
|
|||||||
return real_selabel_open(backend, opts, nopts);
|
return real_selabel_open(backend, opts, nopts);
|
||||||
|
|
||||||
/* struct selabel_handle is opaque; fake it */
|
/* struct selabel_handle is opaque; fake it */
|
||||||
if (VIR_ALLOC(fake_handle) < 0)
|
fake_handle = g_new0(char, 1);
|
||||||
return NULL;
|
|
||||||
return (struct selabel_handle *)fake_handle;
|
return (struct selabel_handle *)fake_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,7 @@ testBuildDomainDef(bool dynamic,
|
|||||||
if (VIR_ALLOC_N(def->seclabels, 1) < 0)
|
if (VIR_ALLOC_N(def->seclabels, 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC(secdef) < 0)
|
secdef = g_new0(virSecurityLabelDef, 1);
|
||||||
goto error;
|
|
||||||
|
|
||||||
secdef->model = g_strdup("selinux");
|
secdef->model = g_strdup("selinux");
|
||||||
|
|
||||||
|
@ -149,8 +149,7 @@ myInit(void)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(mgr) < 0)
|
mgr = g_new0(virHostdevManager, 1);
|
||||||
goto cleanup;
|
|
||||||
if ((mgr->activePCIHostdevs = virPCIDeviceListNew()) == NULL)
|
if ((mgr->activePCIHostdevs = virPCIDeviceListNew()) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((mgr->activeUSBHostdevs = virUSBDeviceListNew()) == NULL)
|
if ((mgr->activeUSBHostdevs = virUSBDeviceListNew()) == NULL)
|
||||||
|
@ -38,8 +38,7 @@ testClientNew(virNetServerClientPtr client G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
struct testClientPriv *priv;
|
struct testClientPriv *priv;
|
||||||
|
|
||||||
if (VIR_ALLOC(priv) < 0)
|
priv = g_new0(struct testClientPriv, 1);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
priv->magic = 1729;
|
priv->magic = 1729;
|
||||||
|
|
||||||
|
@ -227,11 +227,10 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED)
|
|||||||
err.domain = VIR_FROM_RPC;
|
err.domain = VIR_FROM_RPC;
|
||||||
err.level = VIR_ERR_ERROR;
|
err.level = VIR_ERR_ERROR;
|
||||||
|
|
||||||
if (VIR_ALLOC(err.message) < 0 ||
|
err.message = g_new0(char *, 1);
|
||||||
VIR_ALLOC(err.str1) < 0 ||
|
err.str1 = g_new0(char *, 1);
|
||||||
VIR_ALLOC(err.str2) < 0 ||
|
err.str2 = g_new0(char *, 1);
|
||||||
VIR_ALLOC(err.str3) < 0)
|
err.str3 = g_new0(char *, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
*err.message = g_strdup("Hello World");
|
*err.message = g_strdup("Hello World");
|
||||||
*err.str1 = g_strdup("One");
|
*err.str1 = g_strdup("One");
|
||||||
|
@ -32,8 +32,7 @@ testClientNew(virNetServerClientPtr client G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
char *dummy;
|
char *dummy;
|
||||||
|
|
||||||
if (VIR_ALLOC(dummy) < 0)
|
dummy = g_new0(char, 1);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return dummy;
|
return dummy;
|
||||||
}
|
}
|
||||||
|
@ -176,9 +176,8 @@ static int testAdd(const void *args)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list &&
|
if (!list)
|
||||||
VIR_ALLOC(list) < 0)
|
list = g_new0(char *, 1);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(got = virStringListJoin((const char **)list, data->delim))) {
|
if (!(got = virStringListJoin((const char **)list, data->delim))) {
|
||||||
VIR_DEBUG("Got no result");
|
VIR_DEBUG("Got no result");
|
||||||
|
Loading…
Reference in New Issue
Block a user