From nobody Mon Apr 29 12:38:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1604961305; cv=none; d=zohomail.com; s=zohoarc; b=AqEnhfQIbscXGH7Jsz6GH96uyZ9xHG34wm1FsIJlw5sETJFYbD1+/sL9oAgOoH94StSW62Gd4cimdthuqKoEgSAvIemM/JX7cLDwD4gV0LTwmQBfUfRK16Jzb6248nqXdZkv5H4GYPOiKdtF++CL/W/jdVPzr4aInNhqHgLpKaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604961305; 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=6GoPLRSlTcCdZ2J2GUBxI+9uaycjnZ+0ijCZcWWmkN8=; b=a17bYTbY/tfQvuUl2EMDkuPFPIPLTiwh8zpJYqsBOJmWDGeN29/NrzWrNxJK6o235h/iEQQdtAfLEXKWy0VG2KGCiKH1OFF8JweDNmeT5NX5ZSrJs/VOAjQ+Lo0nTaU8aiF0d1cPttt+ByCmPkrBSPRIquTdnSmwbN+BNF6nOk4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1604961305532414.0655835050046; Mon, 9 Nov 2020 14:35:05 -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-205-YBFWHgxePf-7MNYArHUJrQ-1; Mon, 09 Nov 2020 17:35:01 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE6A510866A8; Mon, 9 Nov 2020 22:34:54 +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 E3EA05D9D2; Mon, 9 Nov 2020 22:34:50 +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 02849180610F; Mon, 9 Nov 2020 22:34:45 +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 0A9MYbUT029669 for ; Mon, 9 Nov 2020 17:34:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 86B2C1112843; Mon, 9 Nov 2020 22:34:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 829A01112840 for ; Mon, 9 Nov 2020 22:34:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 2A6DE8007DF for ; Mon, 9 Nov 2020 22:34:34 +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-217-nPehrzM0PXi1HeQ5fS_r3g-1; Mon, 09 Nov 2020 17:34:31 -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 0A9MYTVO001862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Nov 2020 16:34:29 -0600 Received: (from rgahagan@localhost) by ginger.cs.utexas.edu (8.15.2/8.15.2/Submit) id 0A9MYTjv014019; Mon, 9 Nov 2020 16:34:29 -0600 X-MC-Unique: YBFWHgxePf-7MNYArHUJrQ-1 X-MC-Unique: nPehrzM0PXi1HeQ5fS_r3g-1 From: Ryan Gahagan To: libvir-list@redhat.com Subject: [PATCH] util: convert char pointers to use g_autofree Date: Mon, 9 Nov 2020 16:34:22 -0600 Message-Id: <20201109223422.13955-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]); Mon, 09 Nov 2020 16:34:29 -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.14 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. files updated are: - src/util/vircgroupv1.c - src/util/virhostcpu.c - src/util/virlockspace.c - src/util/virmacmap.c - src/util/virresctrl.c - src/util/virsysinfo.c Related issue: https://gitlab.com/libvirt/libvirt/-/issues/11 Signed-off-by: bschoney Signed-off-by: Barrett Schonefeld Reviewed-by: Han Han --- src/util/vircgroupv1.c | 3 +-- src/util/virhostcpu.c | 4 +--- src/util/virlockspace.c | 6 ++---- src/util/virmacmap.c | 3 +-- src/util/virresctrl.c | 25 ++++++++----------------- src/util/virsysinfo.c | 9 +++------ 6 files changed, 16 insertions(+), 34 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/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/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/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/virsysinfo.c b/src/util/virsysinfo.c index 217f842a37..e1336bf566 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -532,9 +532,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 +593,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 --=20 2.29.0