From nobody Sun May 19 11:06:45 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633111558801466.1903046437757; Fri, 1 Oct 2021 11:05:58 -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-78-sdqC78glPBy4sgSYfv28jw-1; Fri, 01 Oct 2021 14:05:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 491E4802C98; Fri, 1 Oct 2021 18:05:47 +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 2B10A10016FF; Fri, 1 Oct 2021 18:05:47 +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 EE51F1800B8B; Fri, 1 Oct 2021 18:05:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191I5Qtw003391 for ; Fri, 1 Oct 2021 14:05:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C8F4117C2C4; Fri, 1 Oct 2021 18:05:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88499117C2C2 for ; Fri, 1 Oct 2021 18:05:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 71084899EC1 for ; Fri, 1 Oct 2021 18:05:26 +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-576-32EecU8VO9KAEssWc1w7zQ-2; 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:45 -0700 X-MC-Unique: sdqC78glPBy4sgSYfv28jw-1 X-MC-Unique: 32EecU8VO9KAEssWc1w7zQ-2 X-IronPort-AV: E=McAfee;i="6200,9189,10124"; a="223618442" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="223618442" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="708807819" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 1/5] ch_monitor: Stop leaking json value objects Date: Fri, 1 Oct 2021 11:12:33 -0700 Message-Id: <20211001181237.1755924-2-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.3 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.22 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: 1633111560954100001 Content-Type: text/plain; charset="utf-8" In virCHMonitorBuildKernelRelatedJson there are two cases of json value objects being lost after the pointer being redefined. This change removes the needless redefinition. Signed-off-by: William Douglas Reviewed-by: Laine Stump --- src/ch/ch_monitor.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 5ed26a574f..a1430f0e65 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -121,7 +121,6 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *conten= t, virDomainDef *vmdef) _("Kernel image path in this domain is not defined"= )); goto cleanup; } else { - kernel =3D virJSONValueNewObject(); if (virJSONValueObjectAppendString(kernel, "path", vmdef->os.kerne= l) < 0) goto cleanup; if (virJSONValueObjectAppend(content, "kernel", &kernel) < 0) @@ -136,7 +135,6 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *conten= t, virDomainDef *vmdef) } =20 if (vmdef->os.initrd !=3D NULL) { - initramfs =3D virJSONValueNewObject(); if (virJSONValueObjectAppendString(initramfs, "path", vmdef->os.in= itrd) < 0) goto cleanup; if (virJSONValueObjectAppend(content, "initramfs", &initramfs) < 0) --=20 2.33.0 From nobody Sun May 19 11:06:45 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633111552697454.14061015477466; Fri, 1 Oct 2021 11:05:52 -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-566-KKVm_aFJO1uK27Runv1rlw-1; Fri, 01 Oct 2021 14:05:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9EB6F1006AA6; Fri, 1 Oct 2021 18:05:44 +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 7E6755C1CF; Fri, 1 Oct 2021 18:05:44 +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 4AFDE1806D02; Fri, 1 Oct 2021 18:05:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191I5Qoq003385 for ; Fri, 1 Oct 2021 14:05:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2771A117C2C4; Fri, 1 Oct 2021 18:05:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23AC4117C2C2 for ; Fri, 1 Oct 2021 18:05:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 0C3BA8007B1 for ; Fri, 1 Oct 2021 18:05:26 +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-576-8REaxYwIP_qwUOsU9-u-7w-1; Fri, 01 Oct 2021 14:05:22 -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:45 -0700 X-MC-Unique: KKVm_aFJO1uK27Runv1rlw-1 X-MC-Unique: 8REaxYwIP_qwUOsU9-u-7w-1 X-IronPort-AV: E=McAfee;i="6200,9189,10124"; a="223618435" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="223618435" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="708807820" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 2/5] ch_monitor: Correctly close and ref the virCHMonitor Date: Fri, 1 Oct 2021 11:12:34 -0700 Message-Id: <20211001181237.1755924-3-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.3 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.79 on 10.5.11.16 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: 1633111554349100002 Content-Type: text/plain; charset="utf-8" In virCHMontiorNew the monitor object is referenced an additional time incorrectly preventing it from being disposed of. Because the disposal wasn't being used, a bug in virCHMonitorClose that would incorrectly unref the domain object wasn't being seen. This change fixes both. Signed-off-by: William Douglas Reviewed-by: Laine Stump --- src/ch/ch_monitor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index a1430f0e65..800457af41 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -468,7 +468,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir) if (!vm->def) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("VM is not defined")); - return NULL; + goto cleanup; } =20 /* prepare to launch Cloud-Hypervisor socket */ @@ -502,12 +502,14 @@ virCHMonitorNew(virDomainObj *vm, const char *socketd= ir) mon->handle =3D curl_easy_init(); =20 /* now has its own reference */ - virObjectRef(mon); mon->vm =3D virObjectRef(vm); =20 ret =3D mon; + mon =3D NULL; =20 cleanup: + if (mon) + virCHMonitorClose(mon); virCommandFree(cmd); return ret; } @@ -542,7 +544,6 @@ void virCHMonitorClose(virCHMonitor *mon) g_free(mon->socketpath); } =20 - virObjectUnref(mon->vm); virObjectUnref(mon); } =20 --=20 2.33.0 From nobody Sun May 19 11:06:45 2024 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 1633111539428111.6520800528292; Fri, 1 Oct 2021 11:05:39 -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-469-gTZWbYAJPpugCz5ab3og2g-1; Fri, 01 Oct 2021 14:05:36 -0400 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 89C771808311; Fri, 1 Oct 2021 18:05:30 +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 7961918EC5; Fri, 1 Oct 2021 18:05:29 +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 200E51800B8B; Fri, 1 Oct 2021 18:05:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191I5PHv003380 for ; Fri, 1 Oct 2021 14:05:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2774F117C2C2; Fri, 1 Oct 2021 18:05:25 +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 20876117A957 for ; Fri, 1 Oct 2021 18:05:22 +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 648AF80158D for ; Fri, 1 Oct 2021 18:05:22 +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-6_sRb9H-Ofi5Wx_1Yf38jg-1; Fri, 01 Oct 2021 14:05:20 -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:46 -0700 X-MC-Unique: gTZWbYAJPpugCz5ab3og2g-1 X-MC-Unique: 6_sRb9H-Ofi5Wx_1Yf38jg-1 X-IronPort-AV: E=McAfee;i="6200,9189,10124"; a="223618437" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="223618437" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="708807835" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 3/5] ch: use g_auto in virCHMonitorBuildMemoryJson Date: Fri, 1 Oct 2021 11:12:35 -0700 Message-Id: <20211001181237.1755924-4-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.3 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.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-ZM-MESSAGEID: 1633111540640100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: William Douglas Reviewed-by: Laine Stump --- src/ch/ch_monitor.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 800457af41..7326ac645b 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -154,22 +154,17 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *cont= ent, virDomainDef *vmdef) static int virCHMonitorBuildMemoryJson(virJSONValue *content, virDomainDef *vmdef) { - virJSONValue *memory; unsigned long long total_memory =3D virDomainDefGetMemoryInitial(vmdef= ) * 1024; =20 if (total_memory !=3D 0) { - memory =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) memory =3D virJSONValueNewObject(); if (virJSONValueObjectAppendNumberUlong(memory, "size", total_memo= ry) < 0) - goto cleanup; + return -1; if (virJSONValueObjectAppend(content, "memory", &memory) < 0) - goto cleanup; + return -1; } =20 return 0; - - cleanup: - virJSONValueFree(memory); - return -1; } =20 static int --=20 2.33.0 From nobody Sun May 19 11:06:45 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633111538920446.8796871416399; Fri, 1 Oct 2021 11:05:38 -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-146-xS5j3h8xOdCeNAROnd4dAw-1; Fri, 01 Oct 2021 14:05:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EDFB180831A; Fri, 1 Oct 2021 18:05:31 +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 5F8DD2C175; Fri, 1 Oct 2021 18:05:30 +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 5285C4EA2A; Fri, 1 Oct 2021 18:05:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191I5RQp003400 for ; Fri, 1 Oct 2021 14:05:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 39AB6117C2C4; Fri, 1 Oct 2021 18:05:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35200117C2C2 for ; Fri, 1 Oct 2021 18:05:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 1E4E01066680 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-472-82_JfDqvOK-l6vQXAM3U7w-1; 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:46 -0700 X-MC-Unique: xS5j3h8xOdCeNAROnd4dAw-1 X-MC-Unique: 82_JfDqvOK-l6vQXAM3U7w-1 X-IronPort-AV: E=McAfee;i="6200,9189,10124"; a="223618444" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="223618444" X-IronPort-AV: E=Sophos;i="5.85,339,1624345200"; d="scan'208";a="708807841" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 4/5] ch: use g_auto in virCHMonitorBuildKernelRelatedJson Date: Fri, 1 Oct 2021 11:12:36 -0700 Message-Id: <20211001181237.1755924-5-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.3 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.79 on 10.5.11.11 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: 1633111540533100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: William Douglas --- src/ch/ch_monitor.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 7326ac645b..bb49c70069 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -112,43 +112,36 @@ virCHMonitorBuildPTYJson(virJSONValue *content, virDo= mainDef *vmdef) static int virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vm= def) { - virJSONValue *kernel =3D virJSONValueNewObject(); - virJSONValue *cmdline =3D virJSONValueNewObject(); - virJSONValue *initramfs =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) kernel =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) cmdline =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) initramfs =3D virJSONValueNewObject(); =20 if (vmdef->os.kernel =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Kernel image path in this domain is not defined"= )); - goto cleanup; + return -1; } else { if (virJSONValueObjectAppendString(kernel, "path", vmdef->os.kerne= l) < 0) - goto cleanup; + return -1; if (virJSONValueObjectAppend(content, "kernel", &kernel) < 0) - goto cleanup; + return -1; } =20 if (vmdef->os.cmdline) { if (virJSONValueObjectAppendString(cmdline, "args", vmdef->os.cmdl= ine) < 0) - goto cleanup; + return -1; if (virJSONValueObjectAppend(content, "cmdline", &cmdline) < 0) - goto cleanup; + return -1; } =20 if (vmdef->os.initrd !=3D NULL) { if (virJSONValueObjectAppendString(initramfs, "path", vmdef->os.in= itrd) < 0) - goto cleanup; + return -1; if (virJSONValueObjectAppend(content, "initramfs", &initramfs) < 0) - goto cleanup; + return -1; } =20 return 0; - - cleanup: - virJSONValueFree(kernel); - virJSONValueFree(cmdline); - virJSONValueFree(initramfs); - - return -1; } =20 static int --=20 2.33.0 From nobody Sun May 19 11:06:45 2024 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