From nobody Mon Feb 9 01:16:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1573728230; cv=none; d=zoho.com; s=zohoarc; b=Bo3zi8L/usZMc7Kc5zD/VLPT5ZMxKAyDPEev3OELEfLkpofRy8DD3V8VzT6zOe9XJUb3zxwUzKEKHfrYqGrLud3hshC7qc8/BVx2UpP76Glaq93CWibZfmw2L5BPVSoEGRuxmtbc3t3OKC4Ey2jcnjlwiNKp8uFnhS4Y24oMp0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728230; 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=GVnmBoVL8ism24xFyIx2f1MXWv1CyBqle26TQP8RhFA=; b=GaCuKnJgB1q8Ditnmy4hf5MdFbI+MImoxUrynRt1VogFywM43CRCjpJwg9KP2SILRI0lEHUrs9FHtjeJNPZH/pDblU0H/IG79o1bTETsHjU38psY1p/7guwCibWvCq6yAXmc64HrdPTqce9pZv5TrmF+mf5IjWj4CNg9zYKSh0g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1573728230074377.6141230953017; Thu, 14 Nov 2019 02:43:50 -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-37-_R5_cI1aOEKygj9TMGfnsw-1; Thu, 14 Nov 2019 05:43:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B34C805A75; Thu, 14 Nov 2019 10:43:41 +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 261965C548; Thu, 14 Nov 2019 10:43:41 +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 D6D6B18089D0; Thu, 14 Nov 2019 10:43:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAhdlX005624 for ; Thu, 14 Nov 2019 05:43:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 51DFC5F762; Thu, 14 Nov 2019 10:43:39 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D10BE67596 for ; Thu, 14 Nov 2019 10:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728229; 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=GVnmBoVL8ism24xFyIx2f1MXWv1CyBqle26TQP8RhFA=; b=LwoTZ6kT/DalliZS4fyIE6q+uowW5njg2kcDgsYOW9I7Zd+K5JBiHyh8eMfV5p5ceAm2/k OV3t6C5cJu3GJp+WI3ZLyCUx1POZ2GlVYzgTdkkpe2WWqR2Bqol+rcTIOHA84ivc1Teq/E gI6nx9XcnlbCU3aI+dbDl/VSUtGLlGM= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:30 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] util: file: Use g_autofree in virFindFileInPath 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.16 X-MC-Unique: _R5_cI1aOEKygj9TMGfnsw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Simplify the final lookup loop by freeing memory automatically and thus being able to directly return the result. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- src/util/virfile.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index b1aeaa5851..072a299b39 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1634,10 +1634,9 @@ char * virFindFileInPath(const char *file) { const char *origpath =3D NULL; - char *path =3D NULL; + g_autofree char *path =3D NULL; char *pathiter; char *pathseg; - char *fullpath =3D NULL; if (file =3D=3D NULL) return NULL; @@ -1672,14 +1671,12 @@ virFindFileInPath(const char *file) */ pathiter =3D path; while ((pathseg =3D strsep(&pathiter, ":")) !=3D NULL) { - fullpath =3D g_strdup_printf("%s/%s", pathseg, file); + g_autofree char *fullpath =3D g_strdup_printf("%s/%s", pathseg, fi= le); if (virFileIsExecutable(fullpath)) - break; - VIR_FREE(fullpath); + return g_steal_pointer(&fullpath); } - VIR_FREE(path); - return fullpath; + return NULL; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list