From nobody Sun May 19 01:43:17 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=1675264299; cv=none; d=zohomail.com; s=zohoarc; b=hyEvXG62dskibtx9NDkHVmg4c7O4FbSoc2VMX3V/vsmp5JlGyB1lIQs+JdPKmFvT3saXaLipSR/thpF+4Ti0icaWqu0cSG6juQa3og1K/hq/u2F1ufOpRcseUdq4gUI5f90AH0iZV7iFrpeVGshargKvSudVqc/QUr9wC0Icff0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675264299; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Gk/7D+EJU1NQco91XhTzlkxzvEKqHf7w0mPX2KvXrr4=; b=l56h/tsjBeXmfgfJ9zXZFhW8+m8dQ7xFEKZjyPy5vY87ZAGe5tzu0oNbMV4vS/kMW58g9CSiWYU+kaszu54pkFBcmqGItElB73xhAFVWJPs+ikhD+i705ImYglWPavBxrbGbwDspgoAzsQU8o0oHWTeQNmcxnVPHKQOELO/9yXY= 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 1675264299900698.6788090640989; Wed, 1 Feb 2023 07:11:39 -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-500-EO6Oz8KYNUeVoME9pBERUg-1; Wed, 01 Feb 2023 10:11:31 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E12C6803D48; Wed, 1 Feb 2023 15:11:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 861112026D4B; Wed, 1 Feb 2023 15:11:17 +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 3450F19465A3; Wed, 1 Feb 2023 15:11:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1CBC5194658F for ; Wed, 1 Feb 2023 15:11:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 01746C15BAE; Wed, 1 Feb 2023 15:11:16 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82EF1C16020 for ; Wed, 1 Feb 2023 15:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675264298; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Gk/7D+EJU1NQco91XhTzlkxzvEKqHf7w0mPX2KvXrr4=; b=eohw+LlXDhRqcsaJAjZ2c3FN0lW7wmnpzn/oi1TaM7vxEKA99G4PR0HITqIYf3p+rczlEV h9Yrv2Ps2ldqTXQBdnkdTjUGgm/+bdxLN/PCk7t8piMwew4HwfDlEoFQCHU5M+nUzO8z2v OOkVVPEIOGDd1o9e2fAEec2truY4AJs= X-MC-Unique: EO6Oz8KYNUeVoME9pBERUg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH] tools: use g_autofree more Date: Wed, 1 Feb 2023 16:11:08 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.4 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: 1675264301486100001 Remove some obvious uses of VIR_FREE in favor of automatic cleanup. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- tools/virsh-domain-monitor.c | 5 +---- tools/virsh-domain.c | 37 +++++++++---------------------- tools/virsh-network.c | 6 ++--- tools/virsh-nwfilter.c | 3 +-- tools/virt-admin.c | 13 ++++------- tools/virt-host-validate-common.c | 6 ++--- 6 files changed, 20 insertions(+), 50 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index f89118f64f..c2134faba1 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1213,7 +1213,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) virDomainInfo info; g_autoptr(virshDomain) dom =3D NULL; virSecurityModel secmodel; - virSecurityLabelPtr seclabel; int persistent =3D 0; bool ret =3D true; int autostart; @@ -1301,6 +1300,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) } else { /* Only print something if a security model is active */ if (secmodel.model[0] !=3D '\0') { + g_autofree virSecurityLabelPtr seclabel =3D NULL; vshPrint(ctl, "%-15s %s\n", _("Security model:"), secmodel.mod= el); vshPrint(ctl, "%-15s %s\n", _("Security DOI:"), secmodel.doi); =20 @@ -1308,15 +1308,12 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) seclabel =3D g_new0(virSecurityLabel, 1); =20 if (virDomainGetSecurityLabel(dom, seclabel) =3D=3D -1) { - VIR_FREE(seclabel); return false; } else { if (seclabel->label[0] !=3D '\0') vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"), seclabel->label, seclabel->enforcing ? "enfor= cing" : "permissive"); } - - VIR_FREE(seclabel); } } =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 59b2b3ce60..a4abcb1b03 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -366,7 +366,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - char *buffer; + g_autofree char *buffer =3D NULL; int rv; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; bool current =3D vshCommandOptBool(cmd, "current"); @@ -404,8 +404,6 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) else rv =3D virDomainAttachDevice(dom, buffer); =20 - VIR_FREE(buffer); - if (rv < 0) { vshError(ctl, _("Failed to attach device from %s"), from); return false; @@ -2364,7 +2362,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) const char *path =3D NULL; int abort_flags =3D 0; const char *xml =3D NULL; - char *xmlstr =3D NULL; + g_autofree char *xmlstr =3D NULL; bool print_xml =3D vshCommandOptBool(cmd, "print-xml"); virTypedParameterPtr params =3D NULL; virshBlockJobWaitData *bjWait =3D NULL; @@ -2567,7 +2565,6 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - VIR_FREE(xmlstr); virTypedParamsFree(params, nparams); virshBlockJobWaitFree(bjWait); return ret; @@ -5624,7 +5621,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) bool ret =3D false; bool created =3D false; bool generated =3D false; - char *mime =3D NULL; + g_autofree char *mime =3D NULL; virshControl *priv =3D ctl->privData; virshStreamCallbackData cbdata; =20 @@ -5688,7 +5685,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - VIR_FREE(mime); return ret; } =20 @@ -7432,9 +7428,8 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 for (i =3D 0; i < nparams; i++) { - char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]= ); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } =20 @@ -8305,7 +8300,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; const char *from =3D NULL; - char *buffer; + g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 @@ -8322,7 +8317,6 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) dom =3D virDomainDefineXMLFlags(priv->conn, buffer, flags); else dom =3D virDomainDefineXML(priv->conn, buffer); - VIR_FREE(buffer); =20 if (!dom) { vshError(ctl, _("Failed to define domain from %s"), from); @@ -10340,7 +10334,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *= cmd) { g_autoptr(virshDomain) dom =3D NULL; bool ret =3D false; - char *guest_agent_cmd =3D NULL; + g_autofree char *guest_agent_cmd =3D NULL; char *result =3D NULL; int timeout =3D VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT; int judge =3D 0; @@ -10405,7 +10399,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *= cmd) =20 cleanup: VIR_FREE(result); - VIR_FREE(guest_agent_cmd); =20 return ret; } @@ -11185,7 +11178,7 @@ doMigrate(void *opaque) if (vshCommandOptStringReq(ctl, cmd, "migrate-disks", &opt) < 0) goto out; if (opt) { - char **val =3D NULL; + g_autofree char **val =3D NULL; =20 val =3D g_strsplit(opt, ",", 0); =20 @@ -11194,28 +11187,22 @@ doMigrate(void *opaque) &maxparams, VIR_MIGRATE_PARAM_MIGRATE_DISKS, (const char **)val) < 0) { - VIR_FREE(val); goto save_error; } - - VIR_FREE(val); } =20 if (vshCommandOptStringReq(ctl, cmd, "comp-methods", &opt) < 0) goto out; if (opt) { - char **val =3D g_strsplit(opt, ",", 0); + g_autofree char **val =3D g_strsplit(opt, ",", 0); =20 if (virTypedParamsAddStringList(¶ms, &nparams, &maxparams, VIR_MIGRATE_PARAM_COMPRESSION, (const char **)val) < 0) { - VIR_FREE(val); goto save_error; } - - VIR_FREE(val); } =20 if ((rv =3D vshCommandOptInt(ctl, cmd, "comp-mt-level", &intOpt)) < 0)= { @@ -11257,7 +11244,7 @@ doMigrate(void *opaque) if (vshCommandOptStringReq(ctl, cmd, "xml", &opt) < 0) goto out; if (opt) { - char *xml; + g_autofree char *xml =3D NULL; =20 if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) { vshError(ctl, _("cannot read file '%s'"), opt); @@ -11266,16 +11253,14 @@ doMigrate(void *opaque) =20 if (virTypedParamsAddString(¶ms, &nparams, &maxparams, VIR_MIGRATE_PARAM_DEST_XML, xml) < 0) { - VIR_FREE(xml); goto save_error; } - VIR_FREE(xml); } =20 if (vshCommandOptStringReq(ctl, cmd, "persistent-xml", &opt) < 0) goto out; if (opt) { - char *xml; + g_autofree char *xml =3D NULL; =20 if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) { vshError(ctl, _("cannot read file '%s'"), opt); @@ -11284,10 +11269,8 @@ doMigrate(void *opaque) =20 if (virTypedParamsAddString(¶ms, &nparams, &maxparams, VIR_MIGRATE_PARAM_PERSIST_XML, xml) < = 0) { - VIR_FREE(xml); goto save_error; } - VIR_FREE(xml); } =20 if ((rv =3D vshCommandOptInt(ctl, cmd, "auto-converge-initial", &intOp= t)) < 0) { diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 004719dad6..13f2e729eb 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -412,7 +412,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) int autostart; int persistent =3D -1; int active =3D -1; - char *bridge =3D NULL; + g_autofree char *bridge =3D NULL; =20 if (!(network =3D virshCommandOptNetwork(ctl, cmd, NULL))) return false; @@ -441,7 +441,6 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) if (bridge) vshPrint(ctl, "%-15s %s\n", _("Bridge:"), bridge); =20 - VIR_FREE(bridge); return true; } =20 @@ -1500,7 +1499,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *c= md) virNetworkPortPtr port =3D NULL; const char *from =3D NULL; bool ret =3D false; - char *buffer =3D NULL; + g_autofree char *buffer =3D NULL; g_autoptr(virshNetwork) network =3D NULL; unsigned int flags =3D 0; =20 @@ -1533,7 +1532,6 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *c= md) =20 ret =3D true; cleanup: - VIR_FREE(buffer); if (port) virNetworkPortFree(port); return ret; diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index d4112c8620..98380b452d 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -516,7 +516,7 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd = *cmd) { virNWFilterBindingPtr binding; const char *from =3D NULL; - char *buffer; + g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 @@ -530,7 +530,6 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd = *cmd) return false; =20 binding =3D virNWFilterBindingCreateXML(priv->conn, buffer, flags); - VIR_FREE(buffer); =20 if (!binding) { vshError(ctl, _("Failed to create network filter from %s"), from); diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 85b010b95f..8baf9636d3 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -73,7 +73,7 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED, vshControl *ctl =3D opaque; const char *str =3D "unknown reason"; virErrorPtr error; - char *uri =3D NULL; + g_autofree char *uri =3D NULL; =20 if (reason =3D=3D VIR_CONNECT_CLOSE_REASON_CLIENT) return; @@ -97,8 +97,6 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED, } =20 vshError(ctl, _(str), NULLSTR(uri)); - VIR_FREE(uri); - virErrorRestore(&error); } =20 @@ -183,7 +181,7 @@ static const vshCmdInfo info_uri[] =3D { static bool cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - char *uri; + g_autofree char *uri =3D NULL; vshAdmControl *priv =3D ctl->privData; =20 uri =3D virAdmConnectGetURI(priv->conn); @@ -193,7 +191,6 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } =20 vshPrint(ctl, "%s\n", uri); - VIR_FREE(uri); =20 return true; } @@ -328,7 +325,7 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UN= USED) int nsrvs =3D 0; size_t i; bool ret =3D false; - char *uri =3D NULL; + g_autofree char *uri =3D NULL; virAdmServerPtr *srvs =3D NULL; vshAdmControl *priv =3D ctl->privData; g_autoptr(vshTable) table =3D NULL; @@ -365,7 +362,6 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UN= USED) virAdmServerFree(srvs[i]); VIR_FREE(srvs); } - VIR_FREE(uri); =20 return ret; } @@ -702,9 +698,8 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd) vshAdmClientTransportToString(virAdmClientGetTransport(clnt))= ); =20 for (i =3D 0; i < nparams; i++) { - char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str =3D vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } =20 ret =3D true; diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 2ac96d1e19..a41bb346d2 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -56,7 +56,7 @@ void virHostMsgCheck(const char *prefix, ...) { va_list args; - char *msg; + g_autofree char *msg =3D NULL; =20 if (quiet) return; @@ -66,7 +66,6 @@ void virHostMsgCheck(const char *prefix, va_end(args); =20 fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg); - VIR_FREE(msg); } =20 static bool virHostMsgWantEscape(void) @@ -114,7 +113,7 @@ void virHostMsgFail(virHostValidateLevel level, ...) { va_list args; - char *msg; + g_autofree char *msg =3D NULL; =20 if (quiet) return; @@ -129,7 +128,6 @@ void virHostMsgFail(virHostValidateLevel level, else fprintf(stdout, "%s (%s)\n", _(failMessages[level]), msg); - VIR_FREE(msg); } =20 =20 --=20 2.39.0