From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480273439196.7537798223401; Fri, 5 Apr 2019 09:04:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7E6030DDBA5; Fri, 5 Apr 2019 16:04:31 +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 5B92E61370; Fri, 5 Apr 2019 16:04:31 +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 A87BC3FB11; Fri, 5 Apr 2019 16:04:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4T1c003379 for ; Fri, 5 Apr 2019 12:04:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6BDEC610A0; Fri, 5 Apr 2019 16:04:29 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E83CB60CAD for ; Fri, 5 Apr 2019 16:04:28 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:13 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/11] qemu: block: Introduce and use AUTOPTR func for qemuBlockStorageSourceAttachDataPtr 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 05 Apr 2019 16:04:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 3 +-- src/qemu/qemu_block.h | 3 +++ src/qemu/qemu_command.c | 14 +++++++------- src/qemu/qemu_hotplug.c | 9 +++------ src/qemu/qemu_migration.c | 3 +-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index cbf0aa4189..7961d31978 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1543,7 +1543,7 @@ qemuBlockStorageSourceAttachDataFree(qemuBlockStorage= SourceAttachDataPtr data) qemuBlockStorageSourceAttachDataPtr qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src) { - qemuBlockStorageSourceAttachDataPtr data; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data =3D NULL; qemuBlockStorageSourceAttachDataPtr ret =3D NULL; if (VIR_ALLOC(data) < 0) @@ -1559,7 +1559,6 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorag= eSourcePtr src) VIR_STEAL_PTR(ret, data); cleanup: - qemuBlockStorageSourceAttachDataFree(data); return ret; } diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 9401ab4e12..eab8da8e2c 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -102,6 +102,9 @@ struct qemuBlockStorageSourceAttachData { void qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr d= ata); +VIR_DEFINE_AUTOPTR_FUNC(qemuBlockStorageSourceAttachData, + qemuBlockStorageSourceAttachDataFree); + qemuBlockStorageSourceAttachDataPtr qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 029780fe86..7d439550f3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2554,7 +2554,7 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd, { qemuBlockStorageSourceAttachDataPtr *data =3D NULL; size_t ndata =3D 0; - qemuBlockStorageSourceAttachDataPtr tmp =3D NULL; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) tmp =3D NULL; virJSONValuePtr copyOnReadProps =3D NULL; virStorageSourcePtr n; char *str =3D NULL; @@ -2613,7 +2613,6 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd, for (i =3D 0; i < ndata; i++) qemuBlockStorageSourceAttachDataFree(data[i]); VIR_FREE(data); - qemuBlockStorageSourceAttachDataFree(tmp); virJSONValueFree(copyOnReadProps); VIR_FREE(str); return ret; @@ -11160,18 +11159,19 @@ qemuBlockStorageSourceAttachDataPtr qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, virQEMUCapsPtr qemuCaps) { - qemuBlockStorageSourceAttachDataPtr data =3D NULL; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data =3D NULL; + qemuBlockStorageSourceAttachDataPtr ret =3D NULL; if (VIR_ALLOC(data) < 0) return NULL; if (!(data->driveCmd =3D qemuBuildDriveStr(disk, qemuCaps)) || - !(data->driveAlias =3D qemuAliasDiskDriveFromDisk(disk))) { - qemuBlockStorageSourceAttachDataFree(data); + !(data->driveAlias =3D qemuAliasDiskDriveFromDisk(disk))) return NULL; - } - return data; + VIR_STEAL_PTR(ret, data); + + return ret; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 34249bd030..90c6a108dc 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -530,7 +530,7 @@ qemuHotplugRemoveStorageSourcePrepareData(virStorageSou= rcePtr src, { qemuDomainStorageSourcePrivatePtr srcpriv =3D QEMU_DOMAIN_STORAGE_SOUR= CE_PRIVATE(src); - qemuBlockStorageSourceAttachDataPtr data; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data =3D NULL; qemuBlockStorageSourceAttachDataPtr ret =3D NULL; if (VIR_ALLOC(data) < 0) @@ -570,7 +570,6 @@ qemuHotplugRemoveStorageSourcePrepareData(virStorageSou= rcePtr src, cleanup: VIR_FREE(driveAlias); - qemuBlockStorageSourceAttachDataFree(data); return ret; } @@ -581,7 +580,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr = disk, virQEMUCapsPtr qemuCaps) { qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - qemuBlockStorageSourceAttachDataPtr backend =3D NULL; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) backend =3D NULL; qemuHotplugDiskSourceDataPtr data =3D NULL; qemuHotplugDiskSourceDataPtr ret =3D NULL; char *drivealias =3D NULL; @@ -616,7 +615,6 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr = disk, VIR_STEAL_PTR(ret, data); cleanup: - qemuBlockStorageSourceAttachDataFree(backend); qemuHotplugDiskSourceDataFree(data); return ret; } @@ -636,7 +634,7 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr = disk, virStorageSourcePtr src, virQEMUCapsPtr qemuCaps) { - qemuBlockStorageSourceAttachDataPtr backend =3D NULL; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) backend =3D NULL; qemuHotplugDiskSourceDataPtr data; qemuHotplugDiskSourceDataPtr ret =3D NULL; virStorageSourcePtr savesrc =3D NULL; @@ -682,7 +680,6 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr = disk, if (savesrc) VIR_STEAL_PTR(disk->src, savesrc); - qemuBlockStorageSourceAttachDataFree(backend); qemuHotplugDiskSourceDataFree(data); return ret; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 5db23b492f..a8d50d310d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -787,7 +787,7 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, unsigned int mirror_flags, const char *tlsAlias) { - qemuBlockStorageSourceAttachDataPtr data =3D NULL; + VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data =3D NULL; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); int mon_ret =3D 0; int ret =3D -1; @@ -849,7 +849,6 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr= driver, ret =3D 0; cleanup: - qemuBlockStorageSourceAttachDataFree(data); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480280630966.6118792697393; Fri, 5 Apr 2019 09:04:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04461307E040; Fri, 5 Apr 2019 16:04:38 +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 CC8DB26DDE; Fri, 5 Apr 2019 16:04:37 +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 8ABE9181AC48; Fri, 5 Apr 2019 16:04:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4UEN003384 for ; Fri, 5 Apr 2019 12:04:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FAE060C8D; Fri, 5 Apr 2019 16:04:30 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B936B60C7A for ; Fri, 5 Apr 2019 16:04:29 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:14 +0200 Message-Id: <9c014ed2d7f372ab2d23b931afda780189019028.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/11] qemu: block: Use VIR_AUTOPTR for virJSONValue 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 05 Apr 2019 16:04:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 80 ++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 7961d31978..769e07d3d8 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -345,8 +345,8 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; virHashTablePtr disktable =3D NULL; - virJSONValuePtr data =3D NULL; - virJSONValuePtr blockstats =3D NULL; + VIR_AUTOPTR(virJSONValue) data =3D NULL; + VIR_AUTOPTR(virJSONValue) blockstats =3D NULL; virDomainDiskDefPtr disk; size_t i; int ret =3D -1; @@ -376,8 +376,6 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, ret =3D 0; cleanup: - virJSONValueFree(data); - virJSONValueFree(blockstats); virHashFree(disktable); return ret; @@ -504,7 +502,7 @@ static virJSONValuePtr qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, bool legacy) { - virJSONValuePtr server =3D NULL; + VIR_AUTOPTR(virJSONValue) server =3D NULL; virJSONValuePtr ret =3D NULL; const char *transport; const char *field; @@ -553,7 +551,6 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, cleanup: VIR_FREE(port); - virJSONValueFree(server); return ret; } @@ -571,8 +568,8 @@ static virJSONValuePtr qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src, bool legacy) { - virJSONValuePtr servers =3D NULL; - virJSONValuePtr server =3D NULL; + VIR_AUTOPTR(virJSONValue) servers =3D NULL; + VIR_AUTOPTR(virJSONValue) server =3D NULL; virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; size_t i; @@ -595,8 +592,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, VIR_STEAL_PTR(ret, servers); cleanup: - virJSONValueFree(servers); - virJSONValueFree(server); return ret; } @@ -646,8 +641,8 @@ qemuBlockStorageSourceBuildJSONInetSocketAddress(virSto= rageNetHostDefPtr host) static virJSONValuePtr qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr = src) { - virJSONValuePtr servers =3D NULL; - virJSONValuePtr server =3D NULL; + VIR_AUTOPTR(virJSONValue) servers =3D NULL; + VIR_AUTOPTR(virJSONValue) server =3D NULL; virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; size_t i; @@ -670,8 +665,6 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(v= irStorageSourcePtr src) VIR_STEAL_PTR(ret, servers); cleanup: - virJSONValueFree(servers); - virJSONValueFree(server); return ret; } @@ -681,8 +674,8 @@ static virJSONValuePtr qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src, bool legacy) { - virJSONValuePtr servers =3D NULL; - virJSONValuePtr props =3D NULL; + VIR_AUTOPTR(virJSONValue) servers =3D NULL; + VIR_AUTOPTR(virJSONValue) props =3D NULL; virJSONValuePtr ret =3D NULL; if (!(servers =3D qemuBlockStorageSourceBuildHostsJSONSocketAddress(sr= c, legacy))) @@ -708,8 +701,6 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourceP= tr src, VIR_STEAL_PTR(ret, props); cleanup: - virJSONValueFree(servers); - virJSONValueFree(props); return ret; } @@ -719,7 +710,7 @@ static virJSONValuePtr qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) { const char *protocol =3D virStorageNetProtocolTypeToString(src->protoc= ol); - virJSONValuePtr server =3D NULL; + VIR_AUTOPTR(virJSONValue) server =3D NULL; virJSONValuePtr ret =3D NULL; if (src->nhosts !=3D 1) { @@ -737,12 +728,11 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePt= r src) * vdisk-id:"eb90327c-8302-4725-4e85ed4dc251", * server:{type:"tcp", host:"1.2.3.4", port:9999}} */ - if (virJSONValueObjectCreate(&ret, - "s:driver", protocol, - "S:tls-creds", src->tlsAlias, - "s:vdisk-id", src->path, - "a:server", &server, NULL) < 0) - virJSONValueFree(server); + ignore_value(virJSONValueObjectCreate(&ret, + "s:driver", protocol, + "S:tls-creds", src->tlsAlias, + "s:vdisk-id", src->path, + "a:server", &server, NULL)); return ret; } @@ -875,7 +865,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr= src) static virJSONValuePtr qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src) { - virJSONValuePtr serverprops; + VIR_AUTOPTR(virJSONValue) serverprops =3D NULL; virJSONValuePtr ret =3D NULL; if (src->nhosts !=3D 1) { @@ -898,7 +888,6 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr s= rc) goto cleanup; cleanup: - virJSONValueFree(serverprops); return ret; } @@ -907,11 +896,11 @@ static virJSONValuePtr qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src) { qemuDomainStorageSourcePrivatePtr srcPriv =3D QEMU_DOMAIN_STORAGE_SOUR= CE_PRIVATE(src); - virJSONValuePtr servers =3D NULL; + VIR_AUTOPTR(virJSONValue) servers =3D NULL; virJSONValuePtr ret =3D NULL; const char *username =3D NULL; - virJSONValuePtr authmodes =3D NULL; - virJSONValuePtr mode =3D NULL; + VIR_AUTOPTR(virJSONValue) authmodes =3D NULL; + VIR_AUTOPTR(virJSONValue) mode =3D NULL; const char *keysecret =3D NULL; if (src->nhosts > 0 && @@ -952,9 +941,6 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr s= rc) goto cleanup; cleanup: - virJSONValueFree(authmodes); - virJSONValueFree(mode); - virJSONValueFree(servers); return ret; } @@ -962,7 +948,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr s= rc) static virJSONValuePtr qemuBlockStorageSourceGetSheepdogProps(virStorageSourcePtr src) { - virJSONValuePtr serverprops; + VIR_AUTOPTR(virJSONValue) serverprops =3D NULL; virJSONValuePtr ret =3D NULL; if (src->nhosts !=3D 1) { @@ -985,7 +971,6 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSource= Ptr src) goto cleanup; cleanup: - virJSONValueFree(serverprops); return ret; } @@ -993,7 +978,7 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSource= Ptr src) static virJSONValuePtr qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src) { - virJSONValuePtr serverprops; + VIR_AUTOPTR(virJSONValue) serverprops =3D NULL; virJSONValuePtr ret =3D NULL; const char *username =3D NULL; @@ -1019,7 +1004,6 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr= src) goto cleanup; cleanup: - virJSONValueFree(serverprops); return ret; } @@ -1078,7 +1062,7 @@ static int qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src, virJSONValuePtr props) { - virJSONValuePtr cacheobj; + VIR_AUTOPTR(virJSONValue) cacheobj =3D NULL; bool direct =3D false; bool noflush =3D false; @@ -1094,10 +1078,9 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virSt= orageSourcePtr src, NULL) < 0) return -1; - if (virJSONValueObjectAppend(props, "cache", cacheobj) < 0) { - virJSONValueFree(cacheobj); + if (virJSONValueObjectAppend(props, "cache", cacheobj) < 0) return -1; - } + cacheobj =3D NULL; return 0; } @@ -1116,7 +1099,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= ePtr src, bool legacy) { int actualType =3D virStorageSourceGetActualType(src); - virJSONValuePtr fileprops =3D NULL; + VIR_AUTOPTR(virJSONValue) fileprops =3D NULL; virJSONValuePtr ret =3D NULL; switch ((virStorageType)actualType) { @@ -1209,7 +1192,6 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= ePtr src, VIR_STEAL_PTR(ret, fileprops); cleanup: - virJSONValueFree(fileprops); return ret; } @@ -1292,7 +1274,7 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virSt= orageSourcePtr src, const char *format, virJSONValuePtr props) { - virJSONValuePtr encprops =3D NULL; + VIR_AUTOPTR(virJSONValue) encprops =3D NULL; int ret =3D -1; if (qemuBlockStorageSourceGetCryptoProps(src, &encprops) < 0) @@ -1306,7 +1288,6 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virSt= orageSourcePtr src, ret =3D 0; cleanup: - virJSONValueFree(encprops); return ret; } @@ -1342,7 +1323,7 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(vi= rStorageSourcePtr src) const char *discard =3D NULL; int detectZeroesMode =3D virDomainDiskGetDetectZeroesMode(src->discard, src->detect_ze= roes); - virJSONValuePtr props =3D NULL; + VIR_AUTOPTR(virJSONValue) props =3D NULL; virJSONValuePtr ret =3D NULL; if (qemuBlockNodeNameValidate(src->nodeformat) < 0) @@ -1372,7 +1353,6 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(vi= rStorageSourcePtr src) VIR_STEAL_PTR(ret, props); cleanup: - virJSONValueFree(props); return ret; } @@ -1381,7 +1361,7 @@ static virJSONValuePtr qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src) { const char *driver =3D NULL; - virJSONValuePtr props =3D NULL; + VIR_AUTOPTR(virJSONValue) props =3D NULL; virJSONValuePtr ret =3D NULL; if (!(props =3D qemuBlockStorageSourceGetBlockdevFormatCommonProps(src= ))) @@ -1449,7 +1429,6 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSourcePtr src) VIR_STEAL_PTR(ret, props); cleanup: - virJSONValueFree(props); return ret; } @@ -1468,7 +1447,7 @@ virJSONValuePtr qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src) { bool backingSupported =3D src->format >=3D VIR_STORAGE_FILE_BACKING; - virJSONValuePtr props =3D NULL; + VIR_AUTOPTR(virJSONValue) props =3D NULL; virJSONValuePtr ret =3D NULL; if (virStorageSourceHasBacking(src) && !backingSupported) { @@ -1500,7 +1479,6 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSour= cePtr src) VIR_STEAL_PTR(ret, props); cleanup: - virJSONValueFree(props); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480280608579.268601035669; Fri, 5 Apr 2019 09:04:40 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0813E300602F; Fri, 5 Apr 2019 16:04:38 +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 D39EB5F9A6; Fri, 5 Apr 2019 16:04:37 +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 8DFE93FB14; Fri, 5 Apr 2019 16:04:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4WJM003402 for ; Fri, 5 Apr 2019 12:04:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9DD7260CBA; Fri, 5 Apr 2019 16:04:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F8060CAD for ; Fri, 5 Apr 2019 16:04:30 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:15 +0200 Message-Id: <27dcdc5daa927bcf3d9e816f20530e81a6bcb4ce.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/11] util: uri: Introduce VIR_AUTOPTR freeing function 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 05 Apr 2019 16:04:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/viruri.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/viruri.h b/src/util/viruri.h index b6e97dafe6..f5b472860e 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -25,6 +25,7 @@ # include "internal.h" # include "virconf.h" +# include "virautoclean.h" typedef struct _virURI virURI; typedef virURI *virURIPtr; @@ -60,6 +61,7 @@ char *virURIFormat(virURIPtr uri) char *virURIFormatParams(virURIPtr uri); void virURIFree(virURIPtr uri); +VIR_DEFINE_AUTOPTR_FUNC(virURI, virURIFree); int virURIResolveAlias(virConfPtr conf, const char *alias, char **uri); # define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "lo= calhost") --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480283530971.0684269324511; Fri, 5 Apr 2019 09:04:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 961DE3001C7E; Fri, 5 Apr 2019 16:04:41 +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 693FC60C1B; Fri, 5 Apr 2019 16:04:41 +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 1F9AF3FAF4; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4Xin003409 for ; Fri, 5 Apr 2019 12:04:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6BAC360CAD; Fri, 5 Apr 2019 16:04:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E982B60C8D for ; Fri, 5 Apr 2019 16:04:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:16 +0200 Message-Id: <60cf25e083476ab8f4a7357a92906005ea3f3a28.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/11] qemu: block: Use VIR_AUTOPTR for virURIPtr 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 05 Apr 2019 16:04:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 769e07d3d8..0504a79957 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -435,7 +435,7 @@ qemuBlockStorageSourceSupportsConcurrentAccess(virStora= geSourcePtr src) virURIPtr qemuBlockStorageSourceGetURI(virStorageSourcePtr src) { - virURIPtr uri =3D NULL; + VIR_AUTOPTR(virURI) uri =3D NULL; virURIPtr ret =3D NULL; if (src->nhosts !=3D 1) { @@ -480,7 +480,6 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) VIR_STEAL_PTR(ret, uri); cleanup: - virURIFree(uri); return ret; } @@ -745,7 +744,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr = src) const char *passwordalias =3D NULL; const char *username =3D NULL; virJSONValuePtr ret =3D NULL; - virURIPtr uri =3D NULL; + VIR_AUTOPTR(virURI) uri =3D NULL; char *uristr =3D NULL; const char *driver; @@ -782,7 +781,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr = src) NULL)); cleanup: - virURIFree(uri); VIR_FREE(uristr); return ret; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480277889953.9866027868699; Fri, 5 Apr 2019 09:04:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1747888AC2; Fri, 5 Apr 2019 16:04:36 +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 DC97E60D62; Fri, 5 Apr 2019 16:04:35 +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 986B6181AC46; Fri, 5 Apr 2019 16:04:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4Y3v003419 for ; Fri, 5 Apr 2019 12:04:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3BAFF60C8D; Fri, 5 Apr 2019 16:04:34 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9A7A60BFB for ; Fri, 5 Apr 2019 16:04:33 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:17 +0200 Message-Id: <99e5398666012b4a32801fad30e0868bf2f34b8a.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/11] qemu: block: Use VIR_AUTOPTR for virHashTablePtr 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 Apr 2019 16:04:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 0504a79957..b00f4c6f8e 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -240,8 +240,8 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namedn= odes, virJSONValuePtr blockstats) { struct qemuBlockNodeNameGetBackingChainData data; - virHashTablePtr namednodestable =3D NULL; - virHashTablePtr disks =3D NULL; + VIR_AUTOPTR(virHashTable) namednodestable =3D NULL; + VIR_AUTOPTR(virHashTable) disks =3D NULL; virHashTablePtr ret =3D NULL; memset(&data, 0, sizeof(data)); @@ -268,8 +268,6 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namedn= odes, VIR_STEAL_PTR(ret, disks); cleanup: - virHashFree(namednodestable); - virHashFree(disks); return ret; } @@ -344,7 +342,7 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, qemuDomainAsyncJob asyncJob) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - virHashTablePtr disktable =3D NULL; + VIR_AUTOPTR(virHashTable) disktable =3D NULL; VIR_AUTOPTR(virJSONValue) data =3D NULL; VIR_AUTOPTR(virJSONValue) blockstats =3D NULL; virDomainDiskDefPtr disk; @@ -376,7 +374,6 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, ret =3D 0; cleanup: - virHashFree(disktable); return ret; } @@ -394,19 +391,20 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, virHashTablePtr qemuBlockGetNodeData(virJSONValuePtr data) { + VIR_AUTOPTR(virHashTable) nodedata =3D NULL; virHashTablePtr ret =3D NULL; - if (!(ret =3D virHashCreate(50, virJSONValueHashFree))) + if (!(nodedata =3D virHashCreate(50, virJSONValueHashFree))) return NULL; if (virJSONValueArrayForeachSteal(data, - qemuBlockNamedNodesArrayToHash, ret)= < 0) + qemuBlockNamedNodesArrayToHash, node= data) < 0) goto error; + VIR_STEAL_PTR(ret, nodedata); return ret; error: - virHashFree(ret); return NULL; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155448028388814.008719248985244; Fri, 5 Apr 2019 09:04:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1535A59447; Fri, 5 Apr 2019 16:04:42 +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 97DA05D71E; Fri, 5 Apr 2019 16:04:41 +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 53AFE3FAF6; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4Zgn003425 for ; Fri, 5 Apr 2019 12:04:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C5FC60BFB; Fri, 5 Apr 2019 16:04:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89A9960C8D for ; Fri, 5 Apr 2019 16:04:34 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:18 +0200 Message-Id: <22e1bc2c4154c624ad10dc838af163cab9e37da3.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/11] qemu: block: Use VIR_AUTOFREE for char * 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 Apr 2019 16:04:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index b00f4c6f8e..822ba44e18 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -293,7 +293,7 @@ qemuBlockDiskDetectNodes(virDomainDiskDefPtr disk, { qemuBlockNodeNameBackingChainDataPtr entry =3D NULL; virStorageSourcePtr src =3D disk->src; - char *alias =3D NULL; + VIR_AUTOFREE(char *) alias =3D NULL; int ret =3D -1; /* don't attempt the detection if the top level already has node names= */ @@ -328,7 +328,6 @@ qemuBlockDiskDetectNodes(virDomainDiskDefPtr disk, ret =3D 0; cleanup: - VIR_FREE(alias); if (ret < 0) qemuBlockDiskClearDetectedNodes(disk); @@ -503,7 +502,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, virJSONValuePtr ret =3D NULL; const char *transport; const char *field; - char *port =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; switch ((virStorageNetHostTransport) host->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: @@ -547,7 +546,6 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, VIR_STEAL_PTR(ret, server); cleanup: - VIR_FREE(port); return ret; } @@ -607,7 +605,7 @@ static virJSONValuePtr qemuBlockStorageSourceBuildJSONInetSocketAddress(virStorageNetHostDefPtr h= ost) { virJSONValuePtr ret =3D NULL; - char *port =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; if (host->transport !=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -623,7 +621,6 @@ qemuBlockStorageSourceBuildJSONInetSocketAddress(virSto= rageNetHostDefPtr host) "s:port", port, NULL)); - VIR_FREE(port); return ret; } @@ -743,7 +740,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr = src) const char *username =3D NULL; virJSONValuePtr ret =3D NULL; VIR_AUTOPTR(virURI) uri =3D NULL; - char *uristr =3D NULL; + VIR_AUTOFREE(char *) uristr =3D NULL; const char *driver; /** @@ -779,7 +776,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr = src) NULL)); cleanup: - VIR_FREE(uristr); return ret; } @@ -790,11 +786,11 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourceP= tr src) { qemuDomainStorageSourcePrivatePtr srcPriv =3D QEMU_DOMAIN_STORAGE_SOUR= CE_PRIVATE(src); const char *protocol =3D virStorageNetProtocolTypeToString(src->protoc= ol); - char *target =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; char *lunStr =3D NULL; char *username =3D NULL; char *objalias =3D NULL; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; unsigned int lun =3D 0; virJSONValuePtr ret =3D NULL; @@ -852,8 +848,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr= src) goto cleanup; cleanup: - VIR_FREE(target); - VIR_FREE(portal); return ret; } @@ -1693,8 +1687,8 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, bool reuse) { const char *format =3D virStorageFileFormatTypeToString(newsrc->format= ); - char *device =3D NULL; - char *source =3D NULL; + VIR_AUTOFREE(char *) device =3D NULL; + VIR_AUTOFREE(char *) source =3D NULL; int ret =3D -1; if (!(device =3D qemuAliasDiskDriveFromDisk(disk))) @@ -1714,8 +1708,6 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, ret =3D 0; cleanup: - VIR_FREE(device); - VIR_FREE(source); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480287169350.6546583749372; Fri, 5 Apr 2019 09:04:47 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 346E0301F12C; Fri, 5 Apr 2019 16:04:45 +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 0FD7C10A3922; Fri, 5 Apr 2019 16:04: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 C97001819AFF; Fri, 5 Apr 2019 16:04:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4ZXZ003438 for ; Fri, 5 Apr 2019 12:04:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF7C260CD0; Fri, 5 Apr 2019 16:04:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58D6360BFB for ; Fri, 5 Apr 2019 16:04:35 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:19 +0200 Message-Id: <55f06927cbfe4806db5bbc047396807bfedfff4c.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/11] qemu: block: Add and use AUTOPTR func for qemuBlockNodeNameBackingChainData 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 05 Apr 2019 16:04:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This is a locally used helper struct but we can make use of automatic freeing for it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 822ba44e18..2017eca139 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -88,6 +88,9 @@ qemuBlockNodeNameBackingChainDataFree(qemuBlockNodeNameBa= ckingChainDataPtr data) VIR_FREE(data); } +VIR_DEFINE_AUTOPTR_FUNC(qemuBlockNodeNameBackingChainData, + qemuBlockNodeNameBackingChainDataFree); + static void qemuBlockNodeNameBackingChainDataHashEntryFree(void *opaque, @@ -128,7 +131,7 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr= next, virHashTablePtr nodenamestable, qemuBlockNodeNameBackingChainDataP= tr *nodenamedata) { - qemuBlockNodeNameBackingChainDataPtr data =3D NULL; + VIR_AUTOPTR(qemuBlockNodeNameBackingChainData) data =3D NULL; qemuBlockNodeNameBackingChainDataPtr backingdata =3D NULL; virJSONValuePtr backing =3D virJSONValueObjectGetObject(next, "backing= "); virJSONValuePtr parent =3D virJSONValueObjectGetObject(next, "parent"); @@ -189,7 +192,6 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr= next, ret =3D 0; cleanup: - qemuBlockNodeNameBackingChainDataFree(data); return ret; } @@ -201,7 +203,7 @@ qemuBlockNodeNameGetBackingChainDisk(size_t pos ATTRIBU= TE_UNUSED, { struct qemuBlockNodeNameGetBackingChainData *data =3D opaque; const char *device =3D virJSONValueObjectGetString(item, "device"); - qemuBlockNodeNameBackingChainDataPtr devicedata =3D NULL; + VIR_AUTOPTR(qemuBlockNodeNameBackingChainData) devicedata =3D NULL; int ret =3D -1; if (qemuBlockNodeNameGetBackingChainBacking(item, data->nodenamestable, @@ -216,7 +218,6 @@ qemuBlockNodeNameGetBackingChainDisk(size_t pos ATTRIBU= TE_UNUSED, ret =3D 1; /* we don't really want to steal @item */ cleanup: - qemuBlockNodeNameBackingChainDataFree(devicedata); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480291730555.141886031989; Fri, 5 Apr 2019 09:04:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9280119CBD5; Fri, 5 Apr 2019 16:04:49 +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 525E026547; Fri, 5 Apr 2019 16:04:49 +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 0092B181B9EC; Fri, 5 Apr 2019 16:04:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4cIo003455 for ; Fri, 5 Apr 2019 12:04:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90ED760CAD; Fri, 5 Apr 2019 16:04:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E73F960C8D for ; Fri, 5 Apr 2019 16:04:36 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:20 +0200 Message-Id: <6ff38833f386d1d9cd614fe325121de96a89a672.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/11] qemu: block: Remove unneeded cleanup jumps 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 05 Apr 2019 16:04:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 206 +++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 134 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 2017eca139..31800919a7 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -142,7 +142,6 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr= next, const char *drvparent =3D NULL; const char *parentnodename =3D NULL; const char *filename =3D NULL; - int ret =3D -1; if (!nodename) return 0; @@ -172,27 +171,24 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValueP= tr next, } if (VIR_ALLOC(data) < 0) - goto cleanup; + return -1; if (VIR_STRDUP(data->nodeformat, nodename) < 0 || VIR_STRDUP(data->nodestorage, parentnodename) < 0 || VIR_STRDUP(data->qemufilename, filename) < 0 || VIR_STRDUP(data->drvformat, drvname) < 0 || VIR_STRDUP(data->drvstorage, drvparent) < 0) - goto cleanup; + return -1; if (backing && qemuBlockNodeNameGetBackingChainBacking(backing, nodenamestable, &backingdata) < 0) - goto cleanup; + return -1; VIR_STEAL_PTR(data->backing, backingdata); VIR_STEAL_PTR(*nodenamedata, data); - ret =3D 0; - - cleanup: - return ret; + return 0; } @@ -204,22 +200,17 @@ qemuBlockNodeNameGetBackingChainDisk(size_t pos ATTRI= BUTE_UNUSED, struct qemuBlockNodeNameGetBackingChainData *data =3D opaque; const char *device =3D virJSONValueObjectGetString(item, "device"); VIR_AUTOPTR(qemuBlockNodeNameBackingChainData) devicedata =3D NULL; - int ret =3D -1; if (qemuBlockNodeNameGetBackingChainBacking(item, data->nodenamestable, &devicedata) < 0) - goto cleanup; + return -1; if (devicedata && virHashAddEntry(data->disks, device, devicedata) < 0) - goto cleanup; + return -1; devicedata =3D NULL; - ret =3D 1; /* we don't really want to steal @item */ - - cleanup: - - return ret; + return 1; /* we don't really want to steal @item */ } @@ -248,15 +239,15 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr name= dnodes, memset(&data, 0, sizeof(data)); if (!(namednodestable =3D virHashCreate(50, virJSONValueHashFree))) - goto cleanup; + return NULL; if (virJSONValueArrayForeachSteal(namednodes, qemuBlockNamedNodesArrayToHash, namednodestable) < 0) - goto cleanup; + return NULL; if (!(disks =3D virHashCreate(50, qemuBlockNodeNameBackingChainDataHas= hEntryFree))) - goto cleanup; + return NULL; data.nodenamestable =3D namednodestable; data.disks =3D disks; @@ -264,13 +255,10 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr name= dnodes, if (virJSONValueArrayForeachSteal(blockstats, qemuBlockNodeNameGetBackingChainDisk, &data) < 0) - goto cleanup; + return NULL; VIR_STEAL_PTR(ret, disks); - - cleanup: - - return ret; + return ret; } @@ -347,7 +335,6 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, VIR_AUTOPTR(virJSONValue) blockstats =3D NULL; virDomainDiskDefPtr disk; size_t i; - int ret =3D -1; if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_NAMED_BLOCK_NODES)) return 0; @@ -359,23 +346,19 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, blockstats =3D qemuMonitorQueryBlockstats(qemuDomainGetMonitor(vm)); if (qemuDomainObjExitMonitor(driver, vm) < 0 || !data || !blockstats) - goto cleanup; + return -1; if (!(disktable =3D qemuBlockNodeNameGetBackingChain(data, blockstats)= )) - goto cleanup; + return -1; for (i =3D 0; i < vm->def->ndisks; i++) { disk =3D vm->def->disks[i]; if (qemuBlockDiskDetectNodes(disk, disktable) < 0) - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - - return ret; + return 0; } @@ -399,13 +382,10 @@ qemuBlockGetNodeData(virJSONValuePtr data) if (virJSONValueArrayForeachSteal(data, qemuBlockNamedNodesArrayToHash, node= data) < 0) - goto error; + return NULL; VIR_STEAL_PTR(ret, nodedata); return ret; - - error: - return NULL; } @@ -440,44 +420,42 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) virReportError(VIR_ERR_INTERNAL_ERROR, _("protocol '%s' accepts only one host"), virStorageNetProtocolTypeToString(src->protocol)); - goto cleanup; + return NULL; } if (VIR_ALLOC(uri) < 0) - goto cleanup; + return NULL; if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { uri->port =3D src->hosts->port; if (VIR_STRDUP(uri->scheme, virStorageNetProtocolTypeToString(src->protocol)) <= 0) - goto cleanup; + return NULL; } else { if (virAsprintf(&uri->scheme, "%s+%s", virStorageNetProtocolTypeToString(src->protocol), virStorageNetHostTransportTypeToString(src->hosts-= >transport)) < 0) - goto cleanup; + return NULL; } if (src->path) { if (src->volume) { if (virAsprintf(&uri->path, "/%s/%s", src->volume, src->path) < 0) - goto cleanup; + return NULL; } else { if (virAsprintf(&uri->path, "%s%s", src->path[0] =3D=3D '/' ? "" : "/", src->path) < 0) - goto cleanup; + return NULL; } } if (VIR_STRDUP(uri->server, src->hosts->name) < 0) - goto cleanup; + return NULL; VIR_STEAL_PTR(ret, uri); - - cleanup: return ret; } @@ -513,14 +491,14 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStora= geNetHostDefPtr host, transport =3D "inet"; if (virAsprintf(&port, "%u", host->port) < 0) - goto cleanup; + return NULL; if (virJSONValueObjectCreate(&server, "s:type", transport, "s:host", host->name, "s:port", port, NULL) < 0) - goto cleanup; + return NULL; break; case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -533,7 +511,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, "s:type", "unix", field, host->socket, NULL) < 0) - goto cleanup; + return NULL; break; case VIR_STORAGE_NET_HOST_TRANS_RDMA: @@ -541,13 +519,10 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStora= geNetHostDefPtr host, virReportError(VIR_ERR_INTERNAL_ERROR, _("transport protocol '%s' is not yet supported"), virStorageNetHostTransportTypeToString(host->transp= ort)); - goto cleanup; + return NULL; } VIR_STEAL_PTR(ret, server); - - cleanup: - return ret; } @@ -571,24 +546,21 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(vir= StorageSourcePtr src, size_t i; if (!(servers =3D virJSONValueNewArray())) - goto cleanup; + return NULL; for (i =3D 0; i < src->nhosts; i++) { host =3D src->hosts + i; if (!(server =3D qemuBlockStorageSourceBuildJSONSocketAddress(host= , legacy))) - goto cleanup; + return NULL; if (virJSONValueArrayAppend(servers, server) < 0) - goto cleanup; + return NULL; server =3D NULL; } VIR_STEAL_PTR(ret, servers); - - cleanup: - return ret; } @@ -643,24 +615,21 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress= (virStorageSourcePtr src) size_t i; if (!(servers =3D virJSONValueNewArray())) - goto cleanup; + return NULL; for (i =3D 0; i < src->nhosts; i++) { host =3D src->hosts + i; if (!(server =3D qemuBlockStorageSourceBuildJSONInetSocketAddress(= host))) - goto cleanup; + return NULL; if (virJSONValueArrayAppend(servers, server) < 0) - goto cleanup; + return NULL; server =3D NULL; } VIR_STEAL_PTR(ret, servers); - - cleanup: - return ret; } @@ -687,16 +656,13 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourc= ePtr src, "s:volume", src->volume, "s:path", src->path, "a:server", &servers, NULL) < 0) - goto cleanup; + return NULL; if (src->debug && virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0) - goto cleanup; + return NULL; VIR_STEAL_PTR(ret, props); - - cleanup: - return ret; } @@ -759,10 +725,10 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePt= r src) driver =3D virStorageNetProtocolTypeToString(src->protocol); if (!(uri =3D qemuBlockStorageSourceGetURI(src))) - goto cleanup; + return NULL; if (!(uristr =3D virURIFormat(uri))) - goto cleanup; + return NULL; if (src->auth) { username =3D src->auth->username; @@ -776,8 +742,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr = src) "S:password-secret", passwordali= as, NULL)); - cleanup: - return ret; } @@ -807,7 +771,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr= src) */ if (VIR_STRDUP(target, src->path) < 0) - goto cleanup; + return NULL; /* Separate the target and lun */ if ((lunStr =3D strchr(target, '/'))) { @@ -816,7 +780,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr= src) virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse target for lunStr '%s'"), target); - goto cleanup; + return NULL; } } @@ -824,11 +788,11 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourceP= tr src) if (virSocketAddrNumericFamily(src->hosts[0].name) =3D=3D AF_INET6) { if (virAsprintf(&portal, "[%s]:%u", src->hosts[0].name, src->hosts[0].port) < 0) - goto cleanup; + return NULL; } else { if (virAsprintf(&portal, "%s:%u", src->hosts[0].name, src->hosts[0].port) < 0) - goto cleanup; + return NULL; } if (src->auth) { @@ -846,9 +810,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr= src) "S:password-secret", objalias, "S:initiator-name", src->initiat= or.iqn, NULL)); - goto cleanup; - - cleanup: return ret; } @@ -876,9 +837,8 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr s= rc) "S:export", src->path, "S:tls-creds", src->tlsAlias, NULL) < 0) - goto cleanup; + return NULL; - cleanup: return ret; } @@ -903,17 +863,17 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr= src) keysecret =3D srcPriv->secinfo->s.aes.alias; /* the auth modes are modelled after our old command line generato= r */ if (!(authmodes =3D virJSONValueNewArray())) - goto cleanup; + return NULL; if (!(mode =3D virJSONValueNewString("cephx")) || virJSONValueArrayAppend(authmodes, mode) < 0) - goto cleanup; + return NULL; mode =3D NULL; if (!(mode =3D virJSONValueNewString("none")) || virJSONValueArrayAppend(authmodes, mode) < 0) - goto cleanup; + return NULL; mode =3D NULL; } @@ -929,9 +889,8 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr s= rc) "A:auth-client-required", &authmodes, "S:key-secret", keysecret, NULL) < 0) - goto cleanup; + return NULL; - cleanup: return ret; } @@ -959,9 +918,8 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSource= Ptr src) "a:server", &serverprops, "s:vdi", src->path, NULL) < 0) - goto cleanup; + return NULL; - cleanup: return ret; } @@ -992,9 +950,8 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr s= rc) "a:server", &serverprops, "S:user", username, NULL) < 0) - goto cleanup; + return NULL; - cleanup: return ret; } @@ -1167,22 +1124,20 @@ qemuBlockStorageSourceGetBackendProps(virStorageSou= rcePtr src, if (qemuBlockNodeNameValidate(src->nodestorage) < 0 || virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage, = NULL) < 0) - goto cleanup; + return NULL; if (!legacy) { if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, fileprops)= < 0) - goto cleanup; + return NULL; if (virJSONValueObjectAdd(fileprops, "b:read-only", src->readonly, "s:discard", "unmap", NULL) < 0) - goto cleanup; + return NULL; } VIR_STEAL_PTR(ret, fileprops); - - cleanup: return ret; } @@ -1266,7 +1221,6 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virSt= orageSourcePtr src, virJSONValuePtr props) { VIR_AUTOPTR(virJSONValue) encprops =3D NULL; - int ret =3D -1; if (qemuBlockStorageSourceGetCryptoProps(src, &encprops) < 0) return -1; @@ -1274,12 +1228,9 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virS= torageSourcePtr src, if (virJSONValueObjectAdd(props, "s:driver", format, "A:encrypt", &encprops, NULL) < 0) - goto cleanup; - - ret =3D 0; + return -1; - cleanup: - return ret; + return 0; } @@ -1339,11 +1290,9 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(v= irStorageSourcePtr src) return NULL; if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0) - goto cleanup; + return NULL; VIR_STEAL_PTR(ret, props); - - cleanup: return ret; } @@ -1356,7 +1305,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSourcePtr src) virJSONValuePtr ret =3D NULL; if (!(props =3D qemuBlockStorageSourceGetBlockdevFormatCommonProps(src= ))) - goto cleanup; + return NULL; switch ((virStorageFileFormat) src->format) { case VIR_STORAGE_FILE_FAT: @@ -1364,17 +1313,17 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virSto= rageSourcePtr src) * put a raw layer on top */ case VIR_STORAGE_FILE_RAW: if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) - goto cleanup; + return NULL; break; case VIR_STORAGE_FILE_QCOW2: if (qemuBlockStorageSourceGetFormatQcow2Props(src, props) < 0) - goto cleanup; + return NULL; break; case VIR_STORAGE_FILE_QCOW: if (qemuBlockStorageSourceGetFormatQcowGenericProps(src, "qcow", p= rops) < 0) - goto cleanup; + return NULL; break; /* formats without any special parameters */ @@ -1405,22 +1354,19 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virSto= rageSourcePtr src) virReportError(VIR_ERR_INTERNAL_ERROR, _("mishandled storage format '%s'"), virStorageFileFormatTypeToString(src->format)); - goto cleanup; + return NULL; case VIR_STORAGE_FILE_LAST: default: virReportEnumRangeError(virStorageFileFormat, src->format); - goto cleanup; + return NULL; } if (driver && virJSONValueObjectAdd(props, "s:driver", driver, NULL) < 0) - goto cleanup; + return NULL; VIR_STEAL_PTR(ret, props); - - cleanup: - return ret; } @@ -1445,31 +1391,29 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSo= urcePtr src) virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("storage format '%s' does not support backing sto= re"), virStorageFileFormatTypeToString(src->format)); - goto cleanup; + return NULL; } if (!(props =3D qemuBlockStorageSourceGetBlockdevFormatProps(src))) - goto cleanup; + return NULL; if (virJSONValueObjectAppendString(props, "file", src->nodestorage) < = 0) - goto cleanup; + return NULL; if (src->backingStore && backingSupported) { if (virStorageSourceHasBacking(src)) { if (virJSONValueObjectAppendString(props, "backing", src->backingStore->nodeform= at) < 0) - goto cleanup; + return NULL; } else { /* chain is terminated, indicate that no detection should happ= en * in qemu */ if (virJSONValueObjectAppendNull(props, "backing") < 0) - goto cleanup; + return NULL; } } VIR_STEAL_PTR(ret, props); - - cleanup: return ret; } @@ -1520,14 +1464,12 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStor= ageSourcePtr src) if (!(data->formatProps =3D qemuBlockStorageSourceGetBlockdevProps(src= )) || !(data->storageProps =3D qemuBlockStorageSourceGetBackendProps(src= , false))) - goto cleanup; + return NULL; data->storageNodeName =3D src->nodestorage; data->formatNodeName =3D src->nodeformat; VIR_STEAL_PTR(ret, data); - - cleanup: return ret; } @@ -1690,13 +1632,12 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, const char *format =3D virStorageFileFormatTypeToString(newsrc->format= ); VIR_AUTOFREE(char *) device =3D NULL; VIR_AUTOFREE(char *) source =3D NULL; - int ret =3D -1; if (!(device =3D qemuAliasDiskDriveFromDisk(disk))) - goto cleanup; + return -1; if (qemuGetDriveSourceString(newsrc, NULL, &source) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONTransactionAdd(actions, "blockdev-snapshot-sync", "s:device", device, @@ -1704,12 +1645,9 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, "s:format", format, "S:mode", reuse ? "existing" : NULL, NULL) < 0) - goto cleanup; - - ret =3D 0; + return -1; - cleanup: - return ret; + return 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480294573685.5803090859995; Fri, 5 Apr 2019 09:04:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6F573689B; Fri, 5 Apr 2019 16:04:52 +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 C24AA60D62; Fri, 5 Apr 2019 16:04:52 +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 7FEBB181B9F0; Fri, 5 Apr 2019 16:04:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4fnN003465 for ; Fri, 5 Apr 2019 12:04:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15BA860CBA; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 924A960CAD for ; Fri, 5 Apr 2019 16:04:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/11] internal: Introduce VIR_RETURN_PTR 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 05 Apr 2019 16:04:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" With the introduction of more and more internal data types which support VIR_AUTOPTR it's becoming common to see the following pattern: VIR_AUTOPTR(virSomething) some =3D NULL virSomethingPtr ret =3D NULL; ... (ret is not touched ) ... VIR_STEAL_PTR(ret, some); return ret; This patch introduces a macro named VIR_RETURN_PTR which returns the pointer directly without the need for an explicitly defined return variable and use of VIR_STEAL_PTR. Internally obviously a temporary pointer is created to allow setting the original pointer to NULL so that the VIR_AUTOPTR function does not free the memory which we want to actually return. The name of the temporary variable is deliberately long and complex to minimize the possibility of collision. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/internal.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/internal.h b/src/internal.h index cf03a82105..5a868bb00c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -279,6 +279,21 @@ (b) =3D NULL; \ } while (0) +/** + * VIR_RETURN_PTR: + * @ret: pointer to return + * + * Returns value of @ret while clearing @ret. This ensures that pointers + * freed by using VIR_AUTOPTR can be easily passed back to the caller with= out + * any temporary variable. @ptr is evaluated more than once. + */ +# define VIR_RETURN_PTR(ptr) \ + do { \ + typeof(ptr) virTemporaryReturnPointer =3D (ptr); \ + (ptr) =3D NULL; \ + return virTemporaryReturnPointer; \ + } while (0) + /** * virCheckFlags: * @supported: an OR'ed set of supported flags --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480287459857.8921773922464; Fri, 5 Apr 2019 09:04:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19D6C308CF96; Fri, 5 Apr 2019 16:04:45 +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 E91132656F; Fri, 5 Apr 2019 16:04:44 +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 ADC93181AC48; Fri, 5 Apr 2019 16:04:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4f6U003470 for ; Fri, 5 Apr 2019 12:04:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8E3A60C8D; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6215460CAD for ; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:22 +0200 Message-Id: <1e2ea793ba1a278fc0120789e64e92463876b0a4.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/11] qemu: block: Use VIR_RETURN_PTR 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 05 Apr 2019 16:04:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Demonstrate how VIR_RETURN_PTR by refactoring qemu_block.c Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 48 +++++++++++-------------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 31800919a7..7d9f7ec3ab 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -234,7 +234,6 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namedn= odes, struct qemuBlockNodeNameGetBackingChainData data; VIR_AUTOPTR(virHashTable) namednodestable =3D NULL; VIR_AUTOPTR(virHashTable) disks =3D NULL; - virHashTablePtr ret =3D NULL; memset(&data, 0, sizeof(data)); @@ -257,8 +256,7 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namedn= odes, &data) < 0) return NULL; - VIR_STEAL_PTR(ret, disks); - return ret; + VIR_RETURN_PTR(disks); } @@ -375,7 +373,6 @@ virHashTablePtr qemuBlockGetNodeData(virJSONValuePtr data) { VIR_AUTOPTR(virHashTable) nodedata =3D NULL; - virHashTablePtr ret =3D NULL; if (!(nodedata =3D virHashCreate(50, virJSONValueHashFree))) return NULL; @@ -384,8 +381,7 @@ qemuBlockGetNodeData(virJSONValuePtr data) qemuBlockNamedNodesArrayToHash, node= data) < 0) return NULL; - VIR_STEAL_PTR(ret, nodedata); - return ret; + VIR_RETURN_PTR(nodedata); } @@ -414,7 +410,6 @@ virURIPtr qemuBlockStorageSourceGetURI(virStorageSourcePtr src) { VIR_AUTOPTR(virURI) uri =3D NULL; - virURIPtr ret =3D NULL; if (src->nhosts !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -455,8 +450,7 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) if (VIR_STRDUP(uri->server, src->hosts->name) < 0) return NULL; - VIR_STEAL_PTR(ret, uri); - return ret; + VIR_RETURN_PTR(uri); } @@ -478,7 +472,6 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, bool legacy) { VIR_AUTOPTR(virJSONValue) server =3D NULL; - virJSONValuePtr ret =3D NULL; const char *transport; const char *field; VIR_AUTOFREE(char *) port =3D NULL; @@ -522,8 +515,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorage= NetHostDefPtr host, return NULL; } - VIR_STEAL_PTR(ret, server); - return ret; + VIR_RETURN_PTR(server); } @@ -541,7 +533,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, { VIR_AUTOPTR(virJSONValue) servers =3D NULL; VIR_AUTOPTR(virJSONValue) server =3D NULL; - virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; size_t i; @@ -560,8 +551,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, server =3D NULL; } - VIR_STEAL_PTR(ret, servers); - return ret; + VIR_RETURN_PTR(servers); } @@ -610,7 +600,6 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(v= irStorageSourcePtr src) { VIR_AUTOPTR(virJSONValue) servers =3D NULL; VIR_AUTOPTR(virJSONValue) server =3D NULL; - virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; size_t i; @@ -629,8 +618,7 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(v= irStorageSourcePtr src) server =3D NULL; } - VIR_STEAL_PTR(ret, servers); - return ret; + VIR_RETURN_PTR(servers); } @@ -640,7 +628,6 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourceP= tr src, { VIR_AUTOPTR(virJSONValue) servers =3D NULL; VIR_AUTOPTR(virJSONValue) props =3D NULL; - virJSONValuePtr ret =3D NULL; if (!(servers =3D qemuBlockStorageSourceBuildHostsJSONSocketAddress(sr= c, legacy))) return NULL; @@ -662,8 +649,7 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourceP= tr src, virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0) return NULL; - VIR_STEAL_PTR(ret, props); - return ret; + VIR_RETURN_PTR(props); } @@ -1048,7 +1034,6 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= ePtr src, { int actualType =3D virStorageSourceGetActualType(src); VIR_AUTOPTR(virJSONValue) fileprops =3D NULL; - virJSONValuePtr ret =3D NULL; switch ((virStorageType)actualType) { case VIR_STORAGE_TYPE_BLOCK: @@ -1137,8 +1122,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= ePtr src, return NULL; } - VIR_STEAL_PTR(ret, fileprops); - return ret; + VIR_RETURN_PTR(fileprops); } @@ -1266,7 +1250,6 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(vi= rStorageSourcePtr src) int detectZeroesMode =3D virDomainDiskGetDetectZeroesMode(src->discard, src->detect_ze= roes); VIR_AUTOPTR(virJSONValue) props =3D NULL; - virJSONValuePtr ret =3D NULL; if (qemuBlockNodeNameValidate(src->nodeformat) < 0) return NULL; @@ -1292,8 +1275,7 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(vi= rStorageSourcePtr src) if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0) return NULL; - VIR_STEAL_PTR(ret, props); - return ret; + VIR_RETURN_PTR(props); } @@ -1302,7 +1284,6 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSourcePtr src) { const char *driver =3D NULL; VIR_AUTOPTR(virJSONValue) props =3D NULL; - virJSONValuePtr ret =3D NULL; if (!(props =3D qemuBlockStorageSourceGetBlockdevFormatCommonProps(src= ))) return NULL; @@ -1366,8 +1347,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStora= geSourcePtr src) virJSONValueObjectAdd(props, "s:driver", driver, NULL) < 0) return NULL; - VIR_STEAL_PTR(ret, props); - return ret; + VIR_RETURN_PTR(props); } @@ -1385,7 +1365,6 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSour= cePtr src) { bool backingSupported =3D src->format >=3D VIR_STORAGE_FILE_BACKING; VIR_AUTOPTR(virJSONValue) props =3D NULL; - virJSONValuePtr ret =3D NULL; if (virStorageSourceHasBacking(src) && !backingSupported) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -1413,8 +1392,7 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSour= cePtr src) } } - VIR_STEAL_PTR(ret, props); - return ret; + VIR_RETURN_PTR(props); } @@ -1457,7 +1435,6 @@ qemuBlockStorageSourceAttachDataPtr qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src) { VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data =3D NULL; - qemuBlockStorageSourceAttachDataPtr ret =3D NULL; if (VIR_ALLOC(data) < 0) return NULL; @@ -1469,8 +1446,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorag= eSourcePtr src) data->storageNodeName =3D src->nodestorage; data->formatNodeName =3D src->nodeformat; - VIR_STEAL_PTR(ret, data); - return ret; + VIR_RETURN_PTR(data); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 10:02:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480290384189.61497619011948; Fri, 5 Apr 2019 09:04:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACB20F3FDA; Fri, 5 Apr 2019 16:04:48 +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 78DE05D722; Fri, 5 Apr 2019 16:04:48 +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 2D28E181B9E8; Fri, 5 Apr 2019 16:04:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4gho003478 for ; Fri, 5 Apr 2019 12:04:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id A96B060CAD; Fri, 5 Apr 2019 16:04:42 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3288560C8D for ; Fri, 5 Apr 2019 16:04:42 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:23 +0200 Message-Id: <84cb35d0b9f6042137ef53552b4507263b8b093b.1554480066.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/11] util: json: Use VIR_APPEND_ELEMENT in virJSONValueObjectAppend 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 Apr 2019 16:04:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function open-codes addition into an array. Use the helper instead. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virjson.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 1dceb746b9..7b874bf2ec 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -609,7 +609,8 @@ virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value) { - char *newkey; + virJSONObjectPair pair =3D { NULL, value }; + int ret =3D -1; if (object->type !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -622,20 +623,14 @@ virJSONValueObjectAppend(virJSONValuePtr object, return -1; } - if (VIR_STRDUP(newkey, key) < 0) - return -1; - - if (VIR_REALLOC_N(object->data.object.pairs, - object->data.object.npairs + 1) < 0) { - VIR_FREE(newkey); + if (VIR_STRDUP(pair.key, key) < 0) return -1; - } - object->data.object.pairs[object->data.object.npairs].key =3D newkey; - object->data.object.pairs[object->data.object.npairs].value =3D value; - object->data.object.npairs++; + ret =3D VIR_APPEND_ELEMENT(object->data.object.pairs, + object->data.object.npairs, pair); - return 0; + VIR_FREE(pair.key); + return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list