From nobody Mon Feb 9 09:01:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617285495; cv=none; d=zohomail.com; s=zohoarc; b=lko46mejKG8SCzimI53IENRmMSzXOpKDcXsVJv/RmWF0naqefXBwQQugnEHD1NrSsPQVrG9JfSthULifz14vjVLOaxKz2/qPdd04p6Hc+WWAQ4rgGhzlw5McNziGZpN3NfWJ4s74BjX9NfBGUjhttxMQF9MzFaNsP6cWjjMBBM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617285495; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6c2ZSYkKaLgZGVN5Sp97YWcg4Pq+IDjMFEVo0Ghpj+c=; b=X8+4NJ/VRHh/gaeqZR3zwQAV3YTu4er/hucTvCU2nLdsZJJwtCq8AevntDxLH+/17fn9ta2VRFMoAi4c264g7QlwOUsTEO0iS+jZ+5o/vUqYUHJhheympMuiTvh1mo1c/OHD/8rLXA+DJtNXIGsbazmJ6W4I9Zwmj1ovJMAxqTc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1617285495324345.3758191193522; Thu, 1 Apr 2021 06:58:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4-Xq0WLiO2P6uQnjMhv0pUhA-1; Thu, 01 Apr 2021 09:55:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EA628B99C0; Thu, 1 Apr 2021 13:55:03 +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 64EC2608DB; Thu, 1 Apr 2021 13:55:03 +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 191D71809C83; Thu, 1 Apr 2021 13:55:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 131DsGOU023601 for ; Thu, 1 Apr 2021 09:54:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29E5F5C237; Thu, 1 Apr 2021 13:54:16 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80B3C5C1A1 for ; Thu, 1 Apr 2021 13:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617285494; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6c2ZSYkKaLgZGVN5Sp97YWcg4Pq+IDjMFEVo0Ghpj+c=; b=doTXTAVgHKzFaPSfJ5uwHtukLIFok5Pj0CRs+3fTgqeJWRG0dJm0p6U1z/WhD3v5QcCcC2 btyo6zX+XO24J4Y5gMo1oNmo4zHp0CecGp3nTXtPwwfbmTJBWSV1uSvn5/syDnN9zdpS63 lj6nnaqMTiTur/K1rJ/qo0z29leK5cA= X-MC-Unique: Xq0WLiO2P6uQnjMhv0pUhA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 30/39] util: virresctrl: Use automatic memory freeing Date: Thu, 1 Apr 2021 15:52:29 +0200 Message-Id: <1120958a9539bf702860589bed244db384c05449.1617285119.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/util/virresctrl.c | 53 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 53c202f99f..6d8e669852 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -641,7 +641,7 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr resc= trl) { int ret =3D -1; int rv =3D -1; - virResctrlInfoMemBWPtr i_membw =3D NULL; + g_autofree virResctrlInfoMemBWPtr i_membw =3D NULL; /* query memory bandwidth allocation info */ i_membw =3D g_new0(virResctrlInfoMemBW, 1); @@ -684,7 +684,6 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr resc= trl) resctrl->membw_info =3D g_steal_pointer(&i_membw); ret =3D 0; cleanup: - VIR_FREE(i_membw); return ret; } @@ -705,10 +704,10 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) { int ret =3D -1; int rv =3D -1; - char *featurestr =3D NULL; - char **features =3D NULL; + g_autofree char *featurestr =3D NULL; + g_auto(GStrv) features =3D NULL; size_t nfeatures =3D 0; - virResctrlInfoMongrpPtr info_monitor =3D NULL; + g_autofree virResctrlInfoMongrpPtr info_monitor =3D NULL; info_monitor =3D g_new0(virResctrlInfoMongrp, 1); @@ -767,9 +766,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) ret =3D 0; cleanup: - VIR_FREE(featurestr); - g_strfreev(features); - VIR_FREE(info_monitor); return ret; } @@ -1480,7 +1476,7 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInf= oPtr resctrl, virResctrlAllocPtr alloc, char *line) { - char **mbs =3D NULL; + g_auto(GStrv) mbs =3D NULL; char *tmp =3D NULL; size_t nmbs =3D 0; size_t i; @@ -1517,7 +1513,6 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInf= oPtr resctrl, ret =3D 0; cleanup: - g_strfreev(mbs); return ret; } @@ -1595,7 +1590,7 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr re= sctrl, { char *tmp =3D strchr(cache, '=3D'); unsigned int cache_id =3D 0; - virBitmapPtr mask =3D NULL; + g_autoptr(virBitmap) mask =3D NULL; int ret =3D -1; if (!tmp) @@ -1632,7 +1627,6 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr re= sctrl, ret =3D 0; cleanup: - virBitmapFree(mask); return ret; } @@ -1642,7 +1636,7 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resct= rl, virResctrlAllocPtr alloc, char *line) { - char **caches =3D NULL; + g_auto(GStrv) caches =3D NULL; char *tmp =3D NULL; unsigned int level =3D 0; int type =3D -1; @@ -1691,7 +1685,6 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resct= rl, ret =3D 0; cleanup: - g_strfreev(caches); return ret; } @@ -1701,7 +1694,7 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc, const char *schemata) { - char **lines =3D NULL; + g_auto(GStrv) lines =3D NULL; size_t nlines =3D 0; size_t i =3D 0; int ret =3D -1; @@ -1717,7 +1710,6 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl, ret =3D 0; cleanup: - g_strfreev(lines); return ret; } @@ -1945,7 +1937,7 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, { unsigned long long *size =3D alloc->levels[level]->types[type]->sizes[= cache]; virBitmapPtr a_mask =3D NULL; - virBitmapPtr f_mask =3D NULL; + g_autoptr(virBitmap) f_mask =3D NULL; unsigned long long need_bits; size_t i =3D 0; ssize_t pos =3D -1; @@ -2049,7 +2041,6 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, ret =3D 0; cleanup: - virBitmapFree(a_mask); return ret; } @@ -2185,8 +2176,8 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, { int ret =3D -1; unsigned int level =3D 0; - virResctrlAllocPtr alloc_free =3D NULL; - virResctrlAllocPtr alloc_default =3D NULL; + g_autoptr(virResctrlAlloc) alloc_free =3D NULL; + g_autoptr(virResctrlAlloc) alloc_default =3D NULL; alloc_free =3D virResctrlAllocGetUnused(resctrl); if (!alloc_free) @@ -2251,8 +2242,6 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl, ret =3D 0; cleanup: - virObjectUnref(alloc_free); - virObjectUnref(alloc_default); return ret; } @@ -2328,8 +2317,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; @@ -2377,8 +2366,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, ret =3D 0; cleanup: virResctrlUnlock(lockfd); - VIR_FREE(alloc_str); - VIR_FREE(schemata_path); return ret; } @@ -2387,8 +2374,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; if (!path) { @@ -2410,8 +2397,6 @@ virResctrlAddPID(const char *path, ret =3D 0; cleanup: - VIR_FREE(tasks); - VIR_FREE(pidstr); return ret; } @@ -2631,8 +2616,7 @@ 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; struct dirent *ent =3D NULL; virResctrlMonitorStatsPtr stat =3D NULL; size_t nresources =3D g_strv_length((char **) resources); @@ -2650,10 +2634,9 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monit= or, *nstats =3D 0; while (virDirRead(dirp, &ent, datapath) > 0) { + g_autofree char *filepath =3D NULL; char *node_id =3D NULL; - VIR_FREE(filepath); - /* Looking for directory that contains resource utilization * information file. The directory name is arranged in format * "mon__". For example, "mon_L3_00" and @@ -2712,8 +2695,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, ret =3D 0; cleanup: - VIR_FREE(datapath); - VIR_FREE(filepath); virResctrlMonitorStatsFree(stat); return ret; } --=20 2.29.2