From nobody Sun Feb 8 10:21:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601920216; cv=none; d=zohomail.com; s=zohoarc; b=lSjJX4fAYgruAqSaAYJF0lze996d5WO8yGHmvsI2gCnfMoavxS2WFxu+ylhpcFWUpPiIgpkDMupRIj0IFZgyU7Atpp1pApunuYcuf8s8WqpdfScaurl4ASmPTHgfcAVnAnZVRqAFBOwNfI/EKPXHcii0CYtiUODtdoaVvxL0v7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601920216; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iGpQ3z4jv/Bn2zTdBoNFc+JGXz9BjdQwIC8UZoqlW9E=; b=W0DpzL14MlZQq9EzAqQwXeikIE2w88FtPgX1K9GKcYlEYzoZLvQdKntGobXdwzYCIlUVScu1Mzwp8H9b2krFFWoc+iti9WQ57ULfHts/Li/sfyHFJrJOEoNXLyJU3x03rFBUBlPvzCKbDnJm7UNVnl0ChRLiLlwBMO461unBJYM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601920216752725.3589248881003; Mon, 5 Oct 2020 10:50:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-5MsEt6MNMRKEVQAIjawJpA-1; Mon, 05 Oct 2020 13:49:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 383BC18C89C7; Mon, 5 Oct 2020 17:48:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 153BB5C225; Mon, 5 Oct 2020 17:48:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D5EE71826D33; Mon, 5 Oct 2020 17:48:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 095HmhL7015688 for ; Mon, 5 Oct 2020 13:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id A59105C1C4; Mon, 5 Oct 2020 17:48:43 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C9CB5C1BD for ; Mon, 5 Oct 2020 17:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601920215; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iGpQ3z4jv/Bn2zTdBoNFc+JGXz9BjdQwIC8UZoqlW9E=; b=HFLI8awMC0tQCMr3ySYNuwfSSNTLCKLqsh6fb9BHbcz/4+K+iNF6P4A2UiWTOwN+9cVxKl 0hTDDopswUbFX8ZfpG/jhXmJ/FB83Qtmz/1VmXR/8ZJ9uKjjIYCiJ0mYDQNciDZgByK5tY r+zTSU2Bu4d1W3Li62WFfM2Fm7Uzyjc= X-MC-Unique: 5MsEt6MNMRKEVQAIjawJpA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 12/12] util: o-z: use g_new0 Date: Mon, 5 Oct 2020 19:48:27 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko --- src/util/virpci.c | 12 ++++-------- src/util/virperf.c | 3 +-- src/util/virpolkit.c | 3 +-- src/util/virportallocator.c | 3 +-- src/util/virprocess.c | 3 +-- src/util/virrotatingfile.c | 15 +++++---------- src/util/virscsi.c | 6 ++---- src/util/virscsivhost.c | 3 +-- src/util/virseclabel.c | 13 +++---------- src/util/virstorageencryption.c | 16 +++++----------- src/util/virstring.c | 3 +-- src/util/virthreadpool.c | 9 +++------ src/util/virtime.c | 6 ++---- src/util/virtypedparam.c | 20 +++++++------------- src/util/viruri.c | 3 +-- src/util/virusb.c | 3 +-- src/util/virutil.c | 15 +++++---------- src/util/virxml.c | 7 ++----- 18 files changed, 46 insertions(+), 97 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 47c671daa0..6fa8acd246 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1372,8 +1372,7 @@ virPCIDeviceNew(unsigned int domain, g_autofree char *vendor =3D NULL; g_autofree char *product =3D NULL; =20 - if (VIR_ALLOC(dev) < 0) - return NULL; + dev =3D g_new0(virPCIDevice, 1); =20 dev->address.domain =3D domain; dev->address.bus =3D bus; @@ -1422,8 +1421,7 @@ virPCIDeviceCopy(virPCIDevicePtr dev) { virPCIDevicePtr copy; =20 - if (VIR_ALLOC(copy) < 0) - return NULL; + copy =3D g_new0(virPCIDevice, 1); =20 /* shallow copy to take care of most attributes */ *copy =3D *dev; @@ -1871,8 +1869,7 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddres= sPtr newDevAddr, void *opaq virPCIDeviceAddressPtr copyAddr; =20 /* make a copy to insert onto the list */ - if (VIR_ALLOC(copyAddr) < 0) - goto cleanup; + copyAddr =3D g_new0(virPCIDeviceAddress, 1); =20 *copyAddr =3D *newDevAddr; =20 @@ -2204,8 +2201,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *devic= e_link) } =20 config_address =3D g_path_get_basename(device_path); - if (VIR_ALLOC(bdf) < 0) - return NULL; + bdf =3D g_new0(virPCIDeviceAddress, 1); =20 if (virPCIDeviceAddressParse(config_address, bdf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virperf.c b/src/util/virperf.c index 2e95509caf..7f260d2da6 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -368,8 +368,7 @@ virPerfNew(void) size_t i; virPerfPtr perf; =20 - if (VIR_ALLOC(perf) < 0) - return NULL; + perf =3D g_new0(virPerf, 1); =20 for (i =3D 0; i < VIR_PERF_EVENT_LAST; i++) { perf->events[i].fd =3D -1; diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index aad924a065..1d6be443f7 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -178,8 +178,7 @@ virPolkitAgentCreate(void) if (virPipe(pipe_fd) < 0) goto error; =20 - if (VIR_ALLOC(agent) < 0) - goto error; + agent =3D g_new0(virPolkitAgent, 1); =20 agent->cmd =3D virCommandNewArgList(PKTTYAGENT, "--process", NULL); =20 diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index f450740318..76c6e43726 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -102,8 +102,7 @@ virPortAllocatorRangeNew(const char *name, return NULL; } =20 - if (VIR_ALLOC(range) < 0) - return NULL; + range =3D g_new0(virPortAllocatorRange, 1); =20 range->start =3D start; range->end =3D end; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index d379f7446f..9366f0630c 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1351,8 +1351,7 @@ virProcessNamespaceAvailable(unsigned int ns) /* Signal parent as soon as the child dies. RIP. */ flags |=3D SIGCHLD; =20 - if (VIR_ALLOC_N(stack, stacksize) < 0) - return -1; + stack =3D g_new0(char, stacksize); =20 childStack =3D stack + stacksize; =20 diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c index b77e30dba7..a88c332cf4 100644 --- a/src/util/virrotatingfile.c +++ b/src/util/virrotatingfile.c @@ -105,8 +105,7 @@ virRotatingFileWriterEntryNew(const char *path, =20 VIR_DEBUG("Opening %s mode=3D0%02o", path, mode); =20 - if (VIR_ALLOC(entry) < 0) - return NULL; + entry =3D g_new0(virRotatingFileWriterEntry, 1); =20 if ((entry->fd =3D open(path, O_CREAT|O_APPEND|O_WRONLY|O_CLOEXEC, mod= e)) < 0) { virReportSystemError(errno, @@ -148,8 +147,7 @@ virRotatingFileReaderEntryNew(const char *path) =20 VIR_DEBUG("Opening %s", path); =20 - if (VIR_ALLOC(entry) < 0) - return NULL; + entry =3D g_new0(virRotatingFileReaderEntry, 1); =20 if ((entry->fd =3D open(path, O_RDONLY|O_CLOEXEC)) < 0) { if (errno !=3D ENOENT) { @@ -238,8 +236,7 @@ virRotatingFileWriterNew(const char *path, { virRotatingFileWriterPtr file; =20 - if (VIR_ALLOC(file) < 0) - goto error; + file =3D g_new0(virRotatingFileWriter, 1); =20 file->basepath =3D g_strdup(path); =20 @@ -288,8 +285,7 @@ virRotatingFileReaderNew(const char *path, virRotatingFileReaderPtr file; size_t i; =20 - if (VIR_ALLOC(file) < 0) - goto error; + file =3D g_new0(virRotatingFileReader, 1); =20 if (maxbackup > VIR_MAX_MAX_BACKUP) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -299,8 +295,7 @@ virRotatingFileReaderNew(const char *path, } =20 file->nentries =3D maxbackup + 1; - if (VIR_ALLOC_N(file->entries, file->nentries) < 0) - goto error; + file->entries =3D g_new0(virRotatingFileReaderEntryPtr, file->nentries= ); =20 if (!(file->entries[file->nentries - 1] =3D virRotatingFileReaderEntry= New(path))) goto error; diff --git a/src/util/virscsi.c b/src/util/virscsi.c index e3bd81b569..4dcd68d53a 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -186,8 +186,7 @@ virSCSIDeviceNew(const char *sysfs_prefix, g_autofree char *model =3D NULL; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; =20 - if (VIR_ALLOC(dev) < 0) - return NULL; + dev =3D g_new0(virSCSIDevice, 1); =20 dev->bus =3D bus; dev->target =3D target; @@ -263,8 +262,7 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, { g_autoptr(virUsedByInfo) copy =3D NULL; =20 - if (VIR_ALLOC(copy) < 0) - return -1; + copy =3D g_new0(virUsedByInfo, 1); copy->drvname =3D g_strdup(drvname); copy->domname =3D g_strdup(domname); =20 diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index be1f57c6e2..a2bf9a446f 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -250,8 +250,7 @@ virSCSIVHostDeviceNew(const char *name) { g_autoptr(virSCSIVHostDevice) dev =3D NULL; =20 - if (VIR_ALLOC(dev) < 0) - return NULL; + dev =3D g_new0(virSCSIVHostDevice, 1); =20 dev->name =3D g_strdup(name); =20 diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c index 2141d84210..174f344a8b 100644 --- a/src/util/virseclabel.c +++ b/src/util/virseclabel.c @@ -58,10 +58,7 @@ virSecurityLabelDefNew(const char *model) { virSecurityLabelDefPtr seclabel =3D NULL; =20 - if (VIR_ALLOC(seclabel) < 0) { - virSecurityLabelDefFree(seclabel); - return NULL; - } + seclabel =3D g_new0(virSecurityLabelDef, 1); =20 seclabel->model =3D g_strdup(model); =20 @@ -75,10 +72,7 @@ virSecurityDeviceLabelDefNew(const char *model) { virSecurityDeviceLabelDefPtr seclabel =3D NULL; =20 - if (VIR_ALLOC(seclabel) < 0) { - virSecurityDeviceLabelDefFree(seclabel); - return NULL; - } + seclabel =3D g_new0(virSecurityDeviceLabelDef, 1); =20 seclabel->model =3D g_strdup(model); =20 @@ -91,8 +85,7 @@ virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabe= lDef *src) { virSecurityDeviceLabelDefPtr ret; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virSecurityDeviceLabelDef, 1); =20 ret->relabel =3D src->relabel; ret->labelskip =3D src->labelskip; diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryptio= n.c index 76958b3876..399c6926bd 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -115,12 +115,9 @@ virStorageEncryptionCopy(const virStorageEncryption *s= rc) virStorageEncryptionPtr ret; size_t i; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; - - if (VIR_ALLOC_N(ret->secrets, src->nsecrets) < 0) - goto error; + ret =3D g_new0(virStorageEncryption, 1); =20 + ret->secrets =3D g_new0(virStorageEncryptionSecretPtr, src->nsecrets); ret->nsecrets =3D src->nsecrets; ret->format =3D src->format; =20 @@ -147,8 +144,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, virStorageEncryptionSecretPtr ret; char *type_str =3D NULL; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virStorageEncryptionSecret, 1); =20 ctxt->node =3D node; =20 @@ -247,8 +243,7 @@ virStorageEncryptionParseNode(xmlNodePtr node, =20 ctxt->node =3D node; =20 - if (VIR_ALLOC(encdef) < 0) - goto cleanup; + encdef =3D g_new0(virStorageEncryption, 1); =20 if (!(format_str =3D virXPathString("string(./@format)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -268,8 +263,7 @@ virStorageEncryptionParseNode(xmlNodePtr node, goto cleanup; =20 if (n > 0) { - if (VIR_ALLOC_N(encdef->secrets, n) < 0) - goto cleanup; + encdef->secrets =3D g_new0(virStorageEncryptionSecretPtr, n); encdef->nsecrets =3D n; =20 for (i =3D 0; i < n; i++) { diff --git a/src/util/virstring.c b/src/util/virstring.c index de2ef964f4..5c49b56f75 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1222,8 +1222,7 @@ virStringToUpper(char **dst, const char *src) if (!src) return 0; =20 - if (VIR_ALLOC_N(cap, strlen(src) + 1) < 0) - return -1; + cap =3D g_new0(char, strlen(src) + 1); =20 for (i =3D 0; src[i]; i++) { cap[i] =3D g_ascii_toupper(src[i]); diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index ca44f55c1b..3942633431 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -188,9 +188,8 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain,= bool priority) =20 for (i =3D 0; i < gain; i++) { g_autofree char *name =3D NULL; - if (VIR_ALLOC(data) < 0) - goto error; =20 + data =3D g_new0(struct virThreadPoolWorkerData, 1); data->pool =3D pool; data->cond =3D priority ? &pool->prioCond : &pool->cond; data->priority =3D priority; @@ -232,8 +231,7 @@ virThreadPoolNewFull(size_t minWorkers, if (minWorkers > maxWorkers) minWorkers =3D maxWorkers; =20 - if (VIR_ALLOC(pool) < 0) - return NULL; + pool =3D g_new0(virThreadPool, 1); =20 pool->jobList.tail =3D pool->jobList.head =3D NULL; =20 @@ -403,8 +401,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, virThreadPoolExpand(pool, 1, false) < 0) goto error; =20 - if (VIR_ALLOC(job) < 0) - goto error; + job =3D g_new0(virThreadPoolJob, 1); =20 job->data =3D jobData; job->priority =3D priority; diff --git a/src/util/virtime.c b/src/util/virtime.c index 88f6f0a551..baf4ce5db7 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -257,8 +257,7 @@ char *virTimeStringNow(void) { char *ret; =20 - if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) - return NULL; + ret =3D g_new0(char, VIR_TIME_STRING_BUFLEN); =20 if (virTimeStringNowRaw(ret) < 0) { virReportSystemError(errno, "%s", @@ -286,8 +285,7 @@ char *virTimeStringThen(unsigned long long when) { char *ret; =20 - if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) - return NULL; + ret =3D g_new0(char, VIR_TIME_STRING_BUFLEN); =20 if (virTimeStringThenRaw(when, ret) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index e4e50d837a..43af4a7c56 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -68,8 +68,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int n= params, ...) =20 va_start(ap, nparams); =20 - if (VIR_ALLOC_N(sorted, nparams) < 0) - goto cleanup; + sorted =3D g_new0(virTypedParameter, nparams); =20 /* Here we intentionally don't copy values */ memcpy(sorted, params, sizeof(*params) * nparams); @@ -361,8 +360,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst, if (!src || nparams <=3D 0) return 0; =20 - if (VIR_ALLOC_N(*dst, nparams) < 0) - return -1; + *dst =3D g_new0(virTypedParameter, nparams); =20 for (i =3D 0; i < nparams; i++) { ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field)); @@ -399,8 +397,7 @@ virTypedParamsFilter(virTypedParameterPtr params, { size_t i, n =3D 0; =20 - if (VIR_ALLOC_N(*ret, nparams) < 0) - return -1; + *ret =3D g_new0(virTypedParameterPtr, nparams); =20 for (i =3D 0; i < nparams; i++) { if (STREQ(params[i].field, name)) { @@ -447,9 +444,8 @@ virTypedParamsGetStringList(virTypedParameterPtr params, if (nfiltered < 0) goto error; =20 - if (nfiltered && - VIR_ALLOC_N(*values, nfiltered) < 0) - goto error; + if (nfiltered) + *values =3D g_new0(const char *, nfiltered); =20 for (n =3D 0, i =3D 0; i < nfiltered; i++) { if (filtered[i]->type =3D=3D VIR_TYPED_PARAM_STRING) @@ -551,8 +547,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr re= mote_params, goto cleanup; } } else { - if (VIR_ALLOC_N(*params, remote_params_len) < 0) - goto cleanup; + *params =3D g_new0(virTypedParameter, remote_params_len); } *nparams =3D remote_params_len; =20 @@ -662,8 +657,7 @@ virTypedParamsSerialize(virTypedParameterPtr params, goto cleanup; } =20 - if (VIR_ALLOC_N(params_val, nparams) < 0) - goto cleanup; + params_val =3D g_new0(struct _virTypedParameterRemote, nparams); =20 for (i =3D 0, j =3D 0; i < nparams; ++i) { virTypedParameterPtr param =3D params + i; diff --git a/src/util/viruri.c b/src/util/viruri.c index dd7559662b..11753a0aef 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -157,8 +157,7 @@ virURIParse(const char *uri) return NULL; } =20 - if (VIR_ALLOC(ret) < 0) - goto error; + ret =3D g_new0(virURI, 1); =20 ret->scheme =3D g_strdup(xmluri->scheme); ret->server =3D g_strdup(xmluri->server); diff --git a/src/util/virusb.c b/src/util/virusb.c index a28604c3f4..3e7e4281a3 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -312,8 +312,7 @@ virUSBDeviceNew(unsigned int bus, { virUSBDevicePtr dev; =20 - if (VIR_ALLOC(dev) < 0) - return NULL; + dev =3D g_new0(virUSBDevice, 1); =20 dev->bus =3D bus; dev->dev =3D devno; diff --git a/src/util/virutil.c b/src/util/virutil.c index 48b38c705b..708c3cf9ef 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -447,8 +447,7 @@ char *virIndexToDiskName(int idx, const char *prefix) =20 offset =3D strlen(prefix); =20 - if (VIR_ALLOC_N(name, offset + i + 1)) - return NULL; + name =3D g_new0(char, offset + i + 1); =20 strcpy(name, prefix); name[offset + i] =3D '\0'; @@ -618,8 +617,7 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, cha= r **dir, char **shell, bo if (val < 0) strbuflen =3D 1024; =20 - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) - return -1; + strbuf =3D g_new0(char, strbuflen); =20 /* * From the manpage (terrifying but true): @@ -688,8 +686,7 @@ static char *virGetGroupEnt(gid_t gid) if (val < 0) strbuflen =3D 1024; =20 - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) - return NULL; + strbuf =3D g_new0(char, strbuflen); =20 /* * From the manpage (terrifying but true): @@ -774,8 +771,7 @@ virGetUserIDByName(const char *name, uid_t *uid, bool m= issing_ok) if (val < 0) strbuflen =3D 1024; =20 - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) - goto cleanup; + strbuf =3D g_new0(char, strbuflen); =20 while ((rc =3D getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) =3D= =3D 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 =3D 1024; =20 - if (VIR_ALLOC_N(strbuf, strbuflen) < 0) - goto cleanup; + strbuf =3D g_new0(char, strbuflen); =20 while ((rc =3D getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) =3D= =3D ERANGE) { if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) diff --git a/src/util/virxml.c b/src/util/virxml.c index 1927ff490f..b4d6684560 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -672,9 +672,7 @@ virXPathNodeSet(const char *xpath, =20 ret =3D obj->nodesetval->nodeNr; if (list !=3D NULL && ret) { - if (VIR_ALLOC_N(*list, ret) < 0) - return -1; - + *list =3D g_new0(xmlNodePtr, ret); memcpy(*list, obj->nodesetval->nodeTab, ret * sizeof(xmlNodePtr)); } xmlXPathFreeObject(obj); @@ -1237,8 +1235,7 @@ virXMLValidatorInit(const char *schemafile) { virXMLValidatorPtr validator =3D NULL; =20 - if (VIR_ALLOC(validator) < 0) - return NULL; + validator =3D g_new0(virXMLValidator, 1); =20 validator->schemafile =3D g_strdup(schemafile); =20 --=20 2.26.2