From nobody Sat Apr 20 02:14:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=cs.utexas.edu ARC-Seal: i=1; a=rsa-sha256; t=1605739660; cv=none; d=zohomail.com; s=zohoarc; b=gJRBgdlL4X5D5nP9T+j1cj6kkUP/EmpL2o2XQzuo8aqNU5fTm+7irzRwGAUb9xsno971GmbSpJw9ZDKWU1MIyT42tIO2CtpEKRuFcgma/h0E7xam7/EbHs6pW4OWiZkSByxk4ZoK5dhZj/eyQ16HDM8nFCLlC7yWjPOaHmA2gbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605739660; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9MUI1h623jQZ9e2tOP7Hh2yzS2l9hqm4QZIiBirrvwQ=; b=SJpSJsVg7mNQkneuvbcqXBmCDrRke9s1QmcethUrESuNQftP8wRpi7ZBZ0sfH88f4Y7bZU8M6LGgP0HKR/sq2SGNebTpia3XIORYMeEXGoYuQz38uTBwKc+zsOlAD1BnCf6gSAP4/YUoMHwbpGPjpg2/AVPmXlKJv8bY7T3DonA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 16057396606565.287841383784212; Wed, 18 Nov 2020 14:47:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-KjI1u0f2P0aWkCQ-tvX9SQ-1; Wed, 18 Nov 2020 17:47:36 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 425138049D4; Wed, 18 Nov 2020 22:47: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 D060360BE2; Wed, 18 Nov 2020 22:47:29 +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 3680044A56; Wed, 18 Nov 2020 22:47:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AIMlQiv016039 for ; Wed, 18 Nov 2020 17:47:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 61908112D19B; Wed, 18 Nov 2020 22:47:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CECD112D19A for ; Wed, 18 Nov 2020 22:47:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0BF6A858F11 for ; Wed, 18 Nov 2020 22:47:24 +0000 (UTC) Received: from newman.cs.utexas.edu (newman.cs.utexas.edu [128.83.139.110]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-rKnrqVpsNjqs1Pm7DW4ayQ-1; Wed, 18 Nov 2020 17:47:21 -0500 Received: from ginger.cs.utexas.edu (ginger.cs.utexas.edu [128.83.144.229]) by newman.cs.utexas.edu (8.14.4/8.14.4/Debian-4.1ubuntu1.1) with ESMTP id 0AIMlIjF022236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Nov 2020 16:47:19 -0600 Received: (from rgahagan@localhost) by ginger.cs.utexas.edu (8.15.2/8.15.2/Submit) id 0AIMlIxL025585; Wed, 18 Nov 2020 16:47:18 -0600 X-MC-Unique: KjI1u0f2P0aWkCQ-tvX9SQ-1 X-MC-Unique: rKnrqVpsNjqs1Pm7DW4ayQ-1 From: Ryan Gahagan To: libvir-list@redhat.com Subject: [PATCH] util: convert char pointers to use g_autofree Date: Wed, 18 Nov 2020 16:47:17 -0600 Message-Id: <20201118224717.25527-1-rgahagan@cs.utexas.edu> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (newman.cs.utexas.edu [128.83.139.110]); Wed, 18 Nov 2020 16:47:19 -0600 (CST) X-Virus-Scanned: clamav-milter 0.100.3 at newman X-Virus-Status: Clean X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Barrett Schonefeld X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Barrett Schonefeld additional conversions to the GLib API in src/util per issue #11. Related issue: https://gitlab.com/libvirt/libvirt/-/issues/11 Signed-off-by: Barrett Schonefeld --- src/util/vircgroupv1.c | 3 +- src/util/virdnsmasq.c | 43 ++++++++------------- src/util/virfile.c | 9 ++--- src/util/virhostcpu.c | 4 +- src/util/virlockspace.c | 6 +-- src/util/virlog.c | 12 ++---- src/util/virmacmap.c | 3 +- src/util/virnetdevbandwidth.c | 48 ++++++++--------------- src/util/virresctrl.c | 25 ++++-------- src/util/virrotatingfile.c | 11 ++---- src/util/virscsihost.c | 25 +++++------- src/util/virsecret.c | 14 +++---- src/util/virstorageencryption.c | 19 +++------ src/util/virstoragefilebackend.c | 4 +- src/util/virsysinfo.c | 18 +++------ src/util/viruri.c | 7 +--- src/util/virutil.c | 66 +++++++++++--------------------- src/util/virvhba.c | 57 ++++++++++----------------- src/util/virxml.c | 7 +--- 19 files changed, 130 insertions(+), 251 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 731e9d61d4..984cd50409 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1549,7 +1549,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, unsigned long long *unevictable) { int ret =3D -1; - char *stat =3D NULL; + g_autofree char *stat =3D NULL; char *line =3D NULL; unsigned long long cacheVal =3D 0; unsigned long long activeAnonVal =3D 0; @@ -1614,7 +1614,6 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, ret =3D 0; =20 cleanup: - VIR_FREE(stat); return ret; } =20 diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 9030f9218a..93bc4a129f 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -164,7 +164,7 @@ addnhostsWrite(const char *path, dnsmasqAddnHost *hosts, unsigned int nhosts) { - char *tmp; + g_autofree char *tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i, j; @@ -180,7 +180,7 @@ addnhostsWrite(const char *path, istmp =3D false; if (!(f =3D fopen(path, "w"))) { rc =3D -errno; - goto cleanup; + return rc; } } =20 @@ -192,7 +192,7 @@ addnhostsWrite(const char *path, if (istmp) unlink(tmp); =20 - goto cleanup; + return rc; } =20 for (j =3D 0; j < hosts[i].nhostnames; j++) { @@ -203,7 +203,7 @@ addnhostsWrite(const char *path, if (istmp) unlink(tmp); =20 - goto cleanup; + return rc; } } =20 @@ -214,24 +214,21 @@ addnhostsWrite(const char *path, if (istmp) unlink(tmp); =20 - goto cleanup; + return rc; } } =20 if (VIR_FCLOSE(f) =3D=3D EOF) { rc =3D -errno; - goto cleanup; + return rc; } =20 if (istmp && rename(tmp, path) < 0) { rc =3D -errno; unlink(tmp); - goto cleanup; + return rc; } =20 - cleanup: - VIR_FREE(tmp); - return rc; } =20 @@ -364,7 +361,7 @@ hostsfileWrite(const char *path, dnsmasqDhcpHost *hosts, unsigned int nhosts) { - char *tmp; + g_autofree char *tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i; @@ -380,7 +377,7 @@ hostsfileWrite(const char *path, istmp =3D false; if (!(f =3D fopen(path, "w"))) { rc =3D -errno; - goto cleanup; + return rc; } } =20 @@ -392,24 +389,21 @@ hostsfileWrite(const char *path, if (istmp) unlink(tmp); =20 - goto cleanup; + return rc; } } =20 if (VIR_FCLOSE(f) =3D=3D EOF) { rc =3D -errno; - goto cleanup; + return rc; } =20 if (istmp && rename(tmp, path) < 0) { rc =3D -errno; unlink(tmp); - goto cleanup; + return rc; } =20 - cleanup: - VIR_FREE(tmp); - return rc; } =20 @@ -686,15 +680,13 @@ static int dnsmasqCapsSetFromFile(dnsmasqCapsPtr caps, const char *path) { int ret =3D -1; - char *buf =3D NULL; + g_autofree char *buf =3D NULL; =20 if (virFileReadAll(path, 1024 * 1024, &buf) < 0) - goto cleanup; + return ret; =20 ret =3D dnsmasqCapsSetFromBuffer(caps, buf); =20 - cleanup: - VIR_FREE(buf); return ret; } =20 @@ -704,7 +696,9 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) int ret =3D -1; struct stat sb; virCommandPtr cmd =3D NULL; - char *help =3D NULL, *version =3D NULL, *complete =3D NULL; + g_autofree char *help =3D NULL; + g_autofree char *version =3D NULL; + g_autofree char *complete =3D NULL; =20 if (!caps || caps->noRefresh) return 0; @@ -749,9 +743,6 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) =20 cleanup: virCommandFree(cmd); - VIR_FREE(help); - VIR_FREE(version); - VIR_FREE(complete); return ret; } =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index f57272ca2f..38207f1948 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3328,9 +3328,9 @@ virFileIsSharedFixFUSE(const char *path, FILE *f =3D NULL; struct mntent mb; char mntbuf[1024]; - char *mntDir =3D NULL; - char *mntType =3D NULL; - char *canonPath =3D NULL; + g_autofree char *mntDir =3D NULL; + g_autofree char *mntType =3D NULL; + g_autofree char *canonPath =3D NULL; size_t maxMatching =3D 0; int ret =3D -1; =20 @@ -3381,9 +3381,6 @@ virFileIsSharedFixFUSE(const char *path, =20 ret =3D 0; cleanup: - VIR_FREE(canonPath); - VIR_FREE(mntType); - VIR_FREE(mntDir); endmntent(f); return ret; } diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index c531d65f86..4f6c3390ce 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -87,7 +87,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum, int *nparams) { const char *sysctl_name; - long *cpu_times; + g_autofree long *cpu_times =3D NULL; struct clockinfo clkinfo; size_t i, j, cpu_times_size, clkinfo_size; int cpu_times_num, offset, hz, stathz, ret =3D -1; @@ -172,8 +172,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum, ret =3D 0; =20 cleanup: - VIR_FREE(cpu_times); - return ret; } =20 diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index b90e13f506..71d5dfb83e 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -515,7 +515,7 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspac= e, const char *resname) { int ret =3D -1; - char *respath =3D NULL; + g_autofree char *respath =3D NULL; =20 VIR_DEBUG("lockspace=3D%p resname=3D%s", lockspace, resname); =20 @@ -538,7 +538,6 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspac= e, =20 cleanup: virMutexUnlock(&lockspace->lock); - VIR_FREE(respath); return ret; } =20 @@ -547,7 +546,7 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspac= e, const char *resname) { int ret =3D -1; - char *respath =3D NULL; + g_autofree char *respath =3D NULL; =20 VIR_DEBUG("lockspace=3D%p resname=3D%s", lockspace, resname); =20 @@ -575,7 +574,6 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspac= e, =20 cleanup: virMutexUnlock(&lockspace->lock); - VIR_FREE(respath); return ret; } =20 diff --git a/src/util/virlog.c b/src/util/virlog.c index 6b7a4512e9..2bf606b8c5 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -505,8 +505,8 @@ virLogVMessage(virLogSourcePtr source, va_list vargs) { static bool logInitMessageStderr =3D true; - char *str =3D NULL; - char *msg =3D NULL; + g_autofree char *str =3D NULL; + g_autofree char *msg =3D NULL; char timestamp[VIR_TIME_STRING_BUFLEN]; size_t i; int saved_errno =3D errno; @@ -528,7 +528,8 @@ virLogVMessage(virLogSourcePtr source, if (source->serial < virLogFiltersSerial) virLogSourceUpdate(source); if (priority < source->priority) - goto cleanup; + errno =3D saved_errno; + return; =20 /* * serialize the error message, add level and timestamp @@ -601,11 +602,6 @@ virLogVMessage(virLogSourcePtr source, str, msg, (void *) STDERR_FILENO); } virLogUnlock(); - - cleanup: - VIR_FREE(str); - VIR_FREE(msg); - errno =3D saved_errno; } =20 =20 diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index f9047d0fb1..e68742de10 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -129,7 +129,7 @@ static int virMacMapLoadFile(virMacMapPtr mgr, const char *file) { - char *map_str =3D NULL; + g_autofree char *map_str =3D NULL; virJSONValuePtr map =3D NULL; int map_str_len =3D 0; size_t i; @@ -189,7 +189,6 @@ virMacMapLoadFile(virMacMapPtr mgr, =20 ret =3D 0; cleanup: - VIR_FREE(map_str); virJSONValueFree(map); return ret; } diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index c8eb5cfc79..2ae03e8edc 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -102,7 +102,7 @@ virNetDevBandwidthManipulateFilter(const char *ifname, bool create_new) { int ret =3D -1; - char *filter_id =3D NULL; + g_autofree char *filter_id =3D NULL; virCommandPtr cmd =3D NULL; unsigned char ifmac[VIR_MAC_BUFLEN]; char *mac[2] =3D {NULL, NULL}; @@ -157,7 +157,6 @@ virNetDevBandwidthManipulateFilter(const char *ifname, cleanup: VIR_FREE(mac[1]); VIR_FREE(mac[0]); - VIR_FREE(filter_id); virCommandFree(cmd); return ret; } @@ -195,9 +194,9 @@ virNetDevBandwidthSet(const char *ifname, int ret =3D -1; virNetDevBandwidthRatePtr rx =3D NULL, tx =3D NULL; /* From domain POV= */ virCommandPtr cmd =3D NULL; - char *average =3D NULL; - char *peak =3D NULL; - char *burst =3D NULL; + g_autofree char *average =3D NULL; + g_autofree char *peak =3D NULL; + g_autofree char *burst =3D NULL; =20 if (!bandwidth) { /* nothing to be enabled */ @@ -385,9 +384,6 @@ virNetDevBandwidthSet(const char *ifname, =20 cleanup: virCommandFree(cmd); - VIR_FREE(average); - VIR_FREE(peak); - VIR_FREE(burst); return ret; } =20 @@ -533,10 +529,10 @@ virNetDevBandwidthPlug(const char *brname, { int ret =3D -1; virCommandPtr cmd =3D NULL; - char *class_id =3D NULL; - char *qdisc_id =3D NULL; - char *floor =3D NULL; - char *ceil =3D NULL; + g_autofree char *class_id =3D NULL; + g_autofree char *qdisc_id =3D NULL; + g_autofree char *floor =3D NULL; + g_autofree char *ceil =3D NULL; char ifmacStr[VIR_MAC_STRING_BUFLEN]; =20 if (id <=3D 2) { @@ -586,10 +582,6 @@ virNetDevBandwidthPlug(const char *brname, ret =3D 0; =20 cleanup: - VIR_FREE(ceil); - VIR_FREE(floor); - VIR_FREE(qdisc_id); - VIR_FREE(class_id); virCommandFree(cmd); return ret; } @@ -610,8 +602,8 @@ virNetDevBandwidthUnplug(const char *brname, int ret =3D -1; int cmd_ret =3D 0; virCommandPtr cmd =3D NULL; - char *class_id =3D NULL; - char *qdisc_id =3D NULL; + g_autofree char *class_id =3D NULL; + g_autofree char *qdisc_id =3D NULL; =20 if (id <=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid class ID %d"), i= d); @@ -645,8 +637,6 @@ virNetDevBandwidthUnplug(const char *brname, ret =3D 0; =20 cleanup: - VIR_FREE(qdisc_id); - VIR_FREE(class_id); virCommandFree(cmd); return ret; } @@ -673,9 +663,9 @@ virNetDevBandwidthUpdateRate(const char *ifname, { int ret =3D -1; virCommandPtr cmd =3D NULL; - char *class_id =3D NULL; - char *rate =3D NULL; - char *ceil =3D NULL; + g_autofree char *class_id =3D NULL; + g_autofree char *rate =3D NULL; + g_autofree char *ceil =3D NULL; =20 class_id =3D g_strdup_printf("1:%x", id); rate =3D g_strdup_printf("%llukbps", new_rate); @@ -696,9 +686,6 @@ virNetDevBandwidthUpdateRate(const char *ifname, =20 cleanup: virCommandFree(cmd); - VIR_FREE(class_id); - VIR_FREE(rate); - VIR_FREE(ceil); return ret; } =20 @@ -725,16 +712,13 @@ virNetDevBandwidthUpdateFilter(const char *ifname, unsigned int id) { int ret =3D -1; - char *class_id =3D NULL; + g_autofree char *class_id =3D NULL; =20 class_id =3D g_strdup_printf("1:%x", id); =20 if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id, class_id, true, true) < 0) - goto cleanup; + return ret; =20 - ret =3D 0; - cleanup: - VIR_FREE(class_id); - return ret; + return 0; } diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index d3087b98c1..1c2d175295 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -709,7 +709,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) { int ret =3D -1; int rv =3D -1; - char *featurestr =3D NULL; + g_autofree char *featurestr =3D NULL; char **features =3D NULL; size_t nfeatures =3D 0; virResctrlInfoMongrpPtr info_monitor =3D NULL; @@ -771,7 +771,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) =20 ret =3D 0; cleanup: - VIR_FREE(featurestr); g_strfreev(features); VIR_FREE(info_monitor); return ret; @@ -1736,7 +1735,7 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl, const char *groupname, virResctrlAllocPtr *alloc) { - char *schemata =3D NULL; + g_autofree char *schemata =3D NULL; int rv =3D virFileReadValueString(&schemata, SYSFS_RESCTRL_PATH "/%s/schemata", groupname); @@ -1753,11 +1752,9 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl, if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0) goto error; =20 - VIR_FREE(schemata); return 0; =20 error: - VIR_FREE(schemata); virObjectUnref(*alloc); *alloc =3D NULL; return -1; @@ -2354,8 +2351,8 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc, const char *machinename) { - char *schemata_path =3D NULL; - char *alloc_str =3D NULL; + g_autofree char *schemata_path =3D NULL; + g_autofree char *alloc_str =3D NULL; int ret =3D -1; int lockfd =3D -1; =20 @@ -2403,8 +2400,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, ret =3D 0; cleanup: virResctrlUnlock(lockfd); - VIR_FREE(alloc_str); - VIR_FREE(schemata_path); return ret; } =20 @@ -2413,8 +2408,8 @@ static int virResctrlAddPID(const char *path, pid_t pid) { - char *tasks =3D NULL; - char *pidstr =3D NULL; + g_autofree char *tasks =3D NULL; + g_autofree char *pidstr =3D NULL; int ret =3D 0; =20 if (!path) { @@ -2436,8 +2431,6 @@ virResctrlAddPID(const char *path, =20 ret =3D 0; cleanup: - VIR_FREE(tasks); - VIR_FREE(pidstr); return ret; } =20 @@ -2657,8 +2650,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, size_t i =3D 0; unsigned long long val =3D 0; g_autoptr(DIR) dirp =3D NULL; - char *datapath =3D NULL; - char *filepath =3D NULL; + g_autofree char *datapath =3D NULL; + g_autofree char *filepath =3D NULL; struct dirent *ent =3D NULL; virResctrlMonitorStatsPtr stat =3D NULL; =20 @@ -2737,8 +2730,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, =20 ret =3D 0; cleanup: - VIR_FREE(datapath); - VIR_FREE(filepath); virResctrlMonitorStatsFree(stat); return ret; } diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c index 9f1ef17c3e..6fe5fa3154 100644 --- a/src/util/virrotatingfile.c +++ b/src/util/virrotatingfile.c @@ -362,8 +362,8 @@ static int virRotatingFileWriterRollover(virRotatingFileWriterPtr file) { size_t i; - char *nextpath =3D NULL; - char *thispath =3D NULL; + g_autofree char *nextpath =3D NULL; + g_autofree char *thispath =3D NULL; int ret =3D -1; =20 VIR_DEBUG("Rollover %s", file->basepath); @@ -373,7 +373,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr = file) virReportSystemError(errno, _("Unable to remove %s"), file->basepath); - goto cleanup; + return ret; } } else { nextpath =3D g_strdup_printf("%s.%zu", file->basepath, file->maxba= ckup - 1); @@ -391,7 +391,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr = file) virReportSystemError(errno, _("Unable to rename %s to %s"), thispath, nextpath); - goto cleanup; + return ret; } =20 VIR_FREE(nextpath); @@ -402,9 +402,6 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr = file) VIR_DEBUG("Rollover done %s", file->basepath); =20 ret =3D 0; - cleanup: - VIR_FREE(nextpath); - VIR_FREE(thispath); return ret; } =20 diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index 969cdd9f79..cad48b4059 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -95,12 +95,12 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_P= ATH; struct dirent *entry =3D NULL; g_autoptr(DIR) dir =3D NULL; - char *host_link =3D NULL; - char *host_path =3D NULL; + g_autofree char *host_link =3D NULL; + g_autofree char *host_path =3D NULL; char *p =3D NULL; char *ret =3D NULL; - char *buf =3D NULL; - char *unique_path =3D NULL; + g_autofree char *buf =3D NULL; + g_autofree char *unique_path =3D NULL; unsigned int read_unique_id; =20 if (virDirOpen(&dir, prefix) < 0) @@ -113,7 +113,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, host_link =3D g_strdup_printf("%s/%s", prefix, entry->d_name); =20 if (virFileResolveLink(host_link, &host_path) < 0) - goto cleanup; + return ret; =20 if (!strstr(host_path, parentaddr)) { VIR_FREE(host_link); @@ -131,13 +131,13 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, } =20 if (virFileReadAll(unique_path, 1024, &buf) < 0) - goto cleanup; + return ret; =20 if ((p =3D strchr(buf, '\n'))) *p =3D '\0'; =20 if (virStrToLong_ui(buf, NULL, 10, &read_unique_id) < 0) - goto cleanup; + return ret; =20 VIR_FREE(buf); =20 @@ -150,11 +150,6 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, break; } =20 - cleanup: - VIR_FREE(unique_path); - VIR_FREE(host_link); - VIR_FREE(host_path); - VIR_FREE(buf); return ret; } =20 @@ -226,7 +221,7 @@ virSCSIHostGetNameByParentaddr(unsigned int domain, unsigned int unique_id) { char *name =3D NULL; - char *parentaddr =3D NULL; + g_autofree char *parentaddr =3D NULL; =20 parentaddr =3D g_strdup_printf("%04x:%02x:%02x.%01x", domain, bus, slo= t, function); @@ -235,11 +230,9 @@ virSCSIHostGetNameByParentaddr(unsigned int domain, _("Failed to find scsi_host using PCI '%s' " "and unique_id=3D'%u'"), parentaddr, unique_id); - goto cleanup; + return name; } =20 - cleanup: - VIR_FREE(parentaddr); return name; } =20 diff --git a/src/util/virsecret.c b/src/util/virsecret.c index 54d6bbcb7c..67c9b68215 100644 --- a/src/util/virsecret.c +++ b/src/util/virsecret.c @@ -65,8 +65,8 @@ int virSecretLookupParseSecret(xmlNodePtr secretnode, virSecretLookupTypeDefPtr def) { - char *uuid; - char *usage; + g_autofree char *uuid =3D NULL; + g_autofree char *usage =3D NULL; int ret =3D -1; =20 uuid =3D virXMLPropString(secretnode, "uuid"); @@ -74,20 +74,20 @@ virSecretLookupParseSecret(xmlNodePtr secretnode, if (uuid =3D=3D NULL && usage =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing secret uuid or usage attribute")); - goto cleanup; + return ret; } =20 if (uuid && usage) { virReportError(VIR_ERR_XML_ERROR, "%s", _("either secret uuid or usage expected")); - goto cleanup; + return ret; } =20 if (uuid) { if (virUUIDParse(uuid, def->u.uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid secret uuid '%s'"), uuid); - goto cleanup; + return ret; } def->type =3D VIR_SECRET_LOOKUP_TYPE_UUID; } else { @@ -96,10 +96,6 @@ virSecretLookupParseSecret(xmlNodePtr secretnode, def->type =3D VIR_SECRET_LOOKUP_TYPE_USAGE; } ret =3D 0; - - cleanup: - VIR_FREE(uuid); - VIR_FREE(usage); return ret; } =20 diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryptio= n.c index 399c6926bd..db886c1e76 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -142,7 +142,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt) virStorageEncryptionSecretPtr ret; - char *type_str =3D NULL; + g_autofree char *type_str =3D NULL; =20 ret =3D g_new0(virStorageEncryptionSecret, 1); =20 @@ -164,12 +164,9 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctx= t, if (virSecretLookupParseSecret(node, &ret->seclookupdef) < 0) goto cleanup; =20 - VIR_FREE(type_str); - return ret; =20 cleanup: - VIR_FREE(type_str); virStorageEncryptionSecretFree(ret); return NULL; } @@ -180,12 +177,12 @@ virStorageEncryptionInfoParseCipher(xmlNodePtr info_n= ode, virStorageEncryptionInfoDefPtr info) { int ret =3D -1; - char *size_str =3D NULL; + g_autofree char *size_str =3D NULL; =20 if (!(info->cipher_name =3D virXMLPropString(info_node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("cipher info missing 'name' attribute")); - goto cleanup; + return ret; } =20 if ((size_str =3D virXMLPropString(info_node, "size")) && @@ -193,22 +190,19 @@ virStorageEncryptionInfoParseCipher(xmlNodePtr info_n= ode, virReportError(VIR_ERR_XML_ERROR, _("cannot parse cipher size: '%s'"), size_str); - goto cleanup; + return ret; } =20 if (!size_str) { virReportError(VIR_ERR_XML_ERROR, "%s", _("cipher info missing 'size' attribute")); - goto cleanup; + return ret; } =20 info->cipher_mode =3D virXMLPropString(info_node, "mode"); info->cipher_hash =3D virXMLPropString(info_node, "hash"); =20 ret =3D 0; - - cleanup: - VIR_FREE(size_str); return ret; } =20 @@ -237,7 +231,7 @@ virStorageEncryptionParseNode(xmlNodePtr node, xmlNodePtr *nodes =3D NULL; virStorageEncryptionPtr encdef =3D NULL; virStorageEncryptionPtr ret =3D NULL; - char *format_str =3D NULL; + g_autofree char *format_str =3D NULL; int n; size_t i; =20 @@ -297,7 +291,6 @@ virStorageEncryptionParseNode(xmlNodePtr node, ret =3D g_steal_pointer(&encdef); =20 cleanup: - VIR_FREE(format_str); VIR_FREE(nodes); virStorageEncryptionFree(encdef); =20 diff --git a/src/util/virstoragefilebackend.c b/src/util/virstoragefileback= end.c index 2779b5c307..55c62b0212 100644 --- a/src/util/virstoragefilebackend.c +++ b/src/util/virstoragefilebackend.c @@ -51,7 +51,7 @@ virStorageFileLoadBackendModule(const char *name, const char *regfunc, bool forceload) { - char *modfile =3D NULL; + g_autofree char *modfile =3D NULL; int ret; =20 if (!(modfile =3D virFileFindResourceFull(name, @@ -64,8 +64,6 @@ virStorageFileLoadBackendModule(const char *name, =20 ret =3D virModuleLoad(modfile, regfunc, forceload); =20 - VIR_FREE(modfile); - return ret; } #endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS || WITH_STORAGE_GLUSTER */ diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 217f842a37..45a950c85a 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -393,7 +393,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinf= oDefPtr ret) const char *cur; char *eol, *tmp_base; virSysinfoProcessorDefPtr processor; - char *processor_type =3D NULL; + g_autofree char *processor_type =3D NULL; =20 if (!(tmp_base =3D strstr(base, "model name")) && !(tmp_base =3D strstr(base, "Processor"))) @@ -411,7 +411,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinf= oDefPtr ret) cur =3D strchr(base, ':') + 1; =20 if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) - goto error; + return -1; processor =3D &ret->processor[ret->nprocessor - 1]; =20 virSkipSpaces(&cur); @@ -424,12 +424,7 @@ virSysinfoParseARMProcessor(const char *base, virSysin= foDefPtr ret) base =3D cur; } =20 - VIR_FREE(processor_type); return 0; - - error: - VIR_FREE(processor_type); - return -1; } =20 /* virSysinfoRead for ARMv7 @@ -532,9 +527,9 @@ static int virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) { const char *tmp_base; - char *manufacturer =3D NULL; - char *procline =3D NULL; - char *ncpu =3D NULL; + g_autofree char *manufacturer =3D NULL; + g_autofree char *procline =3D NULL; + g_autofree char *ncpu =3D NULL; int result =3D -1; virSysinfoProcessorDefPtr processor; =20 @@ -593,9 +588,6 @@ virSysinfoParseS390Processor(const char *base, virSysin= foDefPtr ret) result =3D 0; =20 error: - VIR_FREE(manufacturer); - VIR_FREE(procline); - VIR_FREE(ncpu); return result; } =20 diff --git a/src/util/viruri.c b/src/util/viruri.c index 11753a0aef..d49821451e 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -209,7 +209,7 @@ char * virURIFormat(virURIPtr uri) { xmlURI xmluri; - char *tmpserver =3D NULL; + g_autofree char *tmpserver =3D NULL; char *ret; =20 memset(&xmluri, 0, sizeof(xmluri)); @@ -241,12 +241,9 @@ virURIFormat(virURIPtr uri) ret =3D (char *)xmlSaveUri(&xmluri); if (!ret) { virReportOOMError(); - goto cleanup; + return ret; } =20 - cleanup: - VIR_FREE(tmpserver); - return ret; } =20 diff --git a/src/util/virutil.c b/src/util/virutil.c index a0cd0f1bcd..a7c163ab94 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -598,7 +598,7 @@ char *virGetUserRuntimeDirectory(void) static int virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **she= ll, bool quiet) { - char *strbuf; + g_autofree char *strbuf =3D NULL; struct passwd pwbuf; struct passwd *pw =3D NULL; long val =3D sysconf(_SC_GETPW_R_SIZE_MAX); @@ -668,13 +668,12 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, c= har **dir, char **shell, bo if (shell) VIR_FREE(*shell); } - VIR_FREE(strbuf); return ret; } =20 static char *virGetGroupEnt(gid_t gid) { - char *strbuf; + g_autofree char *strbuf =3D NULL; char *ret; struct group grbuf; struct group *gr =3D NULL; @@ -717,7 +716,6 @@ static char *virGetGroupEnt(gid_t gid) } =20 ret =3D g_strdup(gr->gr_name); - VIR_FREE(strbuf); return ret; } =20 @@ -759,7 +757,7 @@ char *virGetGroupName(gid_t gid) static int virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok) { - char *strbuf =3D NULL; + g_autofree char *strbuf =3D NULL; struct passwd pwbuf; struct passwd *pw =3D NULL; long val =3D sysconf(_SC_GETPW_R_SIZE_MAX); @@ -775,7 +773,7 @@ virGetUserIDByName(const char *name, uid_t *uid, bool m= issing_ok) =20 while ((rc =3D getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) =3D= =3D ERANGE) { if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) - goto cleanup; + return ret; } =20 if (!pw) { @@ -788,16 +786,13 @@ virGetUserIDByName(const char *name, uid_t *uid, bool= missing_ok) } =20 ret =3D 1; - goto cleanup; + return ret; } =20 if (uid) *uid =3D pw->pw_uid; ret =3D 0; =20 - cleanup: - VIR_FREE(strbuf); - return ret; } =20 @@ -840,7 +835,7 @@ virGetUserID(const char *user, uid_t *uid) static int virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok) { - char *strbuf =3D NULL; + g_autofree char *strbuf =3D NULL; struct group grbuf; struct group *gr =3D NULL; long val =3D sysconf(_SC_GETGR_R_SIZE_MAX); @@ -856,7 +851,7 @@ virGetGroupIDByName(const char *name, gid_t *gid, bool = missing_ok) =20 while ((rc =3D getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) =3D= =3D ERANGE) { if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) - goto cleanup; + return ret; } =20 if (!gr) { @@ -869,16 +864,13 @@ virGetGroupIDByName(const char *name, gid_t *gid, boo= l missing_ok) } =20 ret =3D 1; - goto cleanup; + return ret; } =20 if (gid) *gid =3D gr->gr_gid; ret =3D 0; =20 - cleanup: - VIR_FREE(strbuf); - return ret; } =20 @@ -949,7 +941,7 @@ int virGetGroupList(uid_t uid, gid_t gid, gid_t **list) { int ret =3D 0; - char *user =3D NULL; + g_autofree char *user =3D NULL; gid_t primary; =20 *list =3D NULL; @@ -987,19 +979,17 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) =20 for (i =3D 0; i < ret; i++) { if ((*list)[i] =3D=3D gid) - goto cleanup; + return ret; } if (VIR_APPEND_ELEMENT(*list, i, gid) < 0) { ret =3D -1; VIR_FREE(*list); - goto cleanup; + return ret; } else { ret =3D i; } } =20 - cleanup: - VIR_FREE(user); return ret; } =20 @@ -1405,8 +1395,8 @@ virSetDeviceUnprivSGIO(const char *path, const char *sysfs_dir, int unpriv_sgio) { - char *sysfs_path =3D NULL; - char *val =3D NULL; + g_autofree char *sysfs_path =3D NULL; + g_autofree char *val =3D NULL; int ret =3D -1; int rc; =20 @@ -1416,20 +1406,17 @@ virSetDeviceUnprivSGIO(const char *path, if (!virFileExists(sysfs_path)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("unpriv_sgio is not supported by this kernel")); - goto cleanup; + return ret; } =20 val =3D g_strdup_printf("%d", unpriv_sgio); =20 if ((rc =3D virFileWriteStr(sysfs_path, val, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), sysfs_path); - goto cleanup; + return ret; } =20 ret =3D 0; - cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(val); return ret; } =20 @@ -1438,8 +1425,8 @@ virGetDeviceUnprivSGIO(const char *path, const char *sysfs_dir, int *unpriv_sgio) { - char *sysfs_path =3D NULL; - char *buf =3D NULL; + g_autofree char *sysfs_path =3D NULL; + g_autofree char *buf =3D NULL; char *tmp =3D NULL; int ret =3D -1; =20 @@ -1449,11 +1436,11 @@ virGetDeviceUnprivSGIO(const char *path, if (!virFileExists(sysfs_path)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("unpriv_sgio is not supported by this kernel")); - goto cleanup; + return ret; } =20 if (virFileReadAll(sysfs_path, 1024, &buf) < 0) - goto cleanup; + return ret; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -1461,13 +1448,10 @@ virGetDeviceUnprivSGIO(const char *path, if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse value of %s"), sysfs_path); - goto cleanup; + return ret; } =20 ret =3D 0; - cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(buf); return ret; } =20 @@ -1488,7 +1472,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr= , gid_t *gidPtr) int rc =3D -1; uid_t theuid; gid_t thegid; - char *tmp_label =3D NULL; + g_autofree char *tmp_label =3D NULL; char *sep =3D NULL; char *owner =3D NULL; char *group =3D NULL; @@ -1501,7 +1485,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr= , gid_t *gidPtr) virReportError(VIR_ERR_INVALID_ARG, _("Failed to parse uid and gid from '%s'"), label); - goto cleanup; + return rc; } *sep =3D '\0'; owner =3D tmp_label; @@ -1512,7 +1496,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr= , gid_t *gidPtr) */ if (virGetUserID(owner, &theuid) < 0 || virGetGroupID(group, &thegid) < 0) - goto cleanup; + return rc; =20 if (uidPtr) *uidPtr =3D theuid; @@ -1520,10 +1504,6 @@ virParseOwnershipIds(const char *label, uid_t *uidPt= r, gid_t *gidPtr) *gidPtr =3D thegid; =20 rc =3D 0; - - cleanup: - VIR_FREE(tmp_label); - return rc; } =20 diff --git a/src/util/virvhba.c b/src/util/virvhba.c index a4e88024d1..d8642ea041 100644 --- a/src/util/virvhba.c +++ b/src/util/virvhba.c @@ -49,7 +49,7 @@ bool virVHBAPathExists(const char *sysfs_prefix, int host) { - char *sysfs_path =3D NULL; + g_autofree char *sysfs_path =3D NULL; bool ret =3D false; =20 sysfs_path =3D g_strdup_printf("%s/host%d", @@ -58,7 +58,6 @@ virVHBAPathExists(const char *sysfs_prefix, if (virFileExists(sysfs_path)) ret =3D true; =20 - VIR_FREE(sysfs_path); return ret; } =20 @@ -79,8 +78,8 @@ bool virVHBAIsVportCapable(const char *sysfs_prefix, int host) { - char *scsi_host_path =3D NULL; - char *fc_host_path =3D NULL; + g_autofree char *scsi_host_path =3D NULL; + g_autofree char *fc_host_path =3D NULL; bool ret =3D false; =20 fc_host_path =3D g_strdup_printf("%s/host%d/%s", @@ -94,8 +93,6 @@ virVHBAIsVportCapable(const char *sysfs_prefix, if (virFileExists(fc_host_path) || virFileExists(scsi_host_path)) ret =3D true; =20 - VIR_FREE(fc_host_path); - VIR_FREE(scsi_host_path); return ret; } =20 @@ -115,19 +112,19 @@ virVHBAGetConfig(const char *sysfs_prefix, int host, const char *entry) { - char *sysfs_path =3D NULL; + g_autofree char *sysfs_path =3D NULL; char *p =3D NULL; - char *buf =3D NULL; + g_autofree char *buf =3D NULL; char *result =3D NULL; =20 sysfs_path =3D g_strdup_printf("%s/host%d/%s", sysfs_prefix ? sysfs_prefix : SYSFS_FC_HO= ST_PATH, host, entry); =20 if (!virFileExists(sysfs_path)) - goto cleanup; + return result; =20 if (virFileReadAll(sysfs_path, 1024, &buf) < 0) - goto cleanup; + return result; =20 if ((p =3D strchr(buf, '\n'))) *p =3D '\0'; @@ -139,9 +136,6 @@ virVHBAGetConfig(const char *sysfs_prefix, =20 result =3D g_strdup(p); =20 - cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(buf); return result; } =20 @@ -160,8 +154,8 @@ virVHBAFindVportHost(const char *sysfs_prefix) const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; g_autoptr(DIR) dir =3D NULL; struct dirent *entry =3D NULL; - char *max_vports =3D NULL; - char *vports =3D NULL; + g_autofree char *max_vports =3D NULL; + g_autofree char *vports =3D NULL; char *state =3D NULL; char *ret =3D NULL; =20 @@ -212,16 +206,13 @@ virVHBAFindVportHost(const char *sysfs_prefix) ((strlen(max_vports) =3D=3D strlen(vports)) && strcmp(max_vports, vports) > 0)) { ret =3D g_strdup(entry->d_name); - goto cleanup; + return ret; } =20 VIR_FREE(max_vports); VIR_FREE(vports); } =20 - cleanup: - VIR_FREE(max_vports); - VIR_FREE(vports); return ret; } =20 @@ -241,7 +232,8 @@ virVHBAManageVport(const int parent_host, int operation) { int ret =3D -1; - char *operation_path =3D NULL, *vport_name =3D NULL; + g_autofree char *operation_path =3D NULL; + g_autofree char *vport_name =3D NULL; const char *operation_file =3D NULL; =20 switch (operation) { @@ -254,7 +246,7 @@ virVHBAManageVport(const int parent_host, default: virReportError(VIR_ERR_OPERATION_INVALID, _("Invalid vport operation (%d)"), operation); - goto cleanup; + return ret; } =20 operation_path =3D g_strdup_printf("%s/host%d/%s", SYSFS_FC_HOST_PATH, @@ -270,7 +262,7 @@ virVHBAManageVport(const int parent_host, _("vport operation '%s' is not supported " "for host%d"), operation_file, parent_host); - goto cleanup; + return ret; } } =20 @@ -290,9 +282,6 @@ virVHBAManageVport(const int parent_host, "vport create/delete failed"), vport_name, operation_path); =20 - cleanup: - VIR_FREE(vport_name); - VIR_FREE(operation_path); return ret; } =20 @@ -315,8 +304,8 @@ vhbaReadCompareWWN(const char *prefix, const char *f_name, const char *wwn) { - char *path; - char *buf =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *buf =3D NULL; char *p; int ret =3D -1; =20 @@ -324,11 +313,11 @@ vhbaReadCompareWWN(const char *prefix, =20 if (!virFileExists(path)) { ret =3D 0; - goto cleanup; + return ret; } =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return ret; =20 if ((p =3D strchr(buf, '\n'))) *p =3D '\0'; @@ -342,10 +331,6 @@ vhbaReadCompareWWN(const char *prefix, else ret =3D 1; =20 - cleanup: - VIR_FREE(path); - VIR_FREE(buf); - return ret; } =20 @@ -407,7 +392,7 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; struct dirent *entry =3D NULL; g_autoptr(DIR) dir =3D NULL; - char *vport_create_path =3D NULL; + g_autofree char *vport_create_path =3D NULL; char *ret =3D NULL; =20 if (virDirOpen(&dir, prefix) < 0) @@ -428,7 +413,7 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, =20 if ((rc =3D vhbaReadCompareWWN(prefix, entry->d_name, "fabric_name", fabric_wwn)) < 0) - goto cleanup; + return ret; =20 if (rc =3D=3D 0) continue; @@ -437,8 +422,6 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, break; } =20 - cleanup: - VIR_FREE(vport_create_path); return ret; } =20 diff --git a/src/util/virxml.c b/src/util/virxml.c index a3b819d85c..7df50e4b4d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -696,8 +696,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED,= ...) unsigned int n, col; /* GCC warns if signed, because compared w= ith sizeof() */ int domcode =3D VIR_FROM_XML; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *contextstr =3D NULL; - char *pointerstr =3D NULL; + g_autofree char *contextstr =3D NULL; + g_autofree char *pointerstr =3D NULL; =20 =20 /* conditions for error printing */ @@ -763,9 +763,6 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED,= ...) contextstr, pointerstr); } - - VIR_FREE(contextstr); - VIR_FREE(pointerstr); } =20 /** --=20 2.29.0