mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: o-z: use g_new0
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
e59b8f96f7
commit
b15093d867
@ -1372,8 +1372,7 @@ virPCIDeviceNew(unsigned int domain,
|
||||
g_autofree char *vendor = NULL;
|
||||
g_autofree char *product = NULL;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
dev = g_new0(virPCIDevice, 1);
|
||||
|
||||
dev->address.domain = domain;
|
||||
dev->address.bus = bus;
|
||||
@ -1422,8 +1421,7 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
|
||||
{
|
||||
virPCIDevicePtr copy;
|
||||
|
||||
if (VIR_ALLOC(copy) < 0)
|
||||
return NULL;
|
||||
copy = g_new0(virPCIDevice, 1);
|
||||
|
||||
/* shallow copy to take care of most attributes */
|
||||
*copy = *dev;
|
||||
@ -1871,8 +1869,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq
|
||||
virPCIDeviceAddressPtr copyAddr;
|
||||
|
||||
/* make a copy to insert onto the list */
|
||||
if (VIR_ALLOC(copyAddr) < 0)
|
||||
goto cleanup;
|
||||
copyAddr = g_new0(virPCIDeviceAddress, 1);
|
||||
|
||||
*copyAddr = *newDevAddr;
|
||||
|
||||
@ -2204,8 +2201,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link)
|
||||
}
|
||||
|
||||
config_address = g_path_get_basename(device_path);
|
||||
if (VIR_ALLOC(bdf) < 0)
|
||||
return NULL;
|
||||
bdf = g_new0(virPCIDeviceAddress, 1);
|
||||
|
||||
if (virPCIDeviceAddressParse(config_address, bdf) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
@ -368,8 +368,7 @@ virPerfNew(void)
|
||||
size_t i;
|
||||
virPerfPtr perf;
|
||||
|
||||
if (VIR_ALLOC(perf) < 0)
|
||||
return NULL;
|
||||
perf = g_new0(virPerf, 1);
|
||||
|
||||
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
|
||||
perf->events[i].fd = -1;
|
||||
|
@ -178,8 +178,7 @@ virPolkitAgentCreate(void)
|
||||
if (virPipe(pipe_fd) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_ALLOC(agent) < 0)
|
||||
goto error;
|
||||
agent = g_new0(virPolkitAgent, 1);
|
||||
|
||||
agent->cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);
|
||||
|
||||
|
@ -102,8 +102,7 @@ virPortAllocatorRangeNew(const char *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(range) < 0)
|
||||
return NULL;
|
||||
range = g_new0(virPortAllocatorRange, 1);
|
||||
|
||||
range->start = start;
|
||||
range->end = end;
|
||||
|
@ -1351,8 +1351,7 @@ virProcessNamespaceAvailable(unsigned int ns)
|
||||
/* Signal parent as soon as the child dies. RIP. */
|
||||
flags |= SIGCHLD;
|
||||
|
||||
if (VIR_ALLOC_N(stack, stacksize) < 0)
|
||||
return -1;
|
||||
stack = g_new0(char, stacksize);
|
||||
|
||||
childStack = stack + stacksize;
|
||||
|
||||
|
@ -105,8 +105,7 @@ virRotatingFileWriterEntryNew(const char *path,
|
||||
|
||||
VIR_DEBUG("Opening %s mode=0%02o", path, mode);
|
||||
|
||||
if (VIR_ALLOC(entry) < 0)
|
||||
return NULL;
|
||||
entry = g_new0(virRotatingFileWriterEntry, 1);
|
||||
|
||||
if ((entry->fd = open(path, O_CREAT|O_APPEND|O_WRONLY|O_CLOEXEC, mode)) < 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -148,8 +147,7 @@ virRotatingFileReaderEntryNew(const char *path)
|
||||
|
||||
VIR_DEBUG("Opening %s", path);
|
||||
|
||||
if (VIR_ALLOC(entry) < 0)
|
||||
return NULL;
|
||||
entry = g_new0(virRotatingFileReaderEntry, 1);
|
||||
|
||||
if ((entry->fd = open(path, O_RDONLY|O_CLOEXEC)) < 0) {
|
||||
if (errno != ENOENT) {
|
||||
@ -238,8 +236,7 @@ virRotatingFileWriterNew(const char *path,
|
||||
{
|
||||
virRotatingFileWriterPtr file;
|
||||
|
||||
if (VIR_ALLOC(file) < 0)
|
||||
goto error;
|
||||
file = g_new0(virRotatingFileWriter, 1);
|
||||
|
||||
file->basepath = g_strdup(path);
|
||||
|
||||
@ -288,8 +285,7 @@ virRotatingFileReaderNew(const char *path,
|
||||
virRotatingFileReaderPtr file;
|
||||
size_t i;
|
||||
|
||||
if (VIR_ALLOC(file) < 0)
|
||||
goto error;
|
||||
file = g_new0(virRotatingFileReader, 1);
|
||||
|
||||
if (maxbackup > VIR_MAX_MAX_BACKUP) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
@ -299,8 +295,7 @@ virRotatingFileReaderNew(const char *path,
|
||||
}
|
||||
|
||||
file->nentries = maxbackup + 1;
|
||||
if (VIR_ALLOC_N(file->entries, file->nentries) < 0)
|
||||
goto error;
|
||||
file->entries = g_new0(virRotatingFileReaderEntryPtr, file->nentries);
|
||||
|
||||
if (!(file->entries[file->nentries - 1] = virRotatingFileReaderEntryNew(path)))
|
||||
goto error;
|
||||
|
@ -186,8 +186,7 @@ virSCSIDeviceNew(const char *sysfs_prefix,
|
||||
g_autofree char *model = NULL;
|
||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
dev = g_new0(virSCSIDevice, 1);
|
||||
|
||||
dev->bus = bus;
|
||||
dev->target = target;
|
||||
@ -263,8 +262,7 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
|
||||
{
|
||||
g_autoptr(virUsedByInfo) copy = NULL;
|
||||
|
||||
if (VIR_ALLOC(copy) < 0)
|
||||
return -1;
|
||||
copy = g_new0(virUsedByInfo, 1);
|
||||
copy->drvname = g_strdup(drvname);
|
||||
copy->domname = g_strdup(domname);
|
||||
|
||||
|
@ -250,8 +250,7 @@ virSCSIVHostDeviceNew(const char *name)
|
||||
{
|
||||
g_autoptr(virSCSIVHostDevice) dev = NULL;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
dev = g_new0(virSCSIVHostDevice, 1);
|
||||
|
||||
dev->name = g_strdup(name);
|
||||
|
||||
|
@ -58,10 +58,7 @@ virSecurityLabelDefNew(const char *model)
|
||||
{
|
||||
virSecurityLabelDefPtr seclabel = NULL;
|
||||
|
||||
if (VIR_ALLOC(seclabel) < 0) {
|
||||
virSecurityLabelDefFree(seclabel);
|
||||
return NULL;
|
||||
}
|
||||
seclabel = g_new0(virSecurityLabelDef, 1);
|
||||
|
||||
seclabel->model = g_strdup(model);
|
||||
|
||||
@ -75,10 +72,7 @@ virSecurityDeviceLabelDefNew(const char *model)
|
||||
{
|
||||
virSecurityDeviceLabelDefPtr seclabel = NULL;
|
||||
|
||||
if (VIR_ALLOC(seclabel) < 0) {
|
||||
virSecurityDeviceLabelDefFree(seclabel);
|
||||
return NULL;
|
||||
}
|
||||
seclabel = g_new0(virSecurityDeviceLabelDef, 1);
|
||||
|
||||
seclabel->model = g_strdup(model);
|
||||
|
||||
@ -91,8 +85,7 @@ virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src)
|
||||
{
|
||||
virSecurityDeviceLabelDefPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virSecurityDeviceLabelDef, 1);
|
||||
|
||||
ret->relabel = src->relabel;
|
||||
ret->labelskip = src->labelskip;
|
||||
|
@ -115,12 +115,9 @@ virStorageEncryptionCopy(const virStorageEncryption *src)
|
||||
virStorageEncryptionPtr ret;
|
||||
size_t i;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(ret->secrets, src->nsecrets) < 0)
|
||||
goto error;
|
||||
ret = g_new0(virStorageEncryption, 1);
|
||||
|
||||
ret->secrets = g_new0(virStorageEncryptionSecretPtr, src->nsecrets);
|
||||
ret->nsecrets = src->nsecrets;
|
||||
ret->format = src->format;
|
||||
|
||||
@ -147,8 +144,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
|
||||
virStorageEncryptionSecretPtr ret;
|
||||
char *type_str = NULL;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virStorageEncryptionSecret, 1);
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
@ -247,8 +243,7 @@ virStorageEncryptionParseNode(xmlNodePtr node,
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
if (VIR_ALLOC(encdef) < 0)
|
||||
goto cleanup;
|
||||
encdef = g_new0(virStorageEncryption, 1);
|
||||
|
||||
if (!(format_str = virXPathString("string(./@format)", ctxt))) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
@ -268,8 +263,7 @@ virStorageEncryptionParseNode(xmlNodePtr node,
|
||||
goto cleanup;
|
||||
|
||||
if (n > 0) {
|
||||
if (VIR_ALLOC_N(encdef->secrets, n) < 0)
|
||||
goto cleanup;
|
||||
encdef->secrets = g_new0(virStorageEncryptionSecretPtr, n);
|
||||
encdef->nsecrets = n;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
@ -1222,8 +1222,7 @@ virStringToUpper(char **dst, const char *src)
|
||||
if (!src)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC_N(cap, strlen(src) + 1) < 0)
|
||||
return -1;
|
||||
cap = g_new0(char, strlen(src) + 1);
|
||||
|
||||
for (i = 0; src[i]; i++) {
|
||||
cap[i] = g_ascii_toupper(src[i]);
|
||||
|
@ -188,9 +188,8 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain, bool priority)
|
||||
|
||||
for (i = 0; i < gain; i++) {
|
||||
g_autofree char *name = NULL;
|
||||
if (VIR_ALLOC(data) < 0)
|
||||
goto error;
|
||||
|
||||
data = g_new0(struct virThreadPoolWorkerData, 1);
|
||||
data->pool = pool;
|
||||
data->cond = priority ? &pool->prioCond : &pool->cond;
|
||||
data->priority = priority;
|
||||
@ -232,8 +231,7 @@ virThreadPoolNewFull(size_t minWorkers,
|
||||
if (minWorkers > maxWorkers)
|
||||
minWorkers = maxWorkers;
|
||||
|
||||
if (VIR_ALLOC(pool) < 0)
|
||||
return NULL;
|
||||
pool = g_new0(virThreadPool, 1);
|
||||
|
||||
pool->jobList.tail = pool->jobList.head = NULL;
|
||||
|
||||
@ -403,8 +401,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
|
||||
virThreadPoolExpand(pool, 1, false) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_ALLOC(job) < 0)
|
||||
goto error;
|
||||
job = g_new0(virThreadPoolJob, 1);
|
||||
|
||||
job->data = jobData;
|
||||
job->priority = priority;
|
||||
|
@ -257,8 +257,7 @@ char *virTimeStringNow(void)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(char, VIR_TIME_STRING_BUFLEN);
|
||||
|
||||
if (virTimeStringNowRaw(ret) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
@ -286,8 +285,7 @@ char *virTimeStringThen(unsigned long long when)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(char, VIR_TIME_STRING_BUFLEN);
|
||||
|
||||
if (virTimeStringThenRaw(when, ret) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
|
@ -68,8 +68,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
|
||||
va_start(ap, nparams);
|
||||
|
||||
if (VIR_ALLOC_N(sorted, nparams) < 0)
|
||||
goto cleanup;
|
||||
sorted = g_new0(virTypedParameter, nparams);
|
||||
|
||||
/* Here we intentionally don't copy values */
|
||||
memcpy(sorted, params, sizeof(*params) * nparams);
|
||||
@ -361,8 +360,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
|
||||
if (!src || nparams <= 0)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC_N(*dst, nparams) < 0)
|
||||
return -1;
|
||||
*dst = g_new0(virTypedParameter, nparams);
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field));
|
||||
@ -399,8 +397,7 @@ virTypedParamsFilter(virTypedParameterPtr params,
|
||||
{
|
||||
size_t i, n = 0;
|
||||
|
||||
if (VIR_ALLOC_N(*ret, nparams) < 0)
|
||||
return -1;
|
||||
*ret = g_new0(virTypedParameterPtr, nparams);
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
if (STREQ(params[i].field, name)) {
|
||||
@ -447,9 +444,8 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
|
||||
if (nfiltered < 0)
|
||||
goto error;
|
||||
|
||||
if (nfiltered &&
|
||||
VIR_ALLOC_N(*values, nfiltered) < 0)
|
||||
goto error;
|
||||
if (nfiltered)
|
||||
*values = g_new0(const char *, nfiltered);
|
||||
|
||||
for (n = 0, i = 0; i < nfiltered; i++) {
|
||||
if (filtered[i]->type == VIR_TYPED_PARAM_STRING)
|
||||
@ -551,8 +547,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
if (VIR_ALLOC_N(*params, remote_params_len) < 0)
|
||||
goto cleanup;
|
||||
*params = g_new0(virTypedParameter, remote_params_len);
|
||||
}
|
||||
*nparams = remote_params_len;
|
||||
|
||||
@ -662,8 +657,7 @@ virTypedParamsSerialize(virTypedParameterPtr params,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(params_val, nparams) < 0)
|
||||
goto cleanup;
|
||||
params_val = g_new0(struct _virTypedParameterRemote, nparams);
|
||||
|
||||
for (i = 0, j = 0; i < nparams; ++i) {
|
||||
virTypedParameterPtr param = params + i;
|
||||
|
@ -157,8 +157,7 @@ virURIParse(const char *uri)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto error;
|
||||
ret = g_new0(virURI, 1);
|
||||
|
||||
ret->scheme = g_strdup(xmluri->scheme);
|
||||
ret->server = g_strdup(xmluri->server);
|
||||
|
@ -312,8 +312,7 @@ virUSBDeviceNew(unsigned int bus,
|
||||
{
|
||||
virUSBDevicePtr dev;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
dev = g_new0(virUSBDevice, 1);
|
||||
|
||||
dev->bus = bus;
|
||||
dev->dev = devno;
|
||||
|
@ -447,8 +447,7 @@ char *virIndexToDiskName(int idx, const char *prefix)
|
||||
|
||||
offset = strlen(prefix);
|
||||
|
||||
if (VIR_ALLOC_N(name, offset + i + 1))
|
||||
return NULL;
|
||||
name = g_new0(char, offset + i + 1);
|
||||
|
||||
strcpy(name, prefix);
|
||||
name[offset + i] = '\0';
|
||||
@ -618,8 +617,7 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bo
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
return -1;
|
||||
strbuf = g_new0(char, strbuflen);
|
||||
|
||||
/*
|
||||
* From the manpage (terrifying but true):
|
||||
@ -688,8 +686,7 @@ static char *virGetGroupEnt(gid_t gid)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
return NULL;
|
||||
strbuf = g_new0(char, strbuflen);
|
||||
|
||||
/*
|
||||
* From the manpage (terrifying but true):
|
||||
@ -774,8 +771,7 @@ virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
strbuf = g_new0(char, strbuflen);
|
||||
|
||||
while ((rc = getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
|
||||
@ -856,8 +852,7 @@ virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
strbuf = g_new0(char, strbuflen);
|
||||
|
||||
while ((rc = getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
|
||||
|
@ -672,9 +672,7 @@ virXPathNodeSet(const char *xpath,
|
||||
|
||||
ret = obj->nodesetval->nodeNr;
|
||||
if (list != NULL && ret) {
|
||||
if (VIR_ALLOC_N(*list, ret) < 0)
|
||||
return -1;
|
||||
|
||||
*list = g_new0(xmlNodePtr, ret);
|
||||
memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr));
|
||||
}
|
||||
xmlXPathFreeObject(obj);
|
||||
@ -1237,8 +1235,7 @@ virXMLValidatorInit(const char *schemafile)
|
||||
{
|
||||
virXMLValidatorPtr validator = NULL;
|
||||
|
||||
if (VIR_ALLOC(validator) < 0)
|
||||
return NULL;
|
||||
validator = g_new0(virXMLValidator, 1);
|
||||
|
||||
validator->schemafile = g_strdup(schemafile);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user