From nobody Mon Feb 9 03:46: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=1629203179; cv=none; d=zohomail.com; s=zohoarc; b=XLOfB1NqSvQRJi7SAczeYePY0RkRuVUMmJUYntMwYM3G5EQIuezGMTRspDj/1p1vhgRZdtOzjVBAIW/aAY5A2jZAtkU/Cms/3iDKsEyGBk4Y+xynz6uTiThAcpIqTGUeOZT3JENIMdO7gEohcoSHsKT7Ii1ToHwBt4++tmF32As= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629203179; 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=XmF22A4GMWR2agQCZOo3B3Ov92pabJiyorH9L9OW+q4=; b=KECGDNfTNmYrJNj/bvdLKfPY8Xia8/dScY7rC1fP3ktJFZyQA7IEWLLP2Xhos60nC/yAUSxl4o0C6cl3Hm0gXeUL8jZoi/dJAI7RzMte3E7UHcgqwErCKZVp4EaoLhawaldTGJI+NQLdMCHo1Y3sYq7n9zsWxI9/yrShjcjouvg= 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 1629203179951709.6802545917034; Tue, 17 Aug 2021 05:26:19 -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-549-YzfR-BLoNauCkjhJCt-jUw-1; Tue, 17 Aug 2021 08:26:16 -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 CF220802922; Tue, 17 Aug 2021 12:26:10 +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 AC7E51909D; Tue, 17 Aug 2021 12:26:10 +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 74FFD181A1F3; Tue, 17 Aug 2021 12:26:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17HCPePt018135 for ; Tue, 17 Aug 2021 08:25:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4488C60871; Tue, 17 Aug 2021 12:25:40 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C223A60854 for ; Tue, 17 Aug 2021 12:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629203178; 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=XmF22A4GMWR2agQCZOo3B3Ov92pabJiyorH9L9OW+q4=; b=ardkTnsBTGJmAOAEA0Cj6zWM8xDfdQsrQn5nfB0bsgU5KGlK3Bl4XpWaw8Wy4DERgXt/Yl idmUoYPdfwxOfltvaccx5YmH0ukAVDbRWwfoqvt4veEcQpyg9kla+//w6Z0KywS0Bm6Srx 6tSxkp5PzHYEvmbrfQp+QY2ZpPJYHdI= X-MC-Unique: YzfR-BLoNauCkjhJCt-jUw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/6] conf: refactor virNetworkLoadState Date: Tue, 17 Aug 2021 14:25:29 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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: 1629203181530100001 Use g_auto where possible, reducing variable scope where applicable. Signed-off-by: J=C3=A1n Tomko --- src/conf/virnetworkobj.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 2a2d94dc98..aa629af6f6 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -860,13 +860,13 @@ virNetworkLoadState(virNetworkObjList *nets, const char *name, virNetworkXMLOption *xmlopt) { - char *configFile =3D NULL; + g_autofree char *configFile =3D NULL; virNetworkDef *def =3D NULL; virNetworkObj *obj =3D NULL; - xmlDocPtr xml =3D NULL; - xmlNodePtr node =3D NULL, *nodes =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; - virBitmap *classIdMap =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; + xmlNodePtr node =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autoptr(virBitmap) classIdMap =3D NULL; unsigned long long floor_sum_val =3D 0; unsigned int taint =3D 0; int n; @@ -903,18 +903,16 @@ virNetworkLoadState(virNetworkObjList *nets, if (virXMLNodeNameEqual(node, "networkstatus")) { /* Newer network status file. Contains useful * info which are not to be found in bare config XML */ - char *classIdStr =3D NULL; - char *floor_sum =3D NULL; + g_autofree char *classIdStr =3D NULL; + g_autofree char *floor_sum =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; =20 ctxt->node =3D node; if ((classIdStr =3D virXPathString("string(./class_id[1]/@bitmap)", ctxt))) { - if (!(classIdMap =3D virBitmapParseUnlimited(classIdStr))) { - VIR_FREE(classIdStr); + if (!(classIdMap =3D virBitmapParseUnlimited(classIdStr))) goto error; - } } - VIR_FREE(classIdStr); =20 floor_sum =3D virXPathString("string(./floor[1]/@sum)", ctxt); if (floor_sum && @@ -922,31 +920,26 @@ virNetworkLoadState(virNetworkObjList *nets, virReportError(VIR_ERR_INTERNAL_ERROR, _("Malformed 'floor_sum' attribute: %s"), floor_sum); - VIR_FREE(floor_sum); goto error; } - VIR_FREE(floor_sum); =20 if ((n =3D virXPathNodeSet("./taint", ctxt, &nodes)) < 0) goto error; =20 for (i =3D 0; i < n; i++) { - char *str =3D virXMLPropString(nodes[i], "flag"); + g_autofree char *str =3D virXMLPropString(nodes[i], "flag"); if (str) { int flag =3D virNetworkTaintTypeFromString(str); if (flag < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown taint flag %s"), str); - VIR_FREE(str); goto error; } - VIR_FREE(str); /* Compute taint mask here. The network object does not * exist yet, so we can't use virNetworkObjtTaint. */ taint |=3D (1 << flag); } } - VIR_FREE(nodes); } =20 /* create the object */ @@ -958,7 +951,7 @@ virNetworkLoadState(virNetworkObjList *nets, /* assign status data stored in the network object */ if (classIdMap) { virBitmapFree(obj->classIdMap); - obj->classIdMap =3D classIdMap; + obj->classIdMap =3D g_steal_pointer(&classIdMap); } =20 if (floor_sum_val > 0) @@ -967,17 +960,11 @@ virNetworkLoadState(virNetworkObjList *nets, obj->taint =3D taint; obj->active =3D true; /* network with a state file is by definition ac= tive */ =20 - cleanup: - VIR_FREE(configFile); - xmlFreeDoc(xml); - xmlXPathFreeContext(ctxt); return obj; =20 error: - VIR_FREE(nodes); - virBitmapFree(classIdMap); virNetworkDefFree(def); - goto cleanup; + return NULL; } =20 =20 --=20 2.31.1