From nobody Sat Feb 7 23:11:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1601920137; cv=none; d=zohomail.com; s=zohoarc; b=HUYZSqot/r0oeRerYM2Urew0A7p+ZpKUK7qFVjqLp9nNKw9tBjg7SzkXg0yPb2qrz/wrkcqdkSqCRiI0o3FC0jNBefGJnHk1dNmZkGisHIq3TPvfYAo0l7cSijYBV14xuyN6BjYWjBO/vjBqkvHl7oRPzlvuIiYMGybFAwrxQpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601920137; 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=x6LpRuPI13I0yCjBYoj/3lYBrb4xiESdfqha/MHXMaM=; b=CqDjz1AG/K1eqT8B5Ldbei1WdG45fm3Zl9KrZ8YK3b6xSz79hlCKkQsGZYiRKr1WTrxjp93ZjOEHunDCss4IpMYmY7z+OfUQUkrOZbDeXAQtXc96YPiPz6K7Cq81DrQWEeBGRVHY1EIJLEBN/INHtZvMeQnQWmvn1Sr4JFRcprk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601920137452268.7610554339034; Mon, 5 Oct 2020 10:48:57 -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-251-26kRMbV6O6ec0aCWd7gQng-1; Mon, 05 Oct 2020 13:48:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 687D8803F49; Mon, 5 Oct 2020 17:48:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43E321002C11; Mon, 5 Oct 2020 17:48:45 +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 11E9B44A6E; Mon, 5 Oct 2020 17:48:45 +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 095HmbgH015603 for ; Mon, 5 Oct 2020 13:48:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 07EB45C230; Mon, 5 Oct 2020 17:48:37 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83B545C225 for ; Mon, 5 Oct 2020 17:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601920134; 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=x6LpRuPI13I0yCjBYoj/3lYBrb4xiESdfqha/MHXMaM=; b=YalL1/ih5beKgEg9kNGIagT6yKPa/gK2/ryGsrc2Rw4lqwc0ov7lBEWxOIY9RMJlNb31ru BCRtVc+6M88HGPc+v5tgynnTjsnh+dk4vLvk9+FwmWZgMKEWghkvLBC2TIMrBcmC9SB5J6 sXyrDT50W6k4v3LomynEoBZdDGajAho= X-MC-Unique: 26kRMbV6O6ec0aCWd7gQng-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 04/12] util: storagefile: use g_new0 Date: Mon, 5 Oct 2020 19:48:19 +0200 Message-Id: <6fa49906dbd515bca5ef9affedaafd4ce92647f0.1601920046.git.jtomko@redhat.com> 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.84 on 10.5.11.22 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/virstoragefile.c | 82 ++++++++++++--------------------------- 1 file changed, 25 insertions(+), 57 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 459a7be5e4..82388ae544 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -520,8 +520,7 @@ qcow2GetExtensions(const char *buf, if (!backingFormat) break; =20 - if (VIR_ALLOC_N(tmp, len + 1) < 0) - return -1; + tmp =3D g_new0(char, len + 1); memcpy(tmp, buf + offset, len); tmp[len] =3D '\0'; =20 @@ -575,8 +574,7 @@ qcowXGetBackingStore(char **res, return BACKING_STORE_INVALID; if (offset + size > buf_size || offset + size < offset) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) - return BACKING_STORE_ERROR; + *res =3D g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] =3D '\0'; =20 @@ -598,8 +596,7 @@ vmdk4GetBackingStore(char **res, size_t len; g_autofree char *desc =3D NULL; =20 - if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0) - return BACKING_STORE_ERROR; + desc =3D g_new0(char, VIR_STORAGE_MAX_HEADER); =20 *res =3D NULL; /* @@ -669,8 +666,7 @@ qedGetBackingStore(char **res, return BACKING_STORE_OK; if (offset + size > buf_size || offset + size < offset) return BACKING_STORE_INVALID; - if (VIR_ALLOC_N(*res, size + 1) < 0) - return BACKING_STORE_ERROR; + *res =3D g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] =3D '\0'; =20 @@ -959,9 +955,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr m= eta, buf, len)) { int expt_fmt =3D fileTypeInfo[meta->format].cryptInfo[i].f= ormat; if (!meta->encryption) { - if (VIR_ALLOC(meta->encryption) < 0) - return -1; - + meta->encryption =3D g_new0(virStorageEncryption, 1); meta->encryption->format =3D expt_fmt; } else { if (meta->encryption->format !=3D expt_fmt) { @@ -1735,8 +1729,7 @@ virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefPtr ret =3D NULL; size_t i; =20 - if (VIR_ALLOC_N(ret, nhosts) < 0) - goto error; + ret =3D g_new0(virStorageNetHostDef, nhosts); =20 for (i =3D 0; i < nhosts; i++) { virStorageNetHostDefPtr src =3D &hosts[i]; @@ -1750,10 +1743,6 @@ virStorageNetHostDefCopy(size_t nhosts, } =20 return ret; - - error: - virStorageNetHostDefFree(nhosts, ret); - return NULL; } =20 =20 @@ -1775,8 +1764,7 @@ virStorageAuthDefCopy(const virStorageAuthDef *src) { g_autoptr(virStorageAuthDef) authdef =3D NULL; =20 - if (VIR_ALLOC(authdef) < 0) - return NULL; + authdef =3D g_new0(virStorageAuthDef, 1); =20 authdef->username =3D g_strdup(src->username); /* Not present for storage pool, but used for disk source */ @@ -1801,8 +1789,7 @@ virStorageAuthDefParse(xmlNodePtr node, =20 ctxt->node =3D node; =20 - if (VIR_ALLOC(authdef) < 0) - goto cleanup; + authdef =3D g_new0(virStorageAuthDef, 1); =20 if (!(authdef->username =3D virXPathString("string(./@username)", ctxt= ))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1891,8 +1878,7 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) g_autofree char *path =3D NULL; g_autofree char *mode =3D NULL; =20 - if (VIR_ALLOC(prd) < 0) - return NULL; + prd =3D g_new0(virStoragePRDef, 1); =20 if (!(managed =3D virXPathString("string(./@managed)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -2020,8 +2006,7 @@ virStoragePRDefCopy(virStoragePRDefPtr src) virStoragePRDefPtr copy =3D NULL; virStoragePRDefPtr ret =3D NULL; =20 - if (VIR_ALLOC(copy) < 0) - return NULL; + copy =3D g_new0(virStoragePRDef, 1); =20 copy->managed =3D src->managed; =20 @@ -2129,8 +2114,7 @@ virStorageSourceSeclabelsCopy(virStorageSourcePtr to, if (from->nseclabels =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(to->seclabels, from->nseclabels) < 0) - return -1; + to->seclabels =3D g_new0(virSecurityDeviceLabelDefPtr, from->nseclabel= s); to->nseclabels =3D from->nseclabels; =20 for (i =3D 0; i < to->nseclabels; i++) { @@ -2280,8 +2264,7 @@ virStorageTimestampsCopy(const virStorageTimestamps *= src) { virStorageTimestampsPtr ret; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virStorageTimestamps, 1); =20 memcpy(ret, src, sizeof(*src)); =20 @@ -2294,8 +2277,7 @@ virStoragePermsCopy(const virStoragePerms *src) { virStoragePermsPtr ret; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virStoragePerms, 1); =20 ret->mode =3D src->mode; ret->uid =3D src->uid; @@ -2312,8 +2294,7 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoo= lDef *src) { virStorageSourcePoolDefPtr ret; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virStorageSourcePoolDef, 1); =20 ret->voltype =3D src->voltype; ret->pooltype =3D src->pooltype; @@ -2806,9 +2787,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, return -1; } =20 - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (!(scheme =3D virStringSplit(uri->scheme, "+", 2))) @@ -3001,8 +2980,8 @@ virStorageSourceParseRBDColonString(const char *rbdst= r, _("duplicate 'id' found in '%s'"), src->pat= h); return -1; } - if (VIR_ALLOC(authdef) < 0) - return -1; + + authdef =3D g_new0(virStorageAuthDef, 1); =20 authdef->username =3D g_strdup(p + strlen("id=3D")); =20 @@ -3475,8 +3454,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSou= rcePtr src, return -1; } =20 - if (VIR_ALLOC_N(src->hosts, nservers) < 0) - return -1; + src->hosts =3D g_new0(virStorageNetHostDef, nservers); src->nhosts =3D nservers; =20 for (i =3D 0; i < nservers; i++) { @@ -3513,9 +3491,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourc= ePtr src, if (!lun) lun =3D "0"; =20 - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (STRNEQ_NULLABLE(transport, "tcp")) { @@ -3583,8 +3559,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourceP= tr src, =20 src->path =3D g_strdup(export); =20 - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (server) { @@ -3639,9 +3614,7 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSo= urcePtr src, =20 src->path =3D g_strdup(vdi); =20 - if (VIR_ALLOC(src->hosts) < 0) - return -1; - + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) = < 0) @@ -3676,8 +3649,7 @@ virStorageSourceParseBackingJSONSSH(virStorageSourceP= tr src, =20 src->path =3D g_strdup(path); =20 - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (server) { @@ -3738,9 +3710,7 @@ virStorageSourceParseBackingJSONRBD(virStorageSourceP= tr src, if (servers) { nservers =3D virJSONValueArraySize(servers); =20 - if (VIR_ALLOC_N(src->hosts, nservers) < 0) - return -1; - + src->hosts =3D g_new0(virStorageNetHostDef, nservers); src->nhosts =3D nservers; =20 for (i =3D 0; i < nservers; i++) { @@ -3814,8 +3784,7 @@ virStorageSourceParseBackingJSONVxHS(virStorageSource= Ptr src, =20 src->path =3D g_strdup(vdisk_id); =20 - if (VIR_ALLOC_N(src->hosts, 1) < 0) - return -1; + src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; =20 if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, @@ -4887,8 +4856,7 @@ virStorageFileInitAs(virStorageSourcePtr src, uid_t uid, gid_t gid) { int actualType =3D virStorageSourceGetActualType(src); - if (VIR_ALLOC(src->drv) < 0) - return -1; + src->drv =3D g_new0(virStorageDriverData, 1); =20 if (uid =3D=3D (uid_t) -1) src->drv->uid =3D geteuid(); --=20 2.26.2