From nobody Mon Sep 16 19:35:59 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678264136; cv=none; d=zohomail.com; s=zohoarc; b=IPG4VQAJeD19DKATlHMsCZK7gAKobx7kpChvDy/yJ42bzXlKIGzAUhLhOJstf8ldFOu3qmTsehOqRXOyGZkSrCEkFPSzXmXTatfAE9RaKabp1wQDk6KKIWCqFcwQxi00go4Ia7qlm8R9hO/lKaKrl+uK2rVZ8mgF+ViRQy6p5m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678264136; 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=IlhkdD4t4gVkH1bbFivcC1GFLhehkvfBwYPyi8uo6Q0=; b=Hss23tmCHs0GNkHQVlS/x68mBXBe5CNcIdxrT2Y5XsTuBOcfnxGKV3Au3rlklL1NUtXH9RLs+5dCNRCTBVr9sa7XaBfhUcszBF2tlw1F7Cigi+7dkUkVHilPC/asIj36Vjv+XXON+wnm0ZA0ahAnGNEsfo7ns0aTp29qblTP0VI= 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=pass header.from= (p=none dis=none) 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 1678264136246159.73143754230512; Wed, 8 Mar 2023 00:28:56 -0800 (PST) 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-631-XncL9KGtMTSMCYQ1f0Gkug-1; Wed, 08 Mar 2023 03:28:48 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42255100B180; Wed, 8 Mar 2023 08:28:45 +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 1A10E4411E; Wed, 8 Mar 2023 08:28:44 +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 9ABDB1946A41; Wed, 8 Mar 2023 08:28:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9818D19465B1 for ; Wed, 8 Mar 2023 08:28:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2B585440DF; Wed, 8 Mar 2023 08:28:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0E56440DD for ; Wed, 8 Mar 2023 08:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678264135; 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=IlhkdD4t4gVkH1bbFivcC1GFLhehkvfBwYPyi8uo6Q0=; b=dexC6bzD/XMJDzQO5gQulmSzqgsnwGD58rjoA4LJh+1dBK0hH5Mo7eolwC/0GXv9tKu7M8 +4ra2S4AzaS/W5g8fwaicxUb3JPADre5WNhLCTUVhlh3QtvSpOCEqBkv1s611qoVmVEeFL PSS/Opm9cz9jN1Mk/MGWoh11V+BpCpM= X-MC-Unique: XncL9KGtMTSMCYQ1f0Gkug-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] virscsihost: use g_autofree more Date: Wed, 8 Mar 2023 09:28:18 +0100 Message-Id: <5287d426e50f9f9a9d49bab44c1175a1638d6d9c.1678264076.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1678264137412100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Remove some obvious uses of VIR_FREE() in favor of automatic cleanup. This also means, that some variables affected are brought into the inner most block, so that automatic cleanup is effective. Signed-off-by: Michal Privoznik --- src/util/virscsihost.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index 969cdd9f79..54ba9ddb9b 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -95,18 +95,19 @@ 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; char *p =3D NULL; char *ret =3D NULL; - char *buf =3D NULL; - char *unique_path =3D NULL; unsigned int read_unique_id; =20 if (virDirOpen(&dir, prefix) < 0) return NULL; =20 while (virDirRead(dir, &entry, prefix) > 0) { + g_autofree char *host_link =3D NULL; + g_autofree char *host_path =3D NULL; + g_autofree char *unique_path =3D NULL; + g_autofree char *buf =3D NULL; + if (!virFileIsLink(entry->d_name)) continue; =20 @@ -116,17 +117,12 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, goto cleanup; =20 if (!strstr(host_path, parentaddr)) { - VIR_FREE(host_link); - VIR_FREE(host_path); continue; } - VIR_FREE(host_link); - VIR_FREE(host_path); =20 unique_path =3D g_strdup_printf("%s/%s/unique_id", prefix, entry->= d_name); =20 if (!virFileExists(unique_path)) { - VIR_FREE(unique_path); continue; } =20 @@ -139,10 +135,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, if (virStrToLong_ui(buf, NULL, 10, &read_unique_id) < 0) goto cleanup; =20 - VIR_FREE(buf); - if (read_unique_id !=3D unique_id) { - VIR_FREE(unique_path); continue; } =20 @@ -151,10 +144,6 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, } =20 cleanup: - VIR_FREE(unique_path); - VIR_FREE(host_link); - VIR_FREE(host_path); - VIR_FREE(buf); return ret; } =20 @@ -226,7 +215,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); @@ -239,7 +228,6 @@ virSCSIHostGetNameByParentaddr(unsigned int domain, } =20 cleanup: - VIR_FREE(parentaddr); return name; } =20 --=20 2.39.2