From nobody Mon Apr 29 07:32:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508824384476863.4228984046816; Mon, 23 Oct 2017 22:53:04 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9CEEA7CB83; Tue, 24 Oct 2017 05:53:01 +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 F33B218000; Tue, 24 Oct 2017 05:52:59 +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 D6BB71804482; Tue, 24 Oct 2017 05:52:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9O5qtnS011159 for ; Tue, 24 Oct 2017 01:52:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 71C4B51C8A; Tue, 24 Oct 2017 05:52:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 685AF17D3E; Tue, 24 Oct 2017 05:52:53 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1 with cipher RC4-SHA (112/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF68C343395; Tue, 24 Oct 2017 05:52:50 +0000 (UTC) Received: from 172.30.72.60 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJR90605; Tue, 24 Oct 2017 13:52:48 +0800 (CST) Received: from localhost (10.177.25.200) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Tue, 24 Oct 2017 13:52:42 +0800 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9CEEA7CB83 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9CEEA7CB83 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF68C343395 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=caoxinhua@huawei.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CF68C343395 From: "xinhua.Cao" To: , , , Date: Tue, 24 Oct 2017 13:52:28 +0800 Message-ID: <20171024055228.11540-1-caoxinhua@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.25.200] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59EED530.003F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ef46d278defcbb91c3e3410460f83d4d X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 205 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 24 Oct 2017 05:52:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 24 Oct 2017 05:52:52 +0000 (UTC) for IP:'45.249.212.190' DOMAIN:'szxga04-in.huawei.com' HELO:'szxga04-in.huawei.com' FROM:'caoxinhua@huawei.com' RCPT:'' X-RedHat-Spam-Score: -0.012 (RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS) 45.249.212.190 szxga04-in.huawei.com 45.249.212.190 szxga04-in.huawei.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: "xinhua.Cao" , yanqiangjun@huawei.com, weidong.huang@huawei.com, king.wang@huawei.com, weifuqiang@huawei.com Subject: [libvirt] [PATCH] remote: Fix libvirtd service memory leak when libvirt client was terminated unexpectly 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 24 Oct 2017 05:53:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" base on commit 2033e8cc119454bc4273e8a41e66c899c60ba58b and fe8f1c8b8650c8a= b5e7d27338f4538582651bd14, we solve libvirt coredump problem, but it introd= uce a memory leak sense. the sense follow 1. one client register a domain event such as reboot event 2. and client was terminated unexpectly, then this client will not free at = libvirtd service program. remoteDispatchConnectDomainEventCallbackRegisterAny reference the client, b= ut when client was terminated before it call deRegisterAny, the reference o= f client will not reduced to zero. so the memory leak take place. this patc= h will deRegister all event when client was close. --- daemon/remote.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 3f7d2d3..2b5a18b 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1686,25 +1686,16 @@ void remoteRelayConnectionClosedEvent(virConnectPtr= conn ATTRIBUTE_UNUSED, int r VIR_WARN("unexpected %s event deregister failure", name); = \ } = \ VIR_FREE(eventCallbacks); = \ + neventCallbacks =3D 0; = \ } while (0); =20 -/* - * You must hold lock for at least the client - * We don't free stuff here, merely disconnect the client's - * network socket & resources. - * We keep the libvirt connection open until any async - * jobs have finished, then clean it up elsewhere - */ -void remoteClientFreeFunc(void *data) +static void +remoteFreePrivCallbacks(void *data) { struct daemonClientPrivate *priv =3D data; =20 /* Deregister event delivery callback */ - if (priv->conn) { - virIdentityPtr sysident =3D virIdentityGetSystem(); - - virIdentitySetCurrent(sysident); - + if (priv && priv->conn) { DEREG_CB(priv->conn, priv->domainEventCallbacks, priv->ndomainEventCallbacks, virConnectDomainEventDeregisterAny, "domain"); @@ -1723,6 +1714,26 @@ void remoteClientFreeFunc(void *data) DEREG_CB(priv->conn, priv->qemuEventCallbacks, priv->nqemuEventCallbacks, virConnectDomainQemuMonitorEventDeregister, "qemu monitor= "); + } +} +#undef DEREG_CB + +/* + * You must hold lock for at least the client + * We don't free stuff here, merely disconnect the client's + * network socket & resources. + * We keep the libvirt connection open until any async + * jobs have finished, then clean it up elsewhere + */ +void remoteClientFreeFunc(void *data) +{ + struct daemonClientPrivate *priv =3D data; + + if (priv) { + virIdentityPtr sysident =3D virIdentityGetSystem(); + + virIdentitySetCurrent(sysident); + remoteFreePrivCallbacks(priv); =20 if (priv->closeRegistered) { if (virConnectUnregisterCloseCallback(priv->conn, @@ -1734,18 +1745,18 @@ void remoteClientFreeFunc(void *data) =20 virIdentitySetCurrent(NULL); virObjectUnref(sysident); + VIR_FREE(priv); } - - VIR_FREE(priv); } -#undef DEREG_CB - =20 static void remoteClientCloseFunc(virNetServerClientPtr client) { struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(= client); =20 - daemonRemoveAllClientStreams(priv->streams); + if (priv) { + daemonRemoveAllClientStreams(priv->streams); + remoteFreePrivCallbacks(priv); + } } =20 =20 --=20 2.8.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list