From nobody Mon Feb 9 23:43:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1641993123; cv=none; d=zohomail.com; s=zohoarc; b=TGUeQE6/FNOf5QzPKRHyfHRnpgOFJUMgpPrku4MTEJBkIymx3utUNxCT5yrgA/YP6C/yARed5DKyUncNdgQcpX14i9TOMXCgl5UJy4fR8ZvvbV5ZyTPm4kDpX64auNToFGAhEadj55faK31LK24kpf4ct5I4VQGogr2P2NlYEMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641993123; h=Content-Type:Content-Transfer-Encoding:Cc: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=ODkNhxk3ZuagfxwmiIkYDFffwrZo2cB6h0UbcJQRWAQ=; b=XPqL1HSHdpiB+DBQxpcRGMPCFA1Jk4fg0wNPOEEFz419HWJ9JjdYKFjnsIXjZXf6IOPVuAv0sMvpx6x2OCVfyofrBuZzdP2rAa+EBGIFGG1FtnQgqq0/xHa+a+xaE92MhMPFEt9QWcyFECZUzhchCFzHTwsYBRwEC4vwHHmvqeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1641993123294783.3301278600501; Wed, 12 Jan 2022 05:12:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-J_T0YTwTP7-f3fKZ9MmQBg-1; Wed, 12 Jan 2022 08:11:26 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7327F427CA; Wed, 12 Jan 2022 13:11:20 +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 1B42A84FF6; Wed, 12 Jan 2022 13:11:20 +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 D1E271809CBF; Wed, 12 Jan 2022 13:11:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20CDB7J8004298 for ; Wed, 12 Jan 2022 08:11:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 84F7B2634C; Wed, 12 Jan 2022 13:11:07 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id C77412634A; Wed, 12 Jan 2022 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641993122; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=ODkNhxk3ZuagfxwmiIkYDFffwrZo2cB6h0UbcJQRWAQ=; b=Vr9R0KCAMpI1foVLF4vboTPrj0WAHsd0Cg56h4hoT7KRf7r+hC3mAK/SgtbJgQF99uMNfw jw6Bci0tKDCzCMqOviTLlQtHdOkBkEk5s/Tt/cC8tTTs3iN4caPe0MzOE5oEjORlAuUsGu +BA6emY/P/EPiJhngiKrFJuZeH4lkmQ= X-MC-Unique: J_T0YTwTP7-f3fKZ9MmQBg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 05/14] conf: interface: Use g_auto Date: Wed, 12 Jan 2022 14:10:06 +0100 Message-Id: <20220112131015.100288-6-twiederh@redhat.com> In-Reply-To: <20220112131015.100288-1-twiederh@redhat.com> References: <20220112131015.100288-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) X-ZM-MESSAGEID: 1641993124660100006 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/conf/interface_conf.c | 67 ++++++++++++--------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index cbe6aad957..4b464bdf4f 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -68,6 +68,7 @@ virInterfaceProtocolDefFree(virInterfaceProtocolDef *def) g_free(def->gateway); g_free(def); } +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfaceProtocolDef, virInterfaceProtoco= lDefFree); =20 =20 void @@ -155,9 +156,8 @@ static int virInterfaceDefParseStartMode(virInterfaceDef *def, xmlXPathContextPtr ctxt) { - char *tmp; + g_autofree char *tmp =3D virXPathString("string(./start/@mode)", ctxt); =20 - tmp =3D virXPathString("string(./start/@mode)", ctxt); if (tmp =3D=3D NULL) { def->startmode =3D VIR_INTERFACE_START_UNSPECIFIED; } else if (STREQ(tmp, "onboot")) { @@ -169,10 +169,8 @@ virInterfaceDefParseStartMode(virInterfaceDef *def, } else { virReportError(VIR_ERR_XML_ERROR, _("unknown interface startmode %s"), tmp); - VIR_FREE(tmp); return -1; } - VIR_FREE(tmp); return 0; } =20 @@ -180,10 +178,9 @@ virInterfaceDefParseStartMode(virInterfaceDef *def, static int virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt) { - char *tmp; + g_autofree char *tmp =3D virXPathString("string(./@mode)", ctxt); int ret =3D 0; =20 - tmp =3D virXPathString("string(./@mode)", ctxt); if (tmp =3D=3D NULL) return VIR_INTERFACE_BOND_NONE; if (STREQ(tmp, "balance-rr")) { @@ -205,7 +202,6 @@ virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt) _("unknown bonding mode %s"), tmp); ret =3D -1; } - VIR_FREE(tmp); return ret; } =20 @@ -213,10 +209,9 @@ virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt) static int virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr ctxt) { - char *tmp; + g_autofree char *tmp =3D virXPathString("string(./miimon/@carrier)", c= txt); int ret =3D 0; =20 - tmp =3D virXPathString("string(./miimon/@carrier)", ctxt); if (tmp =3D=3D NULL) return VIR_INTERFACE_BOND_MII_NONE; if (STREQ(tmp, "ioctl")) { @@ -228,7 +223,6 @@ virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr c= txt) _("unknown mii bonding carrier %s"), tmp); ret =3D -1; } - VIR_FREE(tmp); return ret; } =20 @@ -236,10 +230,9 @@ virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr = ctxt) static int virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctxt) { - char *tmp; + g_autofree char *tmp =3D virXPathString("string(./arpmon/@validate)", = ctxt); int ret =3D 0; =20 - tmp =3D virXPathString("string(./arpmon/@validate)", ctxt); if (tmp =3D=3D NULL) return VIR_INTERFACE_BOND_ARP_NONE; if (STREQ(tmp, "active")) { @@ -253,7 +246,6 @@ virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctx= t) _("unknown arp bonding validate %s"), tmp); ret =3D -1; } - VIR_FREE(tmp); return ret; } =20 @@ -263,7 +255,7 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDef *def, xmlNodePtr dhcp, xmlXPathContextPtr ctxt) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - char *tmp; + g_autofree char *tmp =3D NULL; int ret =3D 0; =20 def->dhcp =3D 1; @@ -280,7 +272,6 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDef *def, } else { def->peerdns =3D state ? 1 : 0; } - VIR_FREE(tmp); } =20 return ret; @@ -317,7 +308,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDef *= def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp; - xmlNodePtr *ipNodes =3D NULL; + g_autofree xmlNodePtr *ipNodes =3D NULL; int nipNodes, ret =3D -1; size_t i; char *tmp; @@ -357,7 +348,6 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDef *= def, ret =3D 0; =20 error: - VIR_FREE(ipNodes); return ret; } =20 @@ -367,7 +357,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDef *= def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp, autoconf; - xmlNodePtr *ipNodes =3D NULL; + g_autofree xmlNodePtr *ipNodes =3D NULL; int nipNodes, ret =3D -1; size_t i; char *tmp; @@ -411,7 +401,6 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDef *= def, ret =3D 0; =20 error: - VIR_FREE(ipNodes); return ret; } =20 @@ -421,7 +410,7 @@ virInterfaceDefParseIfAdressing(virInterfaceDef *def, xmlXPathContextPtr ctxt) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *protoNodes =3D NULL; + g_autofree xmlNodePtr *protoNodes =3D NULL; int nProtoNodes, pp, ret =3D -1; char *tmp; =20 @@ -439,42 +428,33 @@ virInterfaceDefParseIfAdressing(virInterfaceDef *def, def->nprotos =3D 0; for (pp =3D 0; pp < nProtoNodes; pp++) { =20 - virInterfaceProtocolDef *proto; - - proto =3D g_new0(virInterfaceProtocolDef, 1); + g_autoptr(virInterfaceProtocolDef) proto =3D g_new0(virInterfacePr= otocolDef, 1); =20 ctxt->node =3D protoNodes[pp]; tmp =3D virXPathString("string(./@family)", ctxt); if (tmp =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("protocol misses the family attribute")= ); - virInterfaceProtocolDefFree(proto); goto error; } proto->family =3D tmp; if (STREQ(tmp, "ipv4")) { - if (virInterfaceDefParseProtoIPv4(proto, ctxt) !=3D 0) { - virInterfaceProtocolDefFree(proto); + if (virInterfaceDefParseProtoIPv4(proto, ctxt) !=3D 0) goto error; - } } else if (STREQ(tmp, "ipv6")) { - if (virInterfaceDefParseProtoIPv6(proto, ctxt) !=3D 0) { - virInterfaceProtocolDefFree(proto); + if (virInterfaceDefParseProtoIPv6(proto, ctxt) !=3D 0) goto error; - } } else { virReportError(VIR_ERR_XML_ERROR, _("unsupported protocol family '%s'"), tmp); - virInterfaceProtocolDefFree(proto); goto error; } - def->protos[def->nprotos++] =3D proto; + def->protos[def->nprotos++] =3D g_steal_pointer(&proto); } =20 ret =3D 0; =20 error: - VIR_FREE(protoNodes); return ret; =20 } @@ -484,17 +464,16 @@ static int virInterfaceDefParseBridge(virInterfaceDef *def, xmlXPathContextPtr ctxt) { - xmlNodePtr *interfaces =3D NULL; - xmlNodePtr bridge; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + g_autofree xmlNodePtr *interfaces =3D NULL; virInterfaceDef *itf; - char *tmp =3D NULL; + g_autofree char *tmp =3D NULL; int nbItf; size_t i; int ret =3D 0; =20 - bridge =3D ctxt->node; def->data.bridge.stp =3D -1; - if ((tmp =3D virXMLPropString(bridge, "stp"))) { + if ((tmp =3D virXMLPropString(ctxt->node, "stp"))) { if (STREQ(tmp, "on")) { def->data.bridge.stp =3D 1; } else if (STREQ(tmp, "off")) { @@ -506,7 +485,7 @@ virInterfaceDefParseBridge(virInterfaceDef *def, goto error; } } - def->data.bridge.delay =3D virXMLPropString(bridge, "delay"); + def->data.bridge.delay =3D virXMLPropString(ctxt->node, "delay"); =20 nbItf =3D virXPathNodeSet("./interface", ctxt, &interfaces); if (nbItf < 0) { @@ -530,9 +509,6 @@ virInterfaceDefParseBridge(virInterfaceDef *def, } =20 error: - VIR_FREE(tmp); - VIR_FREE(interfaces); - ctxt->node =3D bridge; return ret; } =20 @@ -541,8 +517,8 @@ static int virInterfaceDefParseBondItfs(virInterfaceDef *def, xmlXPathContextPtr ctxt) { - xmlNodePtr *interfaces =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) + g_autofree xmlNodePtr *interfaces =3D NULL; virInterfaceDef *itf; int nbItf; size_t i; @@ -573,7 +549,6 @@ virInterfaceDefParseBondItfs(virInterfaceDef *def, =20 ret =3D 0; cleanup: - VIR_FREE(interfaces); return ret; } =20 @@ -679,7 +654,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, { g_autoptr(virInterfaceDef) def =3D NULL; int type; - char *tmp; + g_autofree char *tmp =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr lnk; =20 @@ -695,10 +670,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, if (type =3D=3D -1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown interface type %s"), tmp); - VIR_FREE(tmp); return NULL; } - VIR_FREE(tmp); =20 def =3D g_new0(virInterfaceDef, 1); =20 --=20 2.31.1