From nobody Fri May 3 06:11:53 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 1509153886631618.7417219388304; Fri, 27 Oct 2017 18:24:46 -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 18D614E4C8; Sat, 28 Oct 2017 01:24: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 01FC65C3FF; Sat, 28 Oct 2017 01:24:43 +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 635381808800; Sat, 28 Oct 2017 01:24:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9S1Ob7T001648 for ; Fri, 27 Oct 2017 21:24:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 927BB60561; Sat, 28 Oct 2017 01:24:37 +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 DA02460465; Sat, 28 Oct 2017 01:24:35 +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 F1E7537EEF; Sat, 28 Oct 2017 01:24:32 +0000 (UTC) Received: from 172.30.72.60 (EHLO DGGEMS410-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJX57292; Sat, 28 Oct 2017 09:24:31 +0800 (CST) Received: from localhost (10.177.25.200) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Sat, 28 Oct 2017 09:23:48 +0800 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 18D614E4C8 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx09.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 18D614E4C8 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1E7537EEF 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 F1E7537EEF From: "xinhua.Cao" To: , , , Date: Sat, 28 Oct 2017 09:23:45 +0800 Message-ID: <20171028012345.10316-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.0A090206.59F3DC4F.0022, 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: 8de71d4924cb183d6f3b9c76afad15c8 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]); Sat, 28 Oct 2017 01:24:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 28 Oct 2017 01:24:35 +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.11 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] fix libvirtd memory leak when client was killed by user at eventRegister sense 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-Type: text/plain; charset="utf-8" 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.38]); Sat, 28 Oct 2017 01:24:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 =E3=80=90DTS/AR=E3=80=91:DTS2017102200357 =E3=80=90description=E3=80=91:=E5=BD=93=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=B3=A8= =E5=86=8Clibvirt=E4=BA=8B=E4=BB=B6=E5=90=8E=EF=BC=8C=E5=B0=86=E5=AE=A2=E6= =88=B7=E7=AB=AF=E8=BF=9B=E7=A8=8BKill=EF=BC=8Clibvirtd=E6=9C=8D=E5=8A=A1=E7= =AB=AF=E4=BC=9A=E6=9C=89=E5=86=85=E5=AD=98=E6=B3=84=E9=9C=B2=E3=80=82 Change-Id: I7eeffb4f1ba46038cd41fd26e6725ad2943229a8 --- daemon/remote.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index f67370f..4b8de85 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1727,25 +1727,14 @@ 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; - - /* 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"); @@ -1764,6 +1753,27 @@ 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; + + /* Deregister event delivery callback */ + if (priv) { + virIdentityPtr sysident =3D virIdentityGetSystem(); + + virIdentitySetCurrent(sysident); + remoteFreePrivCallbacks(priv); =20 if (priv->closeRegistered) { if (virConnectUnregisterCloseCallback(priv->conn, @@ -1775,19 +1785,21 @@ void remoteClientFreeFunc(void *data) =20 virIdentitySetCurrent(NULL); virObjectUnref(sysident); - } =20 - VIR_FREE(priv->hmacSalt); - VIR_FREE(priv); + VIR_FREE(priv->hmacSalt); + VIR_FREE(priv); + } } -#undef DEREG_CB =20 =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