From nobody Thu May 2 11:34:07 2024 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=1628616485; cv=none; d=zohomail.com; s=zohoarc; b=AZ6BjieZjOv6Gtai2CAjuff29UNtLUj0o4/EQIhDeoNidtNwy1MFUJxvpTvVm3LMNgmqtHkonOKIWh3o6AYPzPPivBOYo7EfAq3YkITj2M0EjmUBSVp53rfFgPpvVFJYFyKG7G4AEhBxZnz+CAKJw9D5bTlYGRUHwkHKWHP6h5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616485; 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=1g+1et0eqYgLgFOiddipbueDa/qJZLSICXowab4XXYM=; b=XLU1PjAwkyhT4A/OZB0cIP+yWvL0dbyOYiCer/DjMFOwIJrRtL3hj4XNeMIk+QlXi9VX/u0FQ+4JjPyDMEchoYDco/zlBehY3hfdZa2swkiWwH/WcI6nQloCYnI+0HYUjZd6SbaCr5Ui/E6gfa2oT8as3I94IgwLclXeYq0CWiQ= 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) 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 1628616485503163.77494671071383; Tue, 10 Aug 2021 10:28:05 -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-293-m4SDBJ-BNXCsfnrb67z3KQ-1; Tue, 10 Aug 2021 13:28:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3140CC73AC; Tue, 10 Aug 2021 17:27:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11CE860BF1; Tue, 10 Aug 2021 17:27:56 +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 D50674BB7C; Tue, 10 Aug 2021 17:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEnlt021474 for ; Tue, 10 Aug 2021 13:14:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3828D18A77; Tue, 10 Aug 2021 17:14:49 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B610F136F5 for ; Tue, 10 Aug 2021 17:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616484; 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=1g+1et0eqYgLgFOiddipbueDa/qJZLSICXowab4XXYM=; b=HC85BqNPtnhgB7wXAP86INnQhhy0CWExFc164PPImSUh13PlZkFssAI/hIV6//ir/o2wy6 6KxZWkgcHbdr4s5CD1YZls8o1dGGcJnrrnDkkkKAILDKV8S0eMEPQYRYSmREmNjga9J3Co 2IrlLfDOsTO+S2b/PNu2D9+vLD8Ao1E= X-MC-Unique: m4SDBJ-BNXCsfnrb67z3KQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/5] vsh: do not cast away const Date: Tue, 10 Aug 2021 19:14:39 +0200 Message-Id: <2954e6b96a34e84734fcaa69cc0e9bf3750d5994.1628615384.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.12 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616486689100001 Instead of using the same variable to store either a const pointer or an allocated string, always make a copy. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- tools/vsh.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 123284c636..3bbaecd2ea 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -318,7 +318,7 @@ vshCmddefCheckInternals(vshControl *ctl, =20 case VSH_OT_ALIAS: { size_t j; - char *name =3D (char *)opt->help; /* cast away const */ + g_autofree char *name =3D NULL; char *p; =20 if (opt->flags || !opt->help) { @@ -326,15 +326,16 @@ vshCmddefCheckInternals(vshControl *ctl, opt->name, cmd->name); return -1; /* alias options are tracked by the original na= me */ } - if ((p =3D strchr(name, '=3D'))) - name =3D g_strndup(name, p - name); + if ((p =3D strchr(opt->help, '=3D'))) + name =3D g_strndup(opt->help, p - opt->help); + else + name =3D g_strdup(opt->help); for (j =3D i + 1; cmd->opts[j].name; j++) { if (STREQ(name, cmd->opts[j].name) && cmd->opts[j].type !=3D VSH_OT_ALIAS) break; } - if (name !=3D opt->help) { - VIR_FREE(name); + if (p) { /* If alias comes with value, replacement must not be bool= */ if (cmd->opts[j].type =3D=3D VSH_OT_BOOL) { vshError(ctl, _("alias '%s' of command '%s' has mismat= ched alias type"), --=20 2.31.1 From nobody Thu May 2 11:34:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1628616486; cv=none; d=zohomail.com; s=zohoarc; b=P31CQMliEdo/bZMy6PoUozhE7v4jsheZgWMoMD/eIsiMT+vSLjmEFHxh9KzP4ZthaOatwjD3yWXE2yWbwQ/QfCcYmL5i2GapMISnfeGT7VaogVZfu8/wZI3HN3fR3Nf1kRMU9EsnNd2HVzHegG9lcDAKyNI9uCKuO95OY/qdY2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616486; 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=EOF8sSnwizIX1SOxuX1cEvILtTKpKIQG821WXUcDEb8=; b=Rkn8irjgMcWPOxIZSmgpQ+m/TnLMZdiFms1gRMF9SN12fChK6FWwXbY0uGIfx+yJACZqbMOFkJY++Ru38bxfC7LeoSrR/jVa5AmoUKeXUOys1+Zfb5llIIA5w2uRAEZWR+8HarUkJYL9YagopUcCMrdwnlBrePTaFhxOvr79rZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 162861648678651.04163654068418; Tue, 10 Aug 2021 10:28:06 -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-500--zLIdG44OImd2Ww3Asf_6A-1; Tue, 10 Aug 2021 13:28:03 -0400 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 CC61A1B18BC1; Tue, 10 Aug 2021 17:27:58 +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 A4B522854F; Tue, 10 Aug 2021 17:27:58 +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 70449181A2AA; Tue, 10 Aug 2021 17:27:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEoss021481 for ; Tue, 10 Aug 2021 13:14:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0712C18A77; Tue, 10 Aug 2021 17:14:50 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84DB9136F5 for ; Tue, 10 Aug 2021 17:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616485; 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=EOF8sSnwizIX1SOxuX1cEvILtTKpKIQG821WXUcDEb8=; b=QdRTFpGv1jsJGTUbM7/KafljklM1Xqc60BdOsL/P8guY0p2PMlZO90sejt48nxmeg+/wDJ 3guRxtE6qIaAKdjOI38S9gOUrMTYsnrT4YATmIy7eItzy+M6L5NWzX6zUlTKp2Hqn3BPSz 1n5suVn9YPsU23KohocLUi8xUdc5yUo= X-MC-Unique: -zLIdG44OImd2Ww3Asf_6A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/5] vsh: cmdEcho: use separate variable for argument Date: Tue, 10 Aug 2021 19:14:40 +0200 Message-Id: <7e0e57a8e1f27c6b838c0fb503d9dbcedcc531da.1628615384.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616488680100003 Do not use 'arg' which is later used for an allocated string. Signed-off-by: J=C3=A1n Tomko --- tools/vsh.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 3bbaecd2ea..bf32a8dc22 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3199,17 +3199,16 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { char *str; g_auto(virBuffer) xmlbuf =3D VIR_BUFFER_INITIALIZER; - - arg =3D opt->data; + const char *curr =3D opt->data; =20 if (count) virBufferAddChar(&buf, ' '); =20 if (xml) { - virBufferEscapeString(&xmlbuf, "%s", arg); + virBufferEscapeString(&xmlbuf, "%s", curr); str =3D virBufferContentAndReset(&xmlbuf); } else { - str =3D g_strdup(arg); + str =3D g_strdup(curr); } =20 if (shell) --=20 2.31.1 From nobody Thu May 2 11:34:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1628616415; cv=none; d=zohomail.com; s=zohoarc; b=bOeiVUYwfZyhFxkaH0YcUNzz6sVuJ9/u0HROzl1INLs5sGWSomwtDdgbbVAGb+0ICZErRv+8b8meSeTWSd/3tMn6iwI6nUj43vLZGBjj0anu1d6OlkUEVoYZI9JN9t+O2aQZD5qafOq+6x8HcL6JzhJsE5B08lTCwg+eiVOc0L4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616415; 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=iQwG5P8Q+64IU8BkLysy6Y98VHVOD4BmYrKYisgDgO0=; b=K4RmZvQSZs0NHaR+0tiL74stb/RmyijcYr9vpXKHSqGtBbz+VO9dMEKB7uXRVKVsD0GmWGiUGSDs1UT50FEdg3a2eF3wxkyzYGimGe6ayh4B6BUy4x8FuZyov391sKPuOLaiTHeK1b/AbxcAGGtEoIgKdTNWB6NmjULzgfBDOsE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1628616415363205.61837930502725; Tue, 10 Aug 2021 10:26:55 -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-560-S3kT89blPom0Cr_6k1HmHQ-1; Tue, 10 Aug 2021 13:26:52 -0400 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 6F40F1B18BCE; Tue, 10 Aug 2021 17:26:47 +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 C6D5D2854E; Tue, 10 Aug 2021 17:26:46 +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 5DAA7181A2A5; Tue, 10 Aug 2021 17:26:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEo2a021489 for ; Tue, 10 Aug 2021 13:14:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9FC3136F5; Tue, 10 Aug 2021 17:14:50 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53DAE620DE for ; Tue, 10 Aug 2021 17:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616414; 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=iQwG5P8Q+64IU8BkLysy6Y98VHVOD4BmYrKYisgDgO0=; b=fQiT5gGzOb+Z8QONX+iJKPOFS26x2ux4jVjH/J4wNjAzh382NvAwp4zPsikCjbYDbc3ous ekoTRziHt01DRhUnk3tqQvwEut7QF7lbEOCyd7PocxaaWdRQvprx86I22TBpcvqYAQS1Xf 1ECVGi6U/nAWFL9ryiewXQWp5kvLxBo= X-MC-Unique: S3kT89blPom0Cr_6k1HmHQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/5] vsh: use g_auto where possible Date: Tue, 10 Aug 2021 19:14:41 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616416448100001 Excluding vshCommandParse. Signed-off-by: J=C3=A1n Tomko --- tools/vsh.c | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index bf32a8dc22..71fbb7401f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -122,7 +122,7 @@ int vshStringToArray(const char *str, char ***array) { - char *str_copied =3D g_strdup(str); + g_autofree char *str_copied =3D g_strdup(str); char *str_tok =3D NULL; char *tmp; unsigned int nstr_tokens =3D 0; @@ -163,7 +163,6 @@ vshStringToArray(const char *str, arr[nstr_tokens++] =3D g_strdup(str_tok); =20 *array =3D arr; - VIR_FREE(str_copied); return nstr_tokens; } =20 @@ -434,7 +433,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cm= d, const char *name, { size_t i; const vshCmdOptDef *ret =3D NULL; - char *alias =3D NULL; + g_autofree char *alias =3D NULL; =20 if (STREQ(name, helpopt.name)) return &helpopt; @@ -481,7 +480,6 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cm= d, const char *name, cmd->name, name); } cleanup: - VIR_FREE(alias); return ret; } =20 @@ -1814,7 +1812,7 @@ void vshDebug(vshControl *ctl, int level, const char *format, ...) { va_list ap; - char *str; + g_autofree char *str =3D NULL; =20 /* Aligning log levels to that of libvirt. * Traces with levels >=3D user-specified-level @@ -1831,14 +1829,13 @@ vshDebug(vshControl *ctl, int level, const char *fo= rmat, ...) str =3D g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); - VIR_FREE(str); } =20 void vshPrintExtra(vshControl *ctl, const char *format, ...) { va_list ap; - char *str; + g_autofree char *str =3D NULL; =20 if (ctl && ctl->quiet) return; @@ -1847,7 +1844,6 @@ vshPrintExtra(vshControl *ctl, const char *format, ..= .) str =3D g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); - VIR_FREE(str); } =20 =20 @@ -1855,13 +1851,12 @@ void vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...) { va_list ap; - char *str; + g_autofree char *str =3D NULL; =20 va_start(ap, format); str =3D g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); - VIR_FREE(str); } =20 =20 @@ -1960,7 +1955,7 @@ void vshError(vshControl *ctl, const char *format, ...) { va_list ap; - char *str; + g_autofree char *str =3D NULL; =20 if (ctl !=3D NULL) { va_start(ap, format); @@ -1980,7 +1975,6 @@ vshError(vshControl *ctl, const char *format, ...) =20 fprintf(stderr, "%s\n", NULLSTR(str)); fflush(stderr); - VIR_FREE(str); } =20 =20 @@ -2186,7 +2180,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, cons= t char *msg_format, va_list ap) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *str =3D NULL; + g_autofree char *str =3D NULL; size_t len; const char *lvl =3D ""; g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); @@ -2237,13 +2231,11 @@ vshOutputLogFile(vshControl *ctl, int log_level, co= nst char *msg_format, if (safewrite(ctl->log_fd, str, len) < 0) goto error; =20 - VIR_FREE(str); return; =20 error: vshCloseLogFile(ctl); vshError(ctl, "%s", _("failed to write the log file")); - VIR_FREE(str); } =20 /** @@ -2359,7 +2351,7 @@ vshAskReedit(vshControl *ctl, char * vshEditWriteToTempFile(vshControl *ctl, const char *doc) { - char *ret; + g_autofree char *ret =3D NULL; const char *tmpdir; int fd; =20 @@ -2370,7 +2362,6 @@ vshEditWriteToTempFile(vshControl *ctl, const char *d= oc) if (fd =3D=3D -1) { vshError(ctl, _("g_mkstemp_full: failed to create temporary file: = %s"), g_strerror(errno)); - VIR_FREE(ret); return NULL; } =20 @@ -2379,14 +2370,12 @@ vshEditWriteToTempFile(vshControl *ctl, const char = *doc) ret, g_strerror(errno)); VIR_FORCE_CLOSE(fd); unlink(ret); - VIR_FREE(ret); return NULL; } if (VIR_CLOSE(fd) < 0) { vshError(ctl, _("close: %s: failed to write or close temporary fil= e: %s"), ret, g_strerror(errno)); unlink(ret); - VIR_FREE(ret); return NULL; } =20 @@ -2406,7 +2395,7 @@ int vshEditFile(vshControl *ctl, const char *filename) { const char *editor; - virCommand *cmd; + g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; int outfd =3D STDOUT_FILENO; int errfd =3D STDERR_FILENO; @@ -2450,7 +2439,6 @@ vshEditFile(vshControl *ctl, const char *filename) ret =3D 0; =20 cleanup: - virCommandFree(cmd); return ret; } =20 @@ -2806,10 +2794,10 @@ vshReadlineCharIsQuoted(char *line, int idx) static int vshReadlineInit(vshControl *ctl) { - char *userdir =3D NULL; + g_autofree char *userdir =3D NULL; int max_history =3D 500; int ret =3D -1; - char *histsize_env =3D NULL; + g_autofree char *histsize_env =3D NULL; const char *histsize_str =3D NULL; const char *break_characters =3D " \t\n`@$><=3D;|&{("; const char *quote_characters =3D "\"'"; @@ -2856,8 +2844,6 @@ vshReadlineInit(vshControl *ctl) ret =3D 0; =20 cleanup: - VIR_FREE(userdir); - VIR_FREE(histsize_env); return ret; } =20 @@ -2940,7 +2926,7 @@ static int vshInitDebug(vshControl *ctl) { const char *debugEnv; - char *env =3D NULL; + g_autofree char *env =3D NULL; =20 if (ctl->debug =3D=3D VSH_DEBUG_DEFAULT) { env =3D g_strdup_printf("%s_DEBUG", ctl->env_prefix); @@ -2957,7 +2943,6 @@ vshInitDebug(vshControl *ctl) ctl->debug =3D debug; } } - VIR_FREE(env); } =20 if (ctl->logfile =3D=3D NULL) { @@ -2969,7 +2954,6 @@ vshInitDebug(vshControl *ctl) ctl->logfile =3D g_strdup(debugEnv); vshOpenLogFile(ctl); } - VIR_FREE(env); } =20 return 0; @@ -3186,7 +3170,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) bool err =3D false; int count =3D 0; const vshCmdOpt *opt =3D NULL; - char *arg; + g_autofree char *arg =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 if (vshCommandOptBool(cmd, "shell")) @@ -3197,7 +3181,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) err =3D true; =20 while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { - char *str; + g_autofree char *str =3D NULL; g_auto(virBuffer) xmlbuf =3D VIR_BUFFER_INITIALIZER; const char *curr =3D opt->data; =20 @@ -3216,7 +3200,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) else virBufferAdd(&buf, str, -1); count++; - VIR_FREE(str); } =20 arg =3D virBufferContentAndReset(&buf); @@ -3226,7 +3209,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s", arg); } - VIR_FREE(arg); return true; } =20 --=20 2.31.1 From nobody Thu May 2 11:34:07 2024 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=1628616427; cv=none; d=zohomail.com; s=zohoarc; b=m3Rr/U9LPYjgfidpy3w2cZ9aZRa10GcRoOJgVMxnusot/Y6mxVMpB2401V7WD4cCUk1d1CY0GAFiOt9i1HMbzFaG1tpYlyDcIlZPqib7L9yOOVC6qs4iUikOc1b1PQ8r0tIBFMHQpzXLvVYxIthVootFYVeyL+Y999jDL5cjocM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616427; 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=3R6twZYzxtpWZHxVPRHr4Kpcljj+EzOidNzSgw78lCc=; b=f9nV1++BhPJK+wG0+EZSox1qtvjtvG3vtconAFanHQ71hNvq/GKipNnPDo0anyDaA3BBNsE1ooLD9aSzCU5xwINl93aX5EJP4lWWG19SUCk6xDC+9F6O1EQd92pqjeNflcLRlnqpeqV52VDDexdyIYDNblT5Hz1pr7UdAsFikBA= 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) 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 1628616427740959.9180606895039; Tue, 10 Aug 2021 10:27:07 -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-59-B4Oahb1dNt2xzA9NnAAV_w-1; Tue, 10 Aug 2021 13:27:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09DE5802B9E; Tue, 10 Aug 2021 17:26:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D59285DF5D; Tue, 10 Aug 2021 17:26:58 +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 A62A64A707; Tue, 10 Aug 2021 17:26:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEpXD021494 for ; Tue, 10 Aug 2021 13:14:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 98E7A136F5; Tue, 10 Aug 2021 17:14:51 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2308B620DE for ; Tue, 10 Aug 2021 17:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616426; 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=3R6twZYzxtpWZHxVPRHr4Kpcljj+EzOidNzSgw78lCc=; b=XT9KJo6wKi1n3p2cZiYXQURM9IrjWuVMxU+FZm0VbrNn3w1SI3UpgrSwE549xK/ISX5GXQ PL4ElqvdyuJPJS5KKpWw0RDM/SR+g8yzWm24GtiR5UxmgBRXlYX2HyjgzgdBoUJeBh/J/y zsi6ZvURISW7sPQi3NK4ls4ohLtFeMw= X-MC-Unique: B4Oahb1dNt2xzA9NnAAV_w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/5] vsh: remove pointless cleanup labels Date: Tue, 10 Aug 2021 19:14:42 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616429303100001 Remove cleanup sections that are no longer needed, as well as unnecessary 'ret' variables. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- tools/vsh.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 71fbb7401f..f4b555fb8b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2396,7 +2396,6 @@ vshEditFile(vshControl *ctl, const char *filename) { const char *editor; g_autoptr(virCommand) cmd =3D NULL; - int ret =3D -1; int outfd =3D STDOUT_FILENO; int errfd =3D STDERR_FILENO; =20 @@ -2434,12 +2433,9 @@ vshEditFile(vshControl *ctl, const char *filename) if (virCommandRunAsync(cmd, NULL) < 0 || virCommandWait(cmd, NULL) < 0) { vshReportError(ctl); - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 char * @@ -2796,7 +2792,6 @@ vshReadlineInit(vshControl *ctl) { g_autofree char *userdir =3D NULL; int max_history =3D 500; - int ret =3D -1; g_autofree char *histsize_env =3D NULL; const char *histsize_str =3D NULL; const char *break_characters =3D " \t\n`@$><=3D;|&{("; @@ -2821,12 +2816,12 @@ vshReadlineInit(vshControl *ctl) if ((histsize_str =3D getenv(histsize_env))) { if (virStrToLong_i(histsize_str, NULL, 10, &max_history) < 0) { vshError(ctl, _("Bad $%s value."), histsize_env); - goto cleanup; + return -1; } else if (max_history > HISTSIZE_MAX || max_history < 0) { vshError(ctl, _("$%s value should be between 0 " "and %d"), histsize_env, HISTSIZE_MAX); - goto cleanup; + return -1; } } stifle_history(max_history); @@ -2841,10 +2836,7 @@ vshReadlineInit(vshControl *ctl) ctl->historyfile =3D g_strdup_printf("%s/history", ctl->historydir); =20 read_history(ctl->historyfile); - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static void --=20 2.31.1 From nobody Thu May 2 11:34:07 2024 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=1628616420; cv=none; d=zohomail.com; s=zohoarc; b=IHhzR11e7YEFZFuj3SXWvjwbfzTsNKWwZOku2CkCasY/54gcqlLb9klkpjVzBTkM4yu9q7YEG+yaTByegU/TgxMkWczpfyhcoiPG44X+NGehcDvSjO0uJ8lAKc2uajV+nGRhjzDEYGhMh4oI8QFDMjMRCuZ7U39TCvfbF4p0+C0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628616420; 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=lN8Ix1H8bMHyb34YYThsFi4Sp5VL6/xYbfuwZAVNvxg=; b=DYe9zPyw0Xy4dRjK+qz3MoamU1x9eumHhkw8RS/J8epAObgCyG19iLJDFTOpnwBLtJiSWxCQegfL7CAajl8orEhnAl/XDo3f9VVik72Abx526LB60PU1UtHE5ReLTjOCs4R7kOiMEHLpFOyqGpL8vqIQKG6W2N6qaneLHQcC5Fg= 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) 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 1628616420801914.4776095526395; Tue, 10 Aug 2021 10:27:00 -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-477-BNiWWR4MPjSpvBai2jt8IQ-1; Tue, 10 Aug 2021 13:26:53 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B85F9100806F; Tue, 10 Aug 2021 17:26:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EE9E10429CA; Tue, 10 Aug 2021 17:26:47 +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 5CC944BB7B; Tue, 10 Aug 2021 17:26:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17AHEqMq021500 for ; Tue, 10 Aug 2021 13:14:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68092136F5; Tue, 10 Aug 2021 17:14:52 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E615C620DE for ; Tue, 10 Aug 2021 17:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628616419; 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=lN8Ix1H8bMHyb34YYThsFi4Sp5VL6/xYbfuwZAVNvxg=; b=VYrCezGxk9LXf99xpqP2JfodKAAKNQ7Q1hU0500Rg++Gua0hvoQ7cgU7SExPaO7ZVvVt+O LGuYR+ugr5sRZf7zL+DO8nDrSkMOR+s4PF43tt5UFeFHIa3LeywV8C9LDjmjXpQoktq8C0 o6w9ytZD/2urH2GQgl0DN23FTroi83I= X-MC-Unique: BNiWWR4MPjSpvBai2jt8IQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/5] vsh: use g_clear_pointer Date: Tue, 10 Aug 2021 19:14:43 +0200 Message-Id: <056271e5c70b8317467a7be750f7a82e23401af5.1628615384.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.22 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628616422482100001 Replace remaining uses of VIR_FREE with g_clear_pointer. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- tools/vsh.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index f4b555fb8b..1f384d4ea6 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2253,10 +2253,7 @@ vshCloseLogFile(vshControl *ctl) g_strerror(errno)); } =20 - if (ctl->logfile) { - VIR_FREE(ctl->logfile); - ctl->logfile =3D NULL; - } + g_clear_pointer(&ctl->logfile, g_free); } =20 #ifndef WIN32 @@ -2852,8 +2849,8 @@ vshReadlineDeinit(vshControl *ctl) } } =20 - VIR_FREE(ctl->historydir); - VIR_FREE(ctl->historyfile); + g_clear_pointer(&ctl->historydir, g_free); + g_clear_pointer(&ctl->historyfile, g_free); } =20 char * --=20 2.31.1