From nobody Mon Feb 9 20:30:51 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com 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 1633111542512855.0678439650186; Fri, 1 Oct 2021 11:05:42 -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-cC1-dU_WMN6rXhcRblbGog-1; Fri, 01 Oct 2021 14:05:37 -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 7BBE5802C92; Fri, 1 Oct 2021 18:05:32 +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 54E0119736; Fri, 1 Oct 2021 18:05:32 +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 250FA4EA30; Fri, 1 Oct 2021 18:05:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191I5Ufm003421 for ; Fri, 1 Oct 2021 14:05:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 72E4F2168683; Fri, 1 Oct 2021 18:05:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D8272168680 for ; Fri, 1 Oct 2021 18:05:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B37C802A5E for ; Fri, 1 Oct 2021 18:05:27 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-sra-hYeCPUKLYCk_1cdOBg-3; Fri, 01 Oct 2021 14:05:23 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2021 11:04:54 -0700 Received: from wdouglas-dev.jf.intel.com (HELO desk.jf.intel.com) ([10.7.200.157]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2021 11:04:47 -0700 X-MC-Unique: cC1-dU_WMN6rXhcRblbGog-1 X-MC-Unique: sra-hYeCPUKLYCk_1cdOBg-3 X-IronPort-AV: E=McAfee;i="6200,9189,10124"; a="223618446" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="223618446" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="708807844" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 5/5] ch: use g_auto in virCHMonitorNew Date: Fri, 1 Oct 2021 11:12:37 -0700 Message-Id: <20211001181237.1755924-6-william.douglas@intel.com> In-Reply-To: <20211001181237.1755924-1-william.douglas@intel.com> References: <20211001181237.1755924-1-william.douglas@intel.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: William Douglas , jtomko@redhat.com, laine@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-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633111542997100001 Content-Type: text/plain; charset="utf-8" Also introduces a G_DEFINE_AUTOPTR_CLEANUP_FUNC for virCHMonitor. Signed-off-by: William Douglas --- src/ch/ch_monitor.c | 22 +++++++--------------- src/ch/ch_monitor.h | 1 + 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index bb49c70069..376404033e 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -442,9 +442,8 @@ chMonitorCreateSocket(const char *socket_path) virCHMonitor * virCHMonitorNew(virDomainObj *vm, const char *socketdir) { - virCHMonitor *ret =3D NULL; - virCHMonitor *mon =3D NULL; - virCommand *cmd =3D NULL; + g_autoptr(virCHMonitor) mon =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; int socket_fd =3D 0; =20 if (virCHMonitorInitialize() < 0) @@ -456,7 +455,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) if (!vm->def) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("VM is not defined")); - goto cleanup; + return NULL; } =20 /* prepare to launch Cloud-Hypervisor socket */ @@ -465,7 +464,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) virReportSystemError(errno, _("Cannot create socket directory '%s'"), socketdir); - goto cleanup; + return NULL; } =20 cmd =3D virCommandNew(vm->def->emulator); @@ -475,7 +474,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) virReportSystemError(errno, _("Cannot create socket '%s'"), mon->socketpath); - goto cleanup; + return NULL; } =20 virCommandAddArg(cmd, "--api-socket"); @@ -484,7 +483,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) =20 /* launch Cloud-Hypervisor socket */ if (virCommandRunAsync(cmd, &mon->pid) < 0) - goto cleanup; + return NULL; =20 /* get a curl handle */ mon->handle =3D curl_easy_init(); @@ -492,14 +491,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdi= r) /* now has its own reference */ mon->vm =3D virObjectRef(vm); =20 - ret =3D mon; - mon =3D NULL; - - cleanup: - if (mon) - virCHMonitorClose(mon); - virCommandFree(cmd); - return ret; + return g_steal_pointer(&mon); } =20 static void virCHMonitorDispose(void *opaque) diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index e39b4eb8b2..0f684ca583 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -53,6 +53,7 @@ struct _virCHMonitor { =20 virCHMonitor *virCHMonitorNew(virDomainObj *vm, const char *socketdir); void virCHMonitorClose(virCHMonitor *mon); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose); =20 int virCHMonitorCreateVM(virCHMonitor *mon); int virCHMonitorBootVM(virCHMonitor *mon); --=20 2.33.0