From nobody Sun Feb 8 22:42:55 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=1637956376; cv=none; d=zohomail.com; s=zohoarc; b=ln5D9CnWwneModS/yir0Rk6jB56hySz84bdBXB0Hn2JqxvC17Ir/nuDO0wPWeo/8XpRZ0VTjqS99+019fIYiau2mSU/Kj/ablOGmAbgbcteNKdOzF8kTxG+WLRcV6OhyG/pBm/dBtPJpuNNutHZ4u/ZLh619cmof330EZtjmVsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637956376; 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=fGGXI4tDBDd4UKpsrytlQBuRdnjObD1yNn4CIDjiSYE=; b=OTHqxdKAnFcL0A6nXUpPN5nvGj52nT5jBW03t4uOWg1rgj+4QmBicqqUIpOlW2A+bC/N3mSF1QpzZawQLL77e3M5boYGmSiCQOcR6O+wlhFlES/iL5NssWznT+ktCRpU08DI48b7GIqu+YsDhy65rYG8HF8KgMWA0SSyllz21y0= 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 1637956376136780.446466778973; Fri, 26 Nov 2021 11:52:56 -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-366-1cEUyrspNSKsq4v19ZgMqA-1; Fri, 26 Nov 2021 14:52:53 -0500 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 92CC281CCB5; Fri, 26 Nov 2021 19:52:48 +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 774E4ADD6; Fri, 26 Nov 2021 19:52:48 +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 45C974A7CB; Fri, 26 Nov 2021 19:52:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1AQJqQRl013327 for ; Fri, 26 Nov 2021 14:52:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1551F5D9CA; Fri, 26 Nov 2021 19:52:26 +0000 (UTC) Received: from rein.int.mamuti.net (unknown [10.40.192.161]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B68F65D9C0 for ; Fri, 26 Nov 2021 19:52:22 +0000 (UTC) Received: by rein.int.mamuti.net (Postfix, from userid 500) id 8D8F518BB30; Fri, 26 Nov 2021 20:52:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637956375; 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=fGGXI4tDBDd4UKpsrytlQBuRdnjObD1yNn4CIDjiSYE=; b=eEedGR+4xM2mJewZoIx03ZNc44rNIyXkXMagdU9Q9xt0CE8BdhtVUisQYNgx72sMuo5S/C TSaHu4S/ooHaShkLDmfIw9MsOTpNv8C84QSfd3gncPeNlUnhqhM34uUC95J4eLd+Ik0aIO oz1DSun7l/RIeMbWE2h8vTEzD539D2k= X-MC-Unique: 1cEUyrspNSKsq4v19ZgMqA-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] virnetserver: Use autoptr for virNetServer and virNetServerClient Date: Fri, 26 Nov 2021 20:52:18 +0100 Message-Id: <7e9b10c42cd70cd5a0d85a60942562996742c825.1637956256.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637956376482100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/rpc/virnetserver.c | 64 +++++++++++++++--------------------- src/rpc/virnetserverclient.h | 2 ++ 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index f016f15f39..d0f248e7f5 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -342,7 +342,7 @@ virNetServerDispatchNewClient(virNetServerService *svc, void *opaque) { virNetServer *srv =3D opaque; - virNetServerClient *client; + g_autoptr(virNetServerClient) client =3D NULL; =20 if (!(client =3D virNetServerClientNew(virNetServerNextClientID(srv), clientsock, @@ -358,10 +358,8 @@ virNetServerDispatchNewClient(virNetServerService *svc, =20 if (virNetServerAddClient(srv, client) < 0) { virNetServerClientClose(client); - virObjectUnref(client); return -1; } - virObjectUnref(client); return 0; } =20 @@ -381,7 +379,7 @@ virNetServerNew(const char *name, virFreeCallback clientPrivFree, void *clientPrivOpaque) { - virNetServer *srv; + g_autoptr(virNetServer) srv =3D NULL; =20 if (virNetServerInitialize() < 0) return NULL; @@ -395,7 +393,7 @@ virNetServerNew(const char *name, "rpc-worker", NULL, srv))) - goto error; + return NULL; =20 srv->name =3D g_strdup(name); =20 @@ -409,10 +407,7 @@ virNetServerNew(const char *name, srv->clientPrivFree =3D clientPrivFree; srv->clientPrivOpaque =3D clientPrivOpaque; =20 - return srv; - error: - virObjectUnref(srv); - return NULL; + return g_steal_pointer(&srv); } =20 =20 @@ -425,7 +420,7 @@ virNetServerNewPostExecRestart(virJSONValue *object, virFreeCallback clientPrivFree, void *clientPrivOpaque) { - virNetServer *srv =3D NULL; + g_autoptr(virNetServer) srv =3D NULL; virJSONValue *clients; virJSONValue *services; size_t i; @@ -441,29 +436,29 @@ virNetServerNewPostExecRestart(virJSONValue *object, if (virJSONValueObjectGetNumberUint(object, "min_workers", &min_worker= s) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing min_workers data in JSON document")); - goto error; + return NULL; } if (virJSONValueObjectGetNumberUint(object, "max_workers", &max_worker= s) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing max_workers data in JSON document")); - goto error; + return NULL; } if (virJSONValueObjectGetNumberUint(object, "priority_workers", &prior= ity_workers) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing priority_workers data in JSON document")= ); - goto error; + return NULL; } if (virJSONValueObjectGetNumberUint(object, "max_clients", &max_client= s) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing max_clients data in JSON document")); - goto error; + return NULL; } if (virJSONValueObjectHasKey(object, "max_anonymous_clients")) { if (virJSONValueObjectGetNumberUint(object, "max_anonymous_clients= ", &max_anonymous_clients) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Malformed max_anonymous_clients data in JSON= document")); - goto error; + return NULL; } } else { max_anonymous_clients =3D max_clients; @@ -471,12 +466,12 @@ virNetServerNewPostExecRestart(virJSONValue *object, if (virJSONValueObjectGetNumberUint(object, "keepaliveInterval", &keep= aliveInterval) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing keepaliveInterval data in JSON document"= )); - goto error; + return NULL; } if (virJSONValueObjectGetNumberUint(object, "keepaliveCount", &keepali= veCount) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing keepaliveCount data in JSON document")); - goto error; + return NULL; } =20 if (virJSONValueObjectGetNumberUlong(object, "next_client_id", @@ -492,18 +487,18 @@ virNetServerNewPostExecRestart(virJSONValue *object, keepaliveInterval, keepaliveCount, clientPrivNew, clientPrivPreExecRestart, clientPrivFree, clientPrivOpaque))) - goto error; + return NULL; =20 if (!(services =3D virJSONValueObjectGet(object, "services"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing services data in JSON document")); - goto error; + return NULL; } =20 if (!virJSONValueIsArray(services)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Malformed services array")); - goto error; + return NULL; } =20 for (i =3D 0; i < virJSONValueArraySize(services); i++) { @@ -512,15 +507,15 @@ virNetServerNewPostExecRestart(virJSONValue *object, if (!child) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing service data in JSON document")); - goto error; + return NULL; } =20 if (!(service =3D virNetServerServiceNewPostExecRestart(child))) - goto error; + return NULL; =20 if (virNetServerAddService(srv, service) < 0) { virObjectUnref(service); - goto error; + return NULL; } } =20 @@ -528,22 +523,22 @@ virNetServerNewPostExecRestart(virJSONValue *object, if (!(clients =3D virJSONValueObjectGet(object, "clients"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing clients data in JSON document")); - goto error; + return NULL; } =20 if (!virJSONValueIsArray(clients)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Malformed clients array")); - goto error; + return NULL; } =20 for (i =3D 0; i < virJSONValueArraySize(clients); i++) { - virNetServerClient *client; + g_autoptr(virNetServerClient) client =3D NULL; virJSONValue *child =3D virJSONValueArrayGet(clients, i); if (!child) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing client data in JSON document")); - goto error; + return NULL; } =20 if (!(client =3D virNetServerClientNewPostExecRestart(srv, @@ -552,20 +547,13 @@ virNetServerNewPostExecRestart(virJSONValue *object, clientPrivPreE= xecRestart, clientPrivFree, clientPrivOpaq= ue))) - goto error; + return NULL; =20 - if (virNetServerAddClient(srv, client) < 0) { - virObjectUnref(client); - goto error; - } - virObjectUnref(client); + if (virNetServerAddClient(srv, client) < 0) + return NULL; } =20 - return srv; - - error: - virObjectUnref(srv); - return NULL; + return g_steal_pointer(&srv); } =20 =20 diff --git a/src/rpc/virnetserverclient.h b/src/rpc/virnetserverclient.h index a9d0afe95a..0d585eb2ce 100644 --- a/src/rpc/virnetserverclient.h +++ b/src/rpc/virnetserverclient.h @@ -28,8 +28,10 @@ #include "virjson.h" =20 typedef struct _virNetServer virNetServer; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetServer, virObjectUnref); =20 typedef struct _virNetServerClient virNetServerClient; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetServerClient, virObjectUnref); =20 /* This function owns the "msg" pointer it is passed and * must arrange for virNetMessageFree to be called on it --=20 2.34.0