From nobody Tue Apr 30 18:24:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1665412369; cv=none; d=zohomail.com; s=zohoarc; b=Y/SU2BGrR4UPCR5uLtWH172YGLi7pJex+TaOcecAEecX8LWtDVr6ryII7cALgJJb4xDoBA+HjrRq+ootmyiP3+LO1WXgk377LOg0YAUeT+PvMe8bEp+Tx5vtm54ZZepvq6v8ryyNBnn6dHjju/RH1VhUmEUSnRNvm8WgdJTwUUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665412369; 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=ogTRjmMqiAb0mSa0Uaa0TFmkEiYIyUCNW6X49oMDOec=; b=VVES8ZYqP6GwHKlSDgLTcsFZQuDFq0vcf2GBCsW3BPxX4AwCwqjk0UjjXBTOpdwvpzxWO2/BDVTVQlqM9GcrqgrhVJ1WBZEA/8FGQkkmKxl0x2brAgpI56I05LiWlU8mw7Vi+dRBY5z9EEoKI+djDTLtOPSy94YVvw5466K8SJE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1665412369555990.4169894340002; Mon, 10 Oct 2022 07:32:49 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-513-IzdKqiqMOiaSbtJGKJHzbg-1; Mon, 10 Oct 2022 10:32:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5262811E81; Mon, 10 Oct 2022 14:32:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 365A21121314; Mon, 10 Oct 2022 14:32:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 180F319465A0; Mon, 10 Oct 2022 14:32:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3737D1946597 for ; Mon, 10 Oct 2022 14:32:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2A52A2157F42; Mon, 10 Oct 2022 14:32:40 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2332B2157F41 for ; Mon, 10 Oct 2022 14:32:40 +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-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04E20101CC62 for ; Mon, 10 Oct 2022 14:32:40 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-doIQ6X2NPhiJBkgTzXuksg-1; Mon, 10 Oct 2022 10:32:35 -0400 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MmLqS0qstzVhqc for ; Mon, 10 Oct 2022 22:28:04 +0800 (CST) Received: from localhost.localdomain (10.175.124.27) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 10 Oct 2022 22:32:27 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665412368; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ogTRjmMqiAb0mSa0Uaa0TFmkEiYIyUCNW6X49oMDOec=; b=CvrUowN4y7ZMsca+ZlJnwNpLKR7OKoG/Ljmevv94v4XHy5EOn4JRdvEHR1QVRfdk0u6OhQ qvTl1Pa8WzxTp+QMsMkX7wbp6zc8526pgiWHQoG2u6ONnDRmzx0aY9HyrULu5dj5gYc4UO 9dpJmsMHJDzoYQSqw1zM5UNF+coMtj8= X-MC-Unique: IzdKqiqMOiaSbtJGKJHzbg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: doIQ6X2NPhiJBkgTzXuksg-1 From: Jiang Jiacheng To: Subject: [PATCH] capabilities: use g_autofree in capabilities.c Date: Mon, 10 Oct 2022 22:26:00 +0800 Message-ID: <20221010142600.1505257-1-jiangjiacheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected 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 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yubihong@huawei.com, zhengchuan@huawei.com, linyilu@huawei.com, jiangjiacheng@huawei.com, xiexiangyou@huawei.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665412371763100001 Content-Type: text/plain; charset="utf-8" Use g_autofree in capabilities.c for some pointers still using manual clean= up, and remove unnecessary cleanup. Signed-off-by: Jiang Jiacheng --- src/conf/capabilities.c | 44 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1a7ebf4a13..e56049687b 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1489,15 +1489,14 @@ virCapabilitiesGetNUMADistances(int node, virNumaDistance **distancesRet, int *ndistancesRet) { - virNumaDistance *tmp =3D NULL; + g_autofree virNumaDistance *tmp =3D NULL; int tmp_size =3D 0; - int ret =3D -1; - int *distances =3D NULL; + g_autofree int *distances =3D NULL; int ndistances =3D 0; size_t i; =20 if (virNumaGetDistances(node, &distances, &ndistances) < 0) - goto cleanup; + return -1; =20 if (!distances) { *distancesRet =3D NULL; @@ -1521,11 +1520,8 @@ virCapabilitiesGetNUMADistances(int node, *ndistancesRet =3D tmp_size; *distancesRet =3D g_steal_pointer(&tmp); tmp_size =3D 0; - ret =3D 0; - cleanup: - VIR_FREE(distances); - VIR_FREE(tmp); - return ret; + + return 0; } =20 static int @@ -1533,13 +1529,12 @@ virCapabilitiesGetNUMAPagesInfo(int node, virCapsHostNUMACellPageInfo **pageinfo, int *npageinfo) { - int ret =3D -1; - unsigned int *pages_size =3D NULL; - unsigned long long *pages_avail =3D NULL; + g_autofree unsigned int *pages_size =3D NULL; + g_autofree unsigned long long *pages_avail =3D NULL; size_t npages, i; =20 if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < = 0) - goto cleanup; + return -1; =20 *pageinfo =3D g_new0(virCapsHostNUMACellPageInfo, npages); *npageinfo =3D npages; @@ -1549,12 +1544,7 @@ virCapabilitiesGetNUMAPagesInfo(int node, (*pageinfo)[i].avail =3D pages_avail[i]; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(pages_avail); - VIR_FREE(pages_size); - return ret; + return 0; } =20 =20 @@ -1685,7 +1675,7 @@ static int virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps) { virNodeInfo nodeinfo; - virCapsHostNUMACellCPU *cpus; + g_autofree virCapsHostNUMACellCPU *cpus; int ncpus; int n, s, c, t; int id, cid; @@ -1741,7 +1731,6 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps) error: for (; cid >=3D 0; cid--) virBitmapFree(cpus[cid].siblings); - VIR_FREE(cpus); return -1; } =20 @@ -1925,7 +1914,7 @@ static int virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) { int n; - virCapsHostNUMACellCPU *cpus =3D NULL; + g_autofree virCapsHostNUMACellCPU *cpus =3D NULL; int ret =3D -1; int ncpus =3D 0; int max_node; @@ -1989,7 +1978,6 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) =20 cleanup: virCapabilitiesClearHostNUMACellCPUTopology(cpus, ncpus); - VIR_FREE(cpus); return ret; } =20 @@ -2034,22 +2022,18 @@ virCapabilitiesHostNUMANewHost(void) int virCapabilitiesInitPages(virCaps *caps) { - int ret =3D -1; - unsigned int *pages_size =3D NULL; + g_autofree unsigned int *pages_size =3D NULL; size_t npages; =20 if (virNumaGetPages(-1 /* Magic constant for overall info */, &pages_size, NULL, NULL, &npages) < 0) - goto cleanup; + return -1; =20 caps->host.pagesSize =3D g_steal_pointer(&pages_size); caps->host.nPagesSize =3D npages; npages =3D 0; =20 - ret =3D 0; - cleanup: - VIR_FREE(pages_size); - return ret; + return 0; } =20 =20 --=20 2.33.0