From nobody Sat Feb 7 09:42:16 2026 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