From nobody Mon Feb 9 19:52:39 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=1612448083; cv=none; d=zohomail.com; s=zohoarc; b=MaMga1c08NnV9Kg3BhsqKeaqxVjvqpSdG1p1F57GNwWlV+5Uk/oY1h9b9V/n91r0Nw4f436ZxxTvnQTR5mGWKt4Dvw/qwFoOEInXmkMCTU50zKDblTT1UJrYfrdNYC1MRqg+7FIDpSfdQuNvLhrwhlyggTo+H67ImEsbVHQ4FeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448083; 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=eOTwHmJVbXtjjbicSIzPaIjXhadTzO9lv3039kZNjYM=; b=GbW3S+hvwDF7dXTPNCpcOaVyy9uQLw3S85NUpPuyUVTNHcAfKAzDPUcN/AL2DMSwAQ85nPelGCL82pzjjqU3QG6AjyFT5tciyibvHg3KjNiE3H/r5ESO0vfwttXWi9KC+wiNf4ZNkUn3UiIKEYB3cMtLIlxdT90abp2n8Xk/nKU= 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 1612448083183266.1030395546186; Thu, 4 Feb 2021 06:14:43 -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-43-VQ0zNF7uM8eMAX68PdSFkw-1; Thu, 04 Feb 2021 09:14:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DB80107ACFC; Thu, 4 Feb 2021 14:13:56 +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 C0EE51971C; Thu, 4 Feb 2021 14:13:55 +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 7DBF01809C8F; Thu, 4 Feb 2021 14:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114EDrGe031618 for ; Thu, 4 Feb 2021 09:13:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EDF35D9EF; Thu, 4 Feb 2021 14:13:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20F8D5D9C9 for ; Thu, 4 Feb 2021 14:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448045; 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=eOTwHmJVbXtjjbicSIzPaIjXhadTzO9lv3039kZNjYM=; b=eGs9pg5pY03/ws2029h7gA9XH5pQi2rWFaFnaBhdHJ/1QlcO968S9+VANMAjJPaYmpwfk8 Gl7WBBX7Wpp2IcrEcGZnT7jg9WdpzafxnIZ6YWc8dVIHqnXCeEJWr8tTdW2aIAZyAWhLjO q+M2tyENtoitzFuu9JoPp+YrU2uPjQw= X-MC-Unique: VQ0zNF7uM8eMAX68PdSFkw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 06/12] vsh: Use g_auto() for string lists returned in readline command/options generators Date: Thu, 4 Feb 2021 15:13:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.23 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" There are two functions that are used to generate completion lists: vshReadlineCommandGenerator() for command names and vshReadlineOptionsGenerator() for --options for given command. Both return a string list, but may also fail while constructing it. For that case, they call g_strfreev() explicitly, which is needless since we have g_auto(GStrv). Signed-off-by: Michal Privoznik --- tools/vsh.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index d7ab7c61db..70b7e3e285 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2572,7 +2572,7 @@ vshReadlineCommandGenerator(const char *text) const vshCmdGrp *grp; const vshCmdDef *cmds; size_t ret_size =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; =20 grp =3D cmdGroups; =20 @@ -2588,10 +2588,9 @@ vshReadlineCommandGenerator(const char *text) continue; =20 if (STRPREFIX(name, text)) { - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) { - g_strfreev(ret); + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) return NULL; - } + ret[ret_size] =3D g_strdup(name); ret_size++; /* Terminate the string list properly. */ @@ -2604,7 +2603,7 @@ vshReadlineCommandGenerator(const char *text) } } =20 - return ret; + return g_steal_pointer(&ret); } =20 static char ** @@ -2615,7 +2614,7 @@ vshReadlineOptionsGenerator(const char *text, size_t list_index =3D 0; size_t len =3D strlen(text); size_t ret_size =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; =20 if (!cmd) return NULL; @@ -2654,10 +2653,8 @@ vshReadlineOptionsGenerator(const char *text, if (exists) continue; =20 - if (VIR_REALLOC_N(ret, ret_size + 2) < 0) { - g_strfreev(ret); + if (VIR_REALLOC_N(ret, ret_size + 2) < 0) return NULL; - } =20 ret[ret_size] =3D g_strdup_printf("--%s", name); ret_size++; @@ -2665,7 +2662,7 @@ vshReadlineOptionsGenerator(const char *text, ret[ret_size] =3D NULL; } =20 - return ret; + return g_steal_pointer(&ret); } =20 =20 --=20 2.26.2