From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044939; cv=none; d=zoho.com; s=zohoarc; b=W+QeYG3ZpNduaM87+gLD+yTpJsDK+Dal+UdMdg+TzjxEd+AB6AYFACgDg0Xrg4Y8duztKHUIdfFM55Vk/4vVppOXkoKrCsw9w6sYUVCEhRMcpdBq5qnxQi7boS6GR9Qv3weZQQbyeRcTKOhrIEexhmPxV/g5gHiDP8ZATyXEyaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044939; 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:ARC-Authentication-Results; bh=NPjXstCARchlTYq9L6mflWqZB638U0wd0XHQ/M+osIw=; b=fh16WiBzDABSoRPYODWe08bChO4bAJiNNmnV1Jj3dqkflF+1sB/d4eOz2kXnNiI4qJCnr589BXR3gsM1SgOJ3hbB/2gbLe2TppHNACDfPtCFXwBh11p1D6l8vS0b9xMTelGm5wuKPpAqBaUol7I+erI5Vc92fFP+hQikupmS0bw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044939956443.7566957824548; Mon, 9 Sep 2019 09:02:19 -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 3D0D67BDD4; Mon, 9 Sep 2019 16:02:18 +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 0E4CC6012D; Mon, 9 Sep 2019 16:02:18 +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 AC7BC24F32; Mon, 9 Sep 2019 16:02:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0USo026497 for ; Mon, 9 Sep 2019 12:00:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3E16F6062E; Mon, 9 Sep 2019 16:00:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B81F25F7F6 for ; Mon, 9 Sep 2019 16:00:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:22 +0200 Message-Id: <1c66a87623a552177aed059c8c365a30708bb1f1.1568044773.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/6] qemu_conf.c: Fix naming of *AddRemove* functions 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.26]); Mon, 09 Sep 2019 16:02:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Our naming rules prefer qemuObjectOperation() scheme rather than qemuOperationObject() for function names. These were not honoured in recent commits to qemu_conf.c. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 86b2eef060..32d411e536 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1679,7 +1679,7 @@ qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver, =20 =20 static int -qemuAddRemoveSharedDiskInternal(virQEMUDriverPtr driver, +qemuSharedDiskAddRemoveInternal(virQEMUDriverPtr driver, virDomainDiskDefPtr disk, const char *name, bool addDisk) @@ -1730,7 +1730,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, virDomainDiskDefPtr disk, const char *name) { - return qemuAddRemoveSharedDiskInternal(driver, disk, name, true); + return qemuSharedDiskAddRemoveInternal(driver, disk, name, true); } =20 =20 @@ -1768,7 +1768,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) =20 =20 static int -qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver, +qemuSharedHostdevAddRemoveInternal(virQEMUDriverPtr driver, virDomainHostdevDefPtr hostdev, const char *name, bool addDevice) @@ -1803,7 +1803,7 @@ qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr d= river, } =20 static int -qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver, +qemuSharedDeviceAddRemoveInternal(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name, bool addDevice) @@ -1813,10 +1813,10 @@ qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr = driver, * which is only valid for block disk and scsi host device. */ if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) - return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, + return qemuSharedDiskAddRemoveInternal(driver, dev->data.disk, name, addDevice); else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, + return qemuSharedHostdevAddRemoveInternal(driver, dev->data.hostde= v, name, addDevice); else return 0; @@ -1837,7 +1837,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - return qemuAddRemoveSharedDeviceInternal(driver, dev, name, true); + return qemuSharedDeviceAddRemoveInternal(driver, dev, name, true); } =20 =20 @@ -1846,7 +1846,7 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, virDomainDiskDefPtr disk, const char *name) { - return qemuAddRemoveSharedDiskInternal(driver, disk, name, false); + return qemuSharedDiskAddRemoveInternal(driver, disk, name, false); } =20 =20 @@ -1864,7 +1864,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - return qemuAddRemoveSharedDeviceInternal(driver, dev, name, false); + return qemuSharedDeviceAddRemoveInternal(driver, dev, name, false); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044865; cv=none; d=zoho.com; s=zohoarc; b=iTSDx0HSy9VixjkXsa9Ff3sdBI34jL88uIRR4mZbcE5a32bRKSfvE9E+rwwmyUpCK2gNC8qkPJd5RzQFFgqF0MYuxaOS5BW59wNp3gcVkcpRk7/rrHYIxSXYapQhDt+i0oQMJqCE8il7pqhGnRma2YkmaeeDfNnUghvgvGDCKHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044865; 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:ARC-Authentication-Results; bh=K4s+TqtXpsGeN7/ro2nBI+mO7LNFnERim8iP7qg0UKs=; b=DEVbm1pa0r+MRDcHsLpgX10Yb8iDp/YmC+wvLmXdOh9OXPo26TP4fn9uXMVdBig6iVTTlSh8zQKxSIXN5Au3bQjCme8MPGNI4KL7KfjhsmQX2sdW3ti9g5PYSTF3aUTaQHyB7DZVC7B1Qrgw6mVYm5XvjX7nTPdRpt07JYwhrAw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044865955890.0984337512829; Mon, 9 Sep 2019 09:01:05 -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 9B97010F2E9D; Mon, 9 Sep 2019 16:01:02 +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 54AD87E3F; Mon, 9 Sep 2019 16:01:02 +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 41D62180B536; Mon, 9 Sep 2019 16:01:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0VO1026505 for ; Mon, 9 Sep 2019 12:00:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C8FB60923; Mon, 9 Sep 2019 16:00:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95598614DD for ; Mon, 9 Sep 2019 16:00:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] qemu_conf: Drop a pair of needless 'cleanup' labels 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.6.2 (mx1.redhat.com [10.5.110.66]); Mon, 09 Sep 2019 16:01:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are two 'cleanup' labels - one in virQEMUDriverConfigHugeTLBFSInit() and the other in virQEMUDriverConfigSetDefaults() that do nothing more than return and integer value. No memory freeing or anything important is done there. Drop them in favour of returning immediately. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 32d411e536..f11df03cf8 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -402,18 +402,12 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr huge= tlbfs, const char *path, bool deflt) { - int ret =3D -1; - - if (VIR_STRDUP(hugetlbfs->mnt_dir, path) < 0) - goto cleanup; - - if (virFileGetHugepageSize(path, &hugetlbfs->size) < 0) - goto cleanup; + if (VIR_STRDUP(hugetlbfs->mnt_dir, path) < 0 || + virFileGetHugepageSize(path, &hugetlbfs->size) < 0) + return -1; =20 hugetlbfs->deflt =3D deflt; - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -1172,8 +1166,6 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cf= g) int virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg) { - int ret =3D -1; - #define SET_TLS_SECRET_UUID_DEFAULT(val) \ do { \ if (!cfg->val## TLSx509certdir && \ @@ -1181,7 +1173,7 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr= cfg) cfg->defaultTLSx509secretUUID) { \ if (VIR_STRDUP(cfg->val## TLSx509secretUUID, \ cfg->defaultTLSx509secretUUID) < 0) \ - goto cleanup; \ + return -1; \ } \ } while (0) =20 @@ -1205,11 +1197,11 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigP= tr cfg) if (virFileExists(SYSCONFDIR "/pki/libvirt-"#val)) { \ if (VIR_STRDUP(cfg->val ## TLSx509certdir, \ SYSCONFDIR "/pki/libvirt-"#val) < 0) \ - goto cleanup; \ + return -1; \ } else { \ if (VIR_STRDUP(cfg->val ## TLSx509certdir, \ cfg->defaultTLSx509certdir) < 0) \ - goto cleanup; \ + return -1; \ } \ } while (0) =20 @@ -1234,9 +1226,7 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr= cfg) =20 #undef SET_TLS_VERIFY_DEFAULT =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044873; cv=none; d=zoho.com; s=zohoarc; b=bpXojFAtsjYY/kbbkwVpk9sxzJbaVS9jLELe0GV01fZXWZTV2T+i/0MO4wH1hAjYk1nTccy4HJSif2fi6RqNpquCesxY2Mo1C2oNBAAm6A80An3Ro2wLP00pcckWYkOcywa8O09OkLQCP+wSGnuMvRYOKoBDVl5YoU4n4uD0I60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044873; 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:ARC-Authentication-Results; bh=MjjYrk/7CG9YcFrD5Diof19RXGx3Zeb42P5XKMYKBYg=; b=f6u9DTH3BeaYmk2mZE6LJb7+7tNnb150Uwm9AIlISAW1HpvPgg/U5e4o/DiQedKJdNtoeRSLk2WpY1QUC/ne5nbTUprauxxbieWOQjaX9KyUro8iua2VARe5j5tPh2a0001g5NILYw0n6ajXeJW0EI+zROEQTp4nkzoMdY90Vv4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044873897437.8333429666113; Mon, 9 Sep 2019 09:01:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 215608980E4; Mon, 9 Sep 2019 16:01:11 +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 DBB2560BE2; Mon, 9 Sep 2019 16:01:10 +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 74C1F180BA9C; Mon, 9 Sep 2019 16:01:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0V0D026520 for ; Mon, 9 Sep 2019 12:00:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E73FD60A9F; Mon, 9 Sep 2019 16:00:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E3696061E for ; Mon, 9 Sep 2019 16:00:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:24 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/6] qemu_conf: Use more of VIR_AUTOFREE() 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Mon, 09 Sep 2019 16:01:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 130 +++++++++++++------------------------------ 1 file changed, 40 insertions(+), 90 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f11df03cf8..c3255a6f54 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -181,37 +181,26 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) virGetGroupID("tss", &cfg->swtpm_group) < 0) cfg->swtpm_group =3D 0; /* fall back to root */ } else { - char *rundir; - char *cachedir; + VIR_AUTOFREE(char *) rundir =3D NULL; + VIR_AUTOFREE(char *) cachedir =3D NULL; =20 cachedir =3D virGetUserCacheDirectory(); if (!cachedir) goto error; =20 - if (virAsprintf(&cfg->logDir, - "%s/qemu/log", cachedir) < 0) { - VIR_FREE(cachedir); + if (virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir) < 0) goto error; - } - if (virAsprintf(&cfg->swtpmLogDir, - "%s/qemu/log", cachedir) < 0) { - VIR_FREE(cachedir); + if (virAsprintf(&cfg->swtpmLogDir, "%s/qemu/log", cachedir) < 0) goto error; - } - if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) { - VIR_FREE(cachedir); + if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) goto error; - } - VIR_FREE(cachedir); =20 rundir =3D virGetUserRuntimeDirectory(); if (!rundir) goto error; if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) { - VIR_FREE(rundir); goto error; } - VIR_FREE(rundir); =20 if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < = 0) goto error; @@ -1261,7 +1250,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDri= verPtr driver) { size_t i, j; virCapsPtr caps; - virSecurityManagerPtr *sec_managers =3D NULL; + VIR_AUTOFREE(virSecurityManagerPtr) *sec_managers =3D NULL; /* Security driver data */ const char *doi, *model, *lbl, *type; const int virtTypes[] =3D {VIR_DOMAIN_VIRT_KVM, @@ -1308,12 +1297,10 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUD= riverPtr driver) VIR_DEBUG("Initialized caps for security driver \"%s\" with " "DOI \"%s\"", model, doi); } - VIR_FREE(sec_managers); =20 return caps; =20 error: - VIR_FREE(sec_managers); virObjectUnref(caps); return NULL; } @@ -1485,31 +1472,26 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices, const char *device_path, int sgio) { - char *sysfs_path =3D NULL; - char *key =3D NULL; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; + VIR_AUTOFREE(char *) key =3D NULL; int val; - int ret =3D -1; =20 if (!(sysfs_path =3D virGetUnprivSGIOSysfsPath(device_path, NULL))) - goto cleanup; + return -1; =20 /* It can't be conflict if unpriv_sgio is not supported by kernel. */ - if (!virFileExists(sysfs_path)) { - ret =3D 0; - goto cleanup; - } + if (!virFileExists(sysfs_path)) + return 0; =20 if (!(key =3D qemuGetSharedDeviceKey(device_path))) - goto cleanup; + return -1; =20 /* It can't be conflict if no other domain is sharing it. */ - if (!(virHashLookup(sharedDevices, key))) { - ret =3D 0; - goto cleanup; - } + if (!(virHashLookup(sharedDevices, key))) + return 0; =20 if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0) - goto cleanup; + return -1; =20 /* Error message on failure needs to be handled in caller * since there is more specific knowledge of device @@ -1519,16 +1501,10 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices, sgio =3D=3D VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) || (val =3D=3D 1 && sgio =3D=3D VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) { - ret =3D -2; - goto cleanup; + return -2; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(key); - return ret; + return 0; } =20 =20 @@ -1674,7 +1650,7 @@ qemuSharedDiskAddRemoveInternal(virQEMUDriverPtr driv= er, const char *name, bool addDisk) { - char *key =3D NULL; + VIR_AUTOFREE(char *) key =3D NULL; int ret =3D -1; =20 if (virStorageSourceIsEmpty(disk->src) || @@ -1701,7 +1677,6 @@ qemuSharedDiskAddRemoveInternal(virQEMUDriverPtr driv= er, ret =3D 0; cleanup: qemuDriverUnlock(driver); - VIR_FREE(key); return ret; } =20 @@ -1739,7 +1714,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) { virDomainHostdevSubsysSCSIPtr scsisrc =3D &hostdev->source.subsys.u.sc= si; virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - char *dev_name =3D NULL; + VIR_AUTOFREE(char *) dev_name =3D NULL; char *dev_path =3D NULL; =20 if (!(dev_name =3D virSCSIDeviceGetDevName(NULL, @@ -1747,12 +1722,9 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit))) - goto cleanup; + return NULL; =20 ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name)); - - cleanup: - VIR_FREE(dev_name); return dev_path; } =20 @@ -1763,18 +1735,16 @@ qemuSharedHostdevAddRemoveInternal(virQEMUDriverPtr= driver, const char *name, bool addDevice) { - char *dev_path =3D NULL; - char *key =3D NULL; + VIR_AUTOFREE(char *) dev_path =3D NULL; + VIR_AUTOFREE(char *) key =3D NULL; int ret =3D -1; =20 if (!qemuIsSharedHostdev(hostdev)) return 0; =20 - if (!(dev_path =3D qemuGetHostdevPath(hostdev))) - goto cleanup; - - if (!(key =3D qemuGetSharedDeviceKey(dev_path))) - goto cleanup; + if (!(dev_path =3D qemuGetHostdevPath(hostdev)) || + !(key =3D qemuGetSharedDeviceKey(dev_path))) + return -1; =20 qemuDriverLock(driver); =20 @@ -1785,11 +1755,7 @@ qemuSharedHostdevAddRemoveInternal(virQEMUDriverPtr = driver, =20 qemuDriverUnlock(driver); =20 - cleanup: - VIR_FREE(dev_path); - VIR_FREE(key); return ret; - } =20 static int @@ -1863,10 +1829,9 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) { virDomainDiskDefPtr disk =3D NULL; virDomainHostdevDefPtr hostdev =3D NULL; - char *sysfs_path =3D NULL; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; const char *path =3D NULL; int val =3D -1; - int ret =3D -1; =20 /* "sgio" is only valid for block disk; cdrom * and floopy disk can have empty source. @@ -1889,7 +1854,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("'sgio' is not supported for SCSI " "generic device yet ")); - goto cleanup; + return -1; } =20 return 0; @@ -1898,7 +1863,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) } =20 if (!(sysfs_path =3D virGetUnprivSGIOSysfsPath(path, NULL))) - goto cleanup; + return -1; =20 /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. = */ val =3D (disk->sgio =3D=3D VIR_DOMAIN_DEVICE_SGIO_UNFILTERED); @@ -1909,13 +1874,9 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) */ if ((virFileExists(sysfs_path) || val =3D=3D 1) && virSetDeviceUnprivSGIO(path, NULL, val) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(sysfs_path); - return ret; + return 0; } =20 int qemuDriverAllocateID(virQEMUDriverPtr driver) @@ -1951,14 +1912,12 @@ char * qemuGetDomainHugepagePath(const virDomainDef *def, virHugeTLBFSPtr hugepage) { - char *base =3D qemuGetBaseHugepagePath(hugepage); - char *domPath =3D virDomainDefGetShortName(def); + VIR_AUTOFREE(char *) base =3D qemuGetBaseHugepagePath(hugepage); + VIR_AUTOFREE(char *) domPath =3D virDomainDefGetShortName(def); char *ret =3D NULL; =20 if (base && domPath) ignore_value(virAsprintf(&ret, "%s/%s", base, domPath)); - VIR_FREE(domPath); - VIR_FREE(base); return ret; } =20 @@ -2019,20 +1978,15 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *= def, virQEMUDriverConfigPtr cfg, char **path) { - char *shortName =3D NULL; - char *base =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) shortName =3D NULL; + VIR_AUTOFREE(char *) base =3D NULL; =20 if (!(shortName =3D virDomainDefGetShortName(def)) || qemuGetMemoryBackingBasePath(cfg, &base) < 0 || virAsprintf(path, "%s/%s", base, shortName) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(base); - VIR_FREE(shortName); - return ret; + return 0; } =20 =20 @@ -2054,22 +2008,18 @@ qemuGetMemoryBackingPath(const virDomainDef *def, const char *alias, char **memPath) { - char *domainPath =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) domainPath =3D NULL; =20 if (!alias) { /* This should never happen (TM) */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("memory device alias is not assigned")); - goto cleanup; + return -1; } =20 if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 || virAsprintf(memPath, "%s/%s", domainPath, alias) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(domainPath); - return ret; + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044945; cv=none; d=zoho.com; s=zohoarc; b=nFfZb2YCWzMUbpC8WHDJWUxKL3CQY6IkUt3ekLICbB1cOoecsVGERp+VgjYLwRz1u2X1Mo/IuhkptsXjfqlzz9eu0d7opwiADL8YAp1PaBXL1S/GDrjBQXdKvk/VRDVujTETAAkVnRdhTsVtDpE/sr+lBn9lGuzLN5l8oonKuWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044945; 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:ARC-Authentication-Results; bh=W82ZkPLyd9vyd32lAfzDdX+yMBbW1BpIyxQyLp0lAoA=; b=QXv5fSx5e1pMFIQaRj2INEYfA7D9WY7k/Aup2Shvj8m7ZXrcweNy7ZU2Tdv/HGGVR7xCVm8Jroibl6IylcRCsgLMIcP+HpwevdTc+fYsQFbR9jcCD7qGxFZfQeNMBN7M0pNMYkhWV7IfaB3I3blkN1mmaVKsSPdNbsvbdVjZc9g= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044945638597.7505688618062; Mon, 9 Sep 2019 09:02:25 -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 BD51785545; Mon, 9 Sep 2019 16:02:23 +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 8FE9D5C220; Mon, 9 Sep 2019 16:02:23 +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 380AD24F34; Mon, 9 Sep 2019 16:02:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0WRi026525 for ; Mon, 9 Sep 2019 12:00:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7CA060923; Mon, 9 Sep 2019 16:00:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 401D36061E for ; Mon, 9 Sep 2019 16:00:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:25 +0200 Message-Id: <18d7dae07b9e0b30e96e3a043ab58bac0137dbea.1568044773.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/6] qemu_conf: Use more of VIR_AUTOUNREF() 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.28]); Mon, 09 Sep 2019 16:02:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 139 ++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 76 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index c3255a6f54..f805991872 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -105,7 +105,7 @@ qemuDriverUnlock(virQEMUDriverPtr driver) =20 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) { - virQEMUDriverConfigPtr cfg; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg =3D NULL; =20 if (virQEMUConfigInitialize() < 0) return NULL; @@ -117,9 +117,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) =20 if (privileged) { if (virGetUserID(QEMU_USER, &cfg->user) < 0) - goto error; + return NULL; if (virGetGroupID(QEMU_GROUP, &cfg->group) < 0) - goto error; + return NULL; } else { cfg->user =3D (uid_t)-1; cfg->group =3D (gid_t)-1; @@ -132,48 +132,48 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) if (privileged) { if (virAsprintf(&cfg->logDir, "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) - goto error; + return NULL; =20 if (virAsprintf(&cfg->swtpmLogDir, "%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0) - goto error; + return NULL; =20 if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0) - goto error; + return NULL; =20 if (virAsprintf(&cfg->stateDir, "%s/libvirt/qemu", RUNSTATEDIR) < 0) - goto error; + return NULL; =20 if (virAsprintf(&cfg->swtpmStateDir, "%s/libvirt/qemu/swtpm", RUNSTATEDIR) < 0) - goto error; + return NULL; =20 if (virAsprintf(&cfg->cacheDir, "%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0) - goto error; + return NULL; =20 if (virAsprintf(&cfg->libDir, "%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->checkpointDir, "%s/checkpoint", cfg->libDir)= < 0) - goto error; + return NULL; if (virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->channelTargetDir, "%s/channel/target", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->memoryBackingDir, "%s/ram", cfg->libDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm", LOCALSTATEDIR) < 0) - goto error; + return NULL; if (!virDoesUserExist("tss") || virGetUserID("tss", &cfg->swtpm_user) < 0) cfg->swtpm_user =3D 0; /* fall back to root */ @@ -186,58 +186,58 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) =20 cachedir =3D virGetUserCacheDirectory(); if (!cachedir) - goto error; + return NULL; =20 if (virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->swtpmLogDir, "%s/qemu/log", cachedir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) - goto error; + return NULL; =20 rundir =3D virGetUserRuntimeDirectory(); if (!rundir) - goto error; + return NULL; if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) { - goto error; + return NULL; } =20 if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < = 0) - goto error; + return NULL; =20 if (!(cfg->configBaseDir =3D virGetUserConfigDirectory())) - goto error; + return NULL; =20 if (virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir) <= 0) - goto error; + return NULL; if (virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir)= < 0) - goto error; + return NULL; if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->config= BaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->checkpointDir, "%s/qemu/checkpoint", cfg->co= nfigBaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBas= eDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->channelTargetDir, "%s/qemu/channel/target", cfg->configBaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->nvramDir, "%s/qemu/nvram", cfg->configBaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->memoryBackingDir, "%s/qemu/ram", cfg->config= BaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->swtpmStorageDir, "%s/qemu/swtpm", cfg->confi= gBaseDir) < 0) - goto error; + return NULL; cfg->swtpm_user =3D (uid_t)-1; cfg->swtpm_group =3D (gid_t)-1; } =20 if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->autostartDir, "%s/qemu/autostart", cfg->configBa= seDir) < 0) - goto error; + return NULL; if (virAsprintf(&cfg->slirpStateDir, "%s/slirp", cfg->stateDir) < 0) - goto error; + return NULL; =20 /* Set the default directory to find TLS X.509 certificates. * This will then be used as a fallback if the service specific @@ -245,13 +245,13 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) */ if (VIR_STRDUP(cfg->defaultTLSx509certdir, SYSCONFDIR "/pki/qemu") < 0) - goto error; + return NULL; =20 if (VIR_STRDUP(cfg->vncListen, VIR_LOOPBACK_IPV4_ADDR) < 0) - goto error; + return NULL; =20 if (VIR_STRDUP(cfg->spiceListen, VIR_LOOPBACK_IPV4_ADDR) < 0) - goto error; + return NULL; =20 cfg->remotePortMin =3D QEMU_REMOTE_PORT_MIN; cfg->remotePortMax =3D QEMU_REMOTE_PORT_MAX; @@ -269,13 +269,13 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) virFileFindHugeTLBFS(&cfg->hugetlbfs, &cfg->nhugetlbfs) < 0) { /* This however is not implemented on all platforms. */ if (virGetLastErrorCode() !=3D VIR_ERR_NO_SUPPORT) - goto error; + return NULL; } =20 if (VIR_STRDUP(cfg->bridgeHelperName, QEMU_BRIDGE_HELPER) < 0 || VIR_STRDUP(cfg->prHelperName, QEMU_PR_HELPER) < 0 || VIR_STRDUP(cfg->slirpHelperName, QEMU_SLIRP_HELPER) < 0) - goto error; + return NULL; =20 cfg->clearEmulatorCapabilities =3D true; =20 @@ -291,23 +291,19 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) cfg->stdioLogD =3D true; =20 if (!(cfg->namespaces =3D virBitmapNew(QEMU_DOMAIN_NS_LAST))) - goto error; + return NULL; =20 if (privileged && qemuDomainNamespaceAvailable(QEMU_DOMAIN_NS_MOUNT) && virBitmapSetBit(cfg->namespaces, QEMU_DOMAIN_NS_MOUNT) < 0) - goto error; + return NULL; =20 if (virFirmwareParseList(DEFAULT_LOADER_NVRAM, &cfg->firmwares, &cfg->nfirmwares) < 0) - goto error; + return NULL; =20 - return cfg; - - error: - virObjectUnref(cfg); - return NULL; + VIR_RETURN_PTR(cfg); } =20 =20 @@ -1249,7 +1245,7 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) { size_t i, j; - virCapsPtr caps; + VIR_AUTOUNREF(virCapsPtr) caps =3D NULL; VIR_AUTOFREE(virSecurityManagerPtr) *sec_managers =3D NULL; /* Security driver data */ const char *doi, *model, *lbl, *type; @@ -1258,17 +1254,17 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUD= riverPtr driver) =20 /* Basic host arch / guest machine capabilities */ if (!(caps =3D virQEMUCapsInit(driver->qemuCapsCache))) - goto error; + return NULL; =20 if (virGetHostUUID(caps->host.host_uuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot get the host uuid")); - goto error; + return NULL; } =20 /* access sec drivers and create a sec model for each one */ if (!(sec_managers =3D qemuSecurityGetNested(driver->securityManager))) - goto error; + return NULL; =20 /* calculate length */ for (i =3D 0; sec_managers[i]; i++) @@ -1276,7 +1272,7 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDri= verPtr driver) caps->host.nsecModels =3D i; =20 if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) - goto error; + return NULL; =20 for (i =3D 0; sec_managers[i]; i++) { virCapsHostSecModelPtr sm =3D &caps->host.secModels[i]; @@ -1284,25 +1280,21 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUD= riverPtr driver) model =3D qemuSecurityGetModel(sec_managers[i]); if (VIR_STRDUP(sm->model, model) < 0 || VIR_STRDUP(sm->doi, doi) < 0) - goto error; + return NULL; =20 for (j =3D 0; j < ARRAY_CARDINALITY(virtTypes); j++) { lbl =3D qemuSecurityGetBaseLabel(sec_managers[i], virtTypes[j]= ); type =3D virDomainVirtTypeToString(virtTypes[j]); if (lbl && virCapabilitiesHostSecModelAddBaseLabel(sm, type, lbl) < 0) - goto error; + return NULL; } =20 VIR_DEBUG("Initialized caps for security driver \"%s\" with " "DOI \"%s\"", model, doi); } =20 - return caps; - - error: - virObjectUnref(caps); - return NULL; + VIR_RETURN_PTR(caps); } =20 =20 @@ -1389,9 +1381,9 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr d= river, virArch arch, virDomainVirtType virttype) { - virDomainCapsPtr ret =3D NULL, domCaps =3D NULL; - virCapsPtr caps =3D NULL; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + VIR_AUTOUNREF(virDomainCapsPtr) domCaps =3D NULL; + VIR_AUTOUNREF(virCapsPtr) caps =3D NULL; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg =3D virQEMUDriverGetConfig(d= river); virHashTablePtr domCapsCache =3D virQEMUCapsGetDomainCapsCache(qemuCap= s); struct virQEMUDriverSearchDomcapsData data =3D { .path =3D virQEMUCapsGetBinary(qemuCaps), @@ -1401,7 +1393,7 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr d= river, }; =20 if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; + return NULL; =20 domCaps =3D virHashSearch(domCapsCache, virQEMUDriverSearchDomcaps, &data, NULL); @@ -1409,24 +1401,19 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr= driver, /* hash miss, build new domcaps */ if (!(domCaps =3D virDomainCapsNew(data.path, data.machine, data.arch, data.virttype))) - goto cleanup; + return NULL; =20 if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, driver->privileged, cfg->firmwares, cfg->nfirmwares) < 0) - goto cleanup; + return NULL; =20 if (virHashAddEntry(domCapsCache, machine, domCaps) < 0) - goto cleanup; + return NULL; } =20 virObjectRef(domCaps); - VIR_STEAL_PTR(ret, domCaps); - cleanup: - virObjectUnref(domCaps); - virObjectUnref(cfg); - virObjectUnref(caps); - return ret; + VIR_RETURN_PTR(domCaps); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044878; cv=none; d=zoho.com; s=zohoarc; b=QeIHs5KV8UEAgUAjoxQN93/TOvCJ6lR1MDjiYLV5zlRqfHXGeWy9BKXiQgSjAkqLIulk9yXEiiIQ6dgDE8RO6T8menc8bt6NsDXKHub0gKk+MyGGijvyrO6R08lLAEWBbKAALBrO/WThgxk18Fw9DqBzbW38T7MXV6NjLayTzW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044878; 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:ARC-Authentication-Results; bh=FUlW6Mh9cDowPvcwRjajCo5AgxLumOce09ssS7Bw16I=; b=OJLn3YuL8U6hL7aU9DP6Y6fDxdmDL9NEJZSCS187/uV6oXIjuWf8fCj9iC6suz5S3LsbKy++uNvNjzaDCCV7h3kl80F9gWB+11f3/m1jSzinMMt736OLRrPKdEVAS6NFeHbns6rH+Sbh8qM6d9FdbTiJv6Po+tm3ptZjVTmJc9Q= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044878098771.7610617567648; Mon, 9 Sep 2019 09:01:18 -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 009368980F5; Mon, 9 Sep 2019 16:01:16 +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 BD75260167; Mon, 9 Sep 2019 16:01:15 +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 66746180BA9E; Mon, 9 Sep 2019 16:01:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0X73026530 for ; Mon, 9 Sep 2019 12:00:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 893EC6061E; Mon, 9 Sep 2019 16:00:33 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11B5F60A9F for ; Mon, 9 Sep 2019 16:00:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:26 +0200 Message-Id: <4ef78558a655fe95ad2a4fdacd4108b703a021c2.1568044773.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] lxcParseConfigString: Don't return success if post parse callback fails 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.6.2 (mx1.redhat.com [10.5.110.67]); Mon, 09 Sep 2019 16:01:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/lxc/lxc_native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 018eec6977..bb8c359147 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -1190,7 +1190,7 @@ lxcParseConfigString(const char *config, =20 if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt, NULL) < 0) - goto cleanup; + goto error; =20 goto cleanup; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 15:27:18 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 ARC-Seal: i=1; a=rsa-sha256; t=1568044883; cv=none; d=zoho.com; s=zohoarc; b=Per7uRLH291itfe0KNxFQKuLXtFBU/KfWhC1qlTGzWBDWPuTKKO7uECwCVCOt9e23nAFL24MiDoHn5l6viGNM5Hfq1RalGq4uS7Ogv6ePvunV/LXgqOl0LOsEpfk0bkvQsEcMT+HR9NBKBXknF7pb+z1XL1YjqITxvuby7jA6m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568044883; 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:ARC-Authentication-Results; bh=stcLNrGZyHRa/+r2GA8gIHSRQAbCwLZYAsUnMg4Nr24=; b=FBTAoJ03kgMhSte40n3PtLxYBVDLGh9s46Lhy9aBD1zHymCO810IPpI4o6cGwfiuLPYWIklnH6PIzHPBcqvfDX9jKd2QCgd6OcxPhLAbSvAHXbozbHtkUGBqczUI6YlJeKfP4mOXTRT+ek7b3l7yw6/QkVXmd853UE27dyW8fxE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568044883302810.2191557266768; Mon, 9 Sep 2019 09:01:23 -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 C82D9C057E9F; Mon, 9 Sep 2019 16:01:20 +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 934AD3DAD; Mon, 9 Sep 2019 16:01:20 +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 32ECB2551D; Mon, 9 Sep 2019 16:01:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x89G0YB6026548 for ; Mon, 9 Sep 2019 12:00:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8105D60623; Mon, 9 Sep 2019 16:00:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7D1560A9F for ; Mon, 9 Sep 2019 16:00:33 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Sep 2019 18:00:27 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/6] lib: Define and use autofree for virConfPtr 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.32]); Mon, 09 Sep 2019 16:01:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/bhyve/bhyve_conf.c | 10 +--- src/libvirt-admin.c | 3 +- src/libvirt.c | 4 +- src/libxl/libxl_conf.c | 22 +++----- src/libxl/libxl_driver.c | 8 +-- src/libxl/xen_xl.c | 33 +++++------ src/libxl/xen_xm.c | 19 +++---- src/locking/lock_daemon_config.c | 7 +-- src/locking/lock_driver_lockd.c | 18 +++--- src/locking/lock_driver_sanlock.c | 3 +- src/logging/log_daemon_config.c | 7 +-- src/lxc/lxc_conf.c | 16 ++---- src/lxc/lxc_native.c | 15 ++--- src/qemu/qemu_conf.c | 47 +++++++--------- src/remote/remote_daemon_config.c | 14 ++--- src/security/security_selinux.c | 4 +- src/util/virconf.h | 2 + src/vmx/vmx.c | 3 +- tests/virconftest.c | 93 +++++++++++++------------------ tests/xlconfigtest.c | 8 +-- tests/xmconfigtest.c | 8 +-- tools/virt-login-shell-helper.c | 3 +- 22 files changed, 133 insertions(+), 214 deletions(-) diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c index ee9427ea18..946be4a811 100644 --- a/src/bhyve/bhyve_conf.c +++ b/src/bhyve/bhyve_conf.c @@ -70,8 +70,7 @@ int virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg, const char *filename) { - virConfPtr conf; - int ret =3D -1; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (access(filename, R_OK) =3D=3D -1) { VIR_INFO("Could not read bhyve config file %s", filename); @@ -83,12 +82,9 @@ virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg, =20 if (virConfGetValueString(conf, "firmware_dir", &cfg->firmwareDir) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 virBhyveDriverConfigPtr diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index ba88f09824..9d5c5b1b7b 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -223,7 +223,7 @@ virAdmConnectOpen(const char *name, unsigned int flags) char *sock_path =3D NULL; char *alias =3D NULL; virAdmConnectPtr conn =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; char *uristr =3D NULL; =20 if (virAdmInitialize() < 0) @@ -272,7 +272,6 @@ virAdmConnectOpen(const char *name, unsigned int flags) cleanup: VIR_FREE(sock_path); VIR_FREE(uristr); - virConfFree(conf); return conn; =20 error: diff --git a/src/libvirt.c b/src/libvirt.c index 9650aaa453..19bc05638f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -859,7 +859,7 @@ virConnectOpenInternal(const char *name, size_t i; int res; virConnectPtr ret; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; char *uristr =3D NULL; =20 ret =3D virGetConnect(); @@ -1069,14 +1069,12 @@ virConnectOpenInternal(const char *name, goto failed; } =20 - virConfFree(conf); VIR_FREE(uristr); =20 return ret; =20 failed: VIR_FREE(uristr); - virConfFree(conf); virObjectUnref(ret); =20 return NULL; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 766a726ebc..c76704a11d 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1864,8 +1864,7 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver) int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, const char *filename) { - virConfPtr conf =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 /* defaults for keepalive messages */ cfg->keepAliveInterval =3D 5; @@ -1880,30 +1879,25 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr = cfg, } =20 if (!(conf =3D virConfReadFile(filename, 0))) - goto cleanup; + return -1; =20 /* setup autoballoon */ if (libxlGetAutoballoonConf(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueString(conf, "lock_manager", &cfg->lockManagerName)= < 0) - goto cleanup; + return -1; =20 if (virConfGetValueInt(conf, "keepalive_interval", &cfg->keepAliveInte= rval) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount)= < 0) - goto cleanup; + return -1; =20 if (virConfGetValueBool(conf, "nested_hvm", &cfg->nested_hvm) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virConfFree(conf); - return ret; + return -1; =20 + return 0; } =20 /* diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index fccc1f42e8..45de6b24c6 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2675,7 +2675,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, libxlDriverPrivatePtr driver =3D conn->privateData; libxlDriverConfigPtr cfg =3D libxlDriverConfigGet(driver); virDomainDefPtr def =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; char *xml =3D NULL; =20 virCheckFlags(0, NULL); @@ -2712,8 +2712,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, =20 cleanup: virDomainDefFree(def); - if (conf) - virConfFree(conf); virObjectUnref(cfg); return xml; } @@ -2727,7 +2725,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, con= st char * nativeFormat, libxlDriverPrivatePtr driver =3D conn->privateData; libxlDriverConfigPtr cfg =3D libxlDriverConfigGet(driver); virDomainDefPtr def =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; int len =3D MAX_CONFIG_SIZE; char *ret =3D NULL; =20 @@ -2764,8 +2762,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, con= st char * nativeFormat, =20 cleanup: virDomainDefFree(def); - if (conf) - virConfFree(conf); virObjectUnref(cfg); return ret; } diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index ca094d30c2..3a41a4ad00 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -2198,52 +2198,47 @@ xenFormatXLDomainChannels(virConfPtr conf, virDomai= nDefPtr def) virConfPtr xenFormatXL(virDomainDefPtr def, virConnectPtr conn) { - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (!(conf =3D virConfNew())) - goto cleanup; + return NULL; =20 if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLOS(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLCPUID(conf, def) < 0) - goto cleanup; + return NULL; =20 #ifdef LIBXL_HAVE_VNUMA if (xenFormatXLDomainVnuma(conf, def) < 0) - goto cleanup; + return NULL; #endif =20 #ifdef LIBXL_HAVE_BUILDINFO_GRANT_LIMITS if (xenFormatXLGntLimits(conf, def) < 0) - goto cleanup; + return NULL; #endif =20 if (xenFormatXLDomainDisks(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLSpice(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLInputDevs(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLUSB(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLUSBController(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXLDomainChannels(conf, def) < 0) - goto cleanup; + return NULL; =20 - return conf; - - cleanup: - if (conf) - virConfFree(conf); - return NULL; + VIR_RETURN_PTR(conf); } diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index b8dee0917e..0296e78ddc 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -599,27 +599,22 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def) { - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (!(conf =3D virConfNew())) - goto cleanup; + return NULL; =20 if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXMOS(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXMDisks(conf, def) < 0) - goto cleanup; + return NULL; =20 if (xenFormatXMInputDevs(conf, def) < 0) - goto cleanup; + return NULL; =20 - return conf; - - cleanup: - if (conf) - virConfFree(conf); - return NULL; + VIR_RETURN_PTR(conf); } diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_con= fig.c index 03feeb02a5..8df7cf89cd 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -114,8 +114,7 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data, const char *filename, bool allow_missing) { - virConfPtr conf; - int ret; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (allow_missing && access(filename, R_OK) =3D=3D -1 && @@ -126,7 +125,5 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data, if (!conf) return -1; =20 - ret =3D virLockDaemonConfigLoadOptions(data, conf); - virConfFree(conf); - return ret; + return virLockDaemonConfigLoadOptions(data, conf); } diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index 164f83eb4b..67f512a64e 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -81,8 +81,7 @@ static virLockManagerLockDaemonDriverPtr driver; =20 static int virLockManagerLockDaemonLoadConfig(const char *configFile) { - virConfPtr conf; - int ret =3D -1; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (access(configFile, R_OK) =3D=3D -1) { if (errno !=3D ENOENT) { @@ -98,25 +97,22 @@ static int virLockManagerLockDaemonLoadConfig(const cha= r *configFile) return -1; =20 if (virConfGetValueBool(conf, "auto_disk_leases", &driver->autoDiskLea= se) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueString(conf, "file_lockspace_dir", &driver->fileLoc= kSpaceDir) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueString(conf, "lvm_lockspace_dir", &driver->lvmLockS= paceDir) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueString(conf, "scsi_lockspace_dir", &driver->scsiLoc= kSpaceDir) < 0) - goto cleanup; + return -1; =20 driver->requireLeaseForDisks =3D !driver->autoDiskLease; if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requ= ireLeaseForDisks) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 =20 diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index ff0c9be8f7..85a23c7642 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -119,7 +119,7 @@ static int virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver, const char *configFile) { - virConfPtr conf; + VIR_AUTOPTR(virConf) conf =3D NULL; int ret =3D -1; char *user =3D NULL; char *group =3D NULL; @@ -167,7 +167,6 @@ virLockManagerSanlockLoadConfig(virLockManagerSanlockDr= iverPtr driver, =20 ret =3D 0; cleanup: - virConfFree(conf); VIR_FREE(user); VIR_FREE(group); return ret; diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_confi= g.c index ec6d0686f4..c7dfa19b5d 100644 --- a/src/logging/log_daemon_config.c +++ b/src/logging/log_daemon_config.c @@ -120,8 +120,7 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data, const char *filename, bool allow_missing) { - virConfPtr conf; - int ret; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (allow_missing && access(filename, R_OK) =3D=3D -1 && @@ -132,7 +131,5 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data, if (!conf) return -1; =20 - ret =3D virLogDaemonConfigLoadOptions(data, conf); - virConfFree(conf); - return ret; + return virLogDaemonConfigLoadOptions(data, conf); } diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 2e4cc4f51a..9d1653f437 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -252,8 +252,7 @@ int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, const char *filename) { - virConfPtr conf; - int ret =3D -1; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 /* Avoid error from non-existent or unreadable file. */ if (access(filename, R_OK) =3D=3D -1) @@ -264,21 +263,18 @@ virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, return -1; =20 if (virConfGetValueBool(conf, "log_with_libvirtd", &cfg->log_libvirtd)= < 0) - goto cleanup; + return -1; =20 if (virConfGetValueString(conf, "security_driver", &cfg->securityDrive= rName) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueBool(conf, "security_default_confined", &cfg->secur= ityDefaultConfined) < 0) - goto cleanup; + return -1; =20 if (virConfGetValueBool(conf, "security_require_confined", &cfg->secur= ityRequireConfined) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index bb8c359147..f9d43a1b3e 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -1079,7 +1079,7 @@ lxcParseConfigString(const char *config, virDomainXMLOptionPtr xmlopt) { virDomainDefPtr vmdef =3D NULL; - virConfPtr properties =3D NULL; + VIR_AUTOPTR(virConf) properties =3D NULL; VIR_AUTOFREE(char *) value =3D NULL; =20 if (!(properties =3D virConfReadString(config, VIR_CONF_FLAG_LXC_FORMA= T))) @@ -1192,14 +1192,9 @@ lxcParseConfigString(const char *config, xmlopt, NULL) < 0) goto error; =20 - goto cleanup; - - error: - virDomainDefFree(vmdef); - vmdef =3D NULL; - - cleanup: - virConfFree(properties); - return vmdef; + + error: + virDomainDefFree(vmdef); + return NULL; } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f805991872..dd571cb3aa 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1000,8 +1000,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPt= r cfg, const char *filename, bool privileged) { - virConfPtr conf =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 /* Just check the file is readable before opening it, otherwise * libvirt emits an error. @@ -1012,67 +1011,63 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfig= Ptr cfg, } =20 if (!(conf =3D virConfReadFile(filename, 0))) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadDefaultTLSEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadVNCEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadNographicsEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadSPICEEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadSpecificTLSEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadSaveEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadProcessEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadDeviceEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadRPCEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadNetworkEntry(cfg, conf, filename) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadLogEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadNVRAMEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadGlusterDebugEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadSecurityEntry(cfg, conf, privileged) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadMemoryEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadSWTPMEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 if (virQEMUDriverConfigLoadCapsFiltersEntry(cfg, conf) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 =20 diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_c= onfig.c index b224e75a18..0eecb20c34 100644 --- a/src/remote/remote_daemon_config.c +++ b/src/remote/remote_daemon_config.c @@ -401,8 +401,7 @@ daemonConfigLoadFile(struct daemonConfig *data, const char *filename, bool allow_missing) { - virConfPtr conf; - int ret; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 if (allow_missing && access(filename, R_OK) =3D=3D -1 && @@ -413,23 +412,18 @@ daemonConfigLoadFile(struct daemonConfig *data, if (!conf) return -1; =20 - ret =3D daemonConfigLoadOptions(data, filename, conf); - virConfFree(conf); - return ret; + return daemonConfigLoadOptions(data, filename, conf); } =20 int daemonConfigLoadData(struct daemonConfig *data, const char *filename, const char *filedata) { - virConfPtr conf; - int ret; + VIR_AUTOPTR(virConf) conf =3D NULL; =20 conf =3D virConfReadString(filedata, 0); if (!conf) return -1; =20 - ret =3D daemonConfigLoadOptions(data, filename, conf); - virConfFree(conf); - return ret; + return daemonConfigLoadOptions(data, filename, conf); } diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index af7f62dfd9..e879fa39ab 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -635,7 +635,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, static int virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr) { - virConfPtr selinux_conf; + VIR_AUTOPTR(virConf) selinux_conf =3D NULL; virSecuritySELinuxDataPtr data =3D virSecurityManagerGetPrivateData(mg= r); =20 data->skipAllLabel =3D true; @@ -685,7 +685,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr m= gr) if (!(data->mcs =3D virHashCreate(10, NULL))) goto error; =20 - virConfFree(selinux_conf); return 0; =20 error: @@ -693,7 +692,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr m= gr) selabel_close(data->label_handle); data->label_handle =3D NULL; # endif - virConfFree(selinux_conf); VIR_FREE(data->domain_context); VIR_FREE(data->file_context); VIR_FREE(data->content_context); diff --git a/src/util/virconf.h b/src/util/virconf.h index ed9d404a1e..4c0c633aad 100644 --- a/src/util/virconf.h +++ b/src/util/virconf.h @@ -22,6 +22,7 @@ =20 #include "virutil.h" #include "virenum.h" +#include "virautoclean.h" =20 /** * virConfType: @@ -80,6 +81,7 @@ virConfPtr virConfReadFile(const char *filename, unsigned= int flags); virConfPtr virConfReadString(const char *memory, unsigned int flags); int virConfFree(virConfPtr conf); +VIR_DEFINE_AUTOPTR_FUNC(virConf, virConfFree); void virConfFreeValue(virConfValuePtr val); virConfValuePtr virConfGetValue(virConfPtr conf, const char *setting); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 2cc0995783..d8f15b5b47 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1275,7 +1275,7 @@ virVMXParseConfig(virVMXContext *ctx, const char *vmx) { bool success =3D false; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; char *encoding =3D NULL; char *utf8; virDomainDefPtr def =3D NULL; @@ -1850,7 +1850,6 @@ virVMXParseConfig(virVMXContext *ctx, def =3D NULL; } =20 - virConfFree(conf); VIR_FREE(encoding); VIR_FREE(sched_cpu_affinity); VIR_FREE(sched_cpu_shares); diff --git a/tests/virconftest.c b/tests/virconftest.c index cc2b26687c..f61e4ea9d5 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -33,7 +33,7 @@ static int testConfRoundTrip(const void *opaque) { const char *name =3D opaque; int ret =3D -1; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; int len =3D 10000; char *buffer =3D NULL; char *srcfile =3D NULL; @@ -68,7 +68,6 @@ static int testConfRoundTrip(const void *opaque) VIR_FREE(srcfile); VIR_FREE(dstfile); VIR_FREE(buffer); - virConfFree(conf); return ret; } =20 @@ -80,7 +79,7 @@ static int testConfMemoryNoNewline(const void *opaque ATT= RIBUTE_UNUSED) "string =3D 'foo'\n" \ "uint =3D 12345"; =20 - virConfPtr conf =3D virConfReadString(srcdata, 0); + VIR_AUTOPTR(virConf) conf =3D virConfReadString(srcdata, 0); int ret =3D -1; virConfValuePtr val; unsigned long long llvalue; @@ -134,7 +133,6 @@ static int testConfMemoryNoNewline(const void *opaque A= TTRIBUTE_UNUSED) ret =3D 0; cleanup: VIR_FREE(str); - virConfFree(conf); return ret; } =20 @@ -150,8 +148,7 @@ static int testConfParseInt(const void *opaque ATTRIBUT= E_UNUSED) "ssize_t =3D -87539319\n" \ "string =3D \"foo\"\n"; =20 - int ret =3D -1; - virConfPtr conf =3D virConfReadString(srcdata, 0); + VIR_AUTOPTR(virConf) conf =3D virConfReadString(srcdata, 0); int iv; unsigned int ui; size_t s; @@ -165,40 +162,40 @@ static int testConfParseInt(const void *opaque ATTRIB= UTE_UNUSED) if (virConfGetValueType(conf, "int") !=3D VIR_CONF_LLONG) { fprintf(stderr, "expected a long for 'int'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueInt(conf, "int", &iv) < 0) - goto cleanup; + return -1; =20 if (iv !=3D -1729) { fprintf(stderr, "Expected -1729 got %d\n", iv); - goto cleanup; + return -1; } =20 if (virConfGetValueInt(conf, "string", &iv) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 =20 if (virConfGetValueType(conf, "uint") !=3D VIR_CONF_ULLONG) { fprintf(stderr, "expected a unsigned long for 'uint'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueUInt(conf, "uint", &ui) < 0) - goto cleanup; + return -1; =20 if (ui !=3D 1729) { fprintf(stderr, "Expected 1729 got %u\n", ui); - goto cleanup; + return -1; } =20 if (virConfGetValueUInt(conf, "string", &ui) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 =20 @@ -206,20 +203,20 @@ static int testConfParseInt(const void *opaque ATTRIB= UTE_UNUSED) if (virConfGetValueType(conf, "llong") !=3D VIR_CONF_LLONG) { fprintf(stderr, "expected a long for 'llong'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueLLong(conf, "llong", &l) < 0) - goto cleanup; + return -1; =20 if (l !=3D -6963472309248) { fprintf(stderr, "Expected -6963472309248 got %lld\n", l); - goto cleanup; + return -1; } =20 if (virConfGetValueLLong(conf, "string", &l) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 =20 @@ -227,20 +224,20 @@ static int testConfParseInt(const void *opaque ATTRIB= UTE_UNUSED) if (virConfGetValueType(conf, "ullong") !=3D VIR_CONF_ULLONG) { fprintf(stderr, "expected a unsigned long for 'ullong'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueULLong(conf, "ullong", &ul) < 0) - goto cleanup; + return -1; =20 if (ul !=3D 6963472309248) { fprintf(stderr, "Expected 6963472309248 got %llu\n", ul); - goto cleanup; + return -1; } =20 if (virConfGetValueULLong(conf, "string", &ul) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 =20 @@ -248,20 +245,20 @@ static int testConfParseInt(const void *opaque ATTRIB= UTE_UNUSED) if (virConfGetValueType(conf, "size_t") !=3D VIR_CONF_ULLONG) { fprintf(stderr, "expected a unsigned long for 'size_T'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueSizeT(conf, "size_t", &s) < 0) - goto cleanup; + return -1; =20 if (s !=3D 87539319) { fprintf(stderr, "Expected 87539319 got %zu\n", s); - goto cleanup; + return -1; } =20 if (virConfGetValueSizeT(conf, "string", &s) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 =20 @@ -269,26 +266,23 @@ static int testConfParseInt(const void *opaque ATTRIB= UTE_UNUSED) if (virConfGetValueType(conf, "ssize_t") !=3D VIR_CONF_LLONG) { fprintf(stderr, "expected a unsigned long for 'ssize_t'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueSSizeT(conf, "ssize_t", &ss) < 0) - goto cleanup; + return -1; =20 if (ss !=3D -87539319) { fprintf(stderr, "Expected -87539319 got %zd\n", ss); - goto cleanup; + return -1; } =20 if (virConfGetValueSSizeT(conf, "string", &ss) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED) @@ -299,8 +293,7 @@ static int testConfParseBool(const void *opaque ATTRIBU= TE_UNUSED) "int =3D 6963472309248\n" \ "string =3D \"foo\"\n"; =20 - int ret =3D -1; - virConfPtr conf =3D virConfReadString(srcdata, 0); + VIR_AUTOPTR(virConf) conf =3D virConfReadString(srcdata, 0); bool f =3D true; bool t =3D false; =20 @@ -310,15 +303,15 @@ static int testConfParseBool(const void *opaque ATTRI= BUTE_UNUSED) if (virConfGetValueType(conf, "false") !=3D VIR_CONF_ULLONG) { fprintf(stderr, "expected a long for 'false'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueBool(conf, "false", &f) < 0) - goto cleanup; + return -1; =20 if (f !=3D false) { fprintf(stderr, "Expected 0 got %d\n", f); - goto cleanup; + return -1; } =20 =20 @@ -326,34 +319,30 @@ static int testConfParseBool(const void *opaque ATTRI= BUTE_UNUSED) if (virConfGetValueType(conf, "true") !=3D VIR_CONF_ULLONG) { fprintf(stderr, "expected a long for 'true'\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueBool(conf, "true", &t) < 0) - goto cleanup; + return -1; =20 if (t !=3D true) { fprintf(stderr, "Expected 1 got %d\n", t); - goto cleanup; + return -1; } =20 =20 =20 if (virConfGetValueBool(conf, "int", &t) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 if (virConfGetValueBool(conf, "string", &t) !=3D -1) { fprintf(stderr, "Expected error for 'string' param\n"); - goto cleanup; + return -1; } =20 - - ret =3D 0; - cleanup: - virConfFree(conf); - return ret; + return 0; } =20 =20 @@ -364,7 +353,7 @@ static int testConfParseString(const void *opaque ATTRI= BUTE_UNUSED) "string =3D \"foo\"\n"; =20 int ret =3D -1; - virConfPtr conf =3D virConfReadString(srcdata, 0); + VIR_AUTOPTR(virConf) conf =3D virConfReadString(srcdata, 0); char *str =3D NULL; =20 if (!conf) @@ -392,7 +381,6 @@ static int testConfParseString(const void *opaque ATTRI= BUTE_UNUSED) ret =3D 0; cleanup: VIR_FREE(str); - virConfFree(conf); return ret; } =20 @@ -404,7 +392,7 @@ static int testConfParseStringList(const void *opaque A= TTRIBUTE_UNUSED) "string =3D \"foo\"\n"; =20 int ret =3D -1; - virConfPtr conf =3D virConfReadString(srcdata, 0); + VIR_AUTOPTR(virConf) conf =3D virConfReadString(srcdata, 0); char **str =3D NULL; =20 if (!conf) @@ -457,7 +445,6 @@ static int testConfParseStringList(const void *opaque A= TTRIBUTE_UNUSED) ret =3D 0; cleanup: virStringListFree(str); - virConfFree(conf); return ret; } =20 diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c index ae0db71293..80ac9b2c9a 100644 --- a/tests/xlconfigtest.c +++ b/tests/xlconfigtest.c @@ -68,7 +68,7 @@ static int testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) { char *gotxlcfgData =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; virConnectPtr conn =3D NULL; int wrote =3D 4096; int ret =3D -1; @@ -113,8 +113,6 @@ testCompareParseXML(const char *xlcfg, const char *xml,= bool replaceVars) fail: VIR_FREE(replacedXML); VIR_FREE(gotxlcfgData); - if (conf) - virConfFree(conf); virDomainDefFree(def); virObjectUnref(conn); =20 @@ -130,7 +128,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml= , bool replaceVars) { char *xlcfgData =3D NULL; char *gotxml =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; int ret =3D -1; virConnectPtr conn; virDomainDefPtr def =3D NULL; @@ -165,8 +163,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml= , bool replaceVars) ret =3D 0; =20 fail: - if (conf) - virConfFree(conf); VIR_FREE(replacedXML); VIR_FREE(xlcfgData); VIR_FREE(gotxml); diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 3137dc564c..484b023a1c 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -41,7 +41,7 @@ static int testCompareParseXML(const char *xmcfg, const char *xml) { char *gotxmcfgData =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; int ret =3D -1; virConnectPtr conn =3D NULL; int wrote =3D 4096; @@ -76,8 +76,6 @@ testCompareParseXML(const char *xmcfg, const char *xml) =20 fail: VIR_FREE(gotxmcfgData); - if (conf) - virConfFree(conf); virDomainDefFree(def); virObjectUnref(conn); =20 @@ -89,7 +87,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml) { char *xmcfgData =3D NULL; char *gotxml =3D NULL; - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; int ret =3D -1; virDomainDefPtr def =3D NULL; =20 @@ -111,8 +109,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml) ret =3D 0; =20 fail: - if (conf) - virConfFree(conf); VIR_FREE(xmcfgData); VIR_FREE(gotxml); virDomainDefFree(def); diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index d062c07a27..1a621ae53c 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -152,7 +152,7 @@ hideErrorFunc(void *opaque ATTRIBUTE_UNUSED, int main(int argc, char **argv) { - virConfPtr conf =3D NULL; + VIR_AUTOPTR(virConf) conf =3D NULL; const char *login_shell_path =3D conf_file; pid_t cpid =3D -1; int ret =3D EXIT_CANCELED; @@ -414,7 +414,6 @@ main(int argc, char **argv) for (i =3D 0; i < nfdlist; i++) VIR_FORCE_CLOSE(fdlist[i]); VIR_FREE(fdlist); - virConfFree(conf); if (dom) virDomainFree(dom); if (conn) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list