From nobody Sun May 5 19:35:57 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.zoho.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 1496320386657766.4960812023155; Thu, 1 Jun 2017 05:33:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7233C80488; Thu, 1 Jun 2017 12:33:04 +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 4B08E17D22; Thu, 1 Jun 2017 12:33:04 +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 BE741180BAF5; Thu, 1 Jun 2017 12:33:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v51CX1kC026397 for ; Thu, 1 Jun 2017 08:33:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 75E0B53CC7; Thu, 1 Jun 2017 12:33:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6063E53CCB; Thu, 1 Jun 2017 12:32:59 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1 with cipher RC4-SHA (112/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 841FDC05FFCA; Thu, 1 Jun 2017 12:32:55 +0000 (UTC) Received: from 172.30.72.55 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.55]) by dggrg02-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOO80148; Thu, 01 Jun 2017 20:26:44 +0800 (CST) Received: from localhost (10.177.223.127) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Thu, 1 Jun 2017 20:26:36 +0800 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7233C80488 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7233C80488 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 841FDC05FFCA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fangying1@huawei.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 841FDC05FFCA From: fangying To: Date: Thu, 1 Jun 2017 20:25:40 +0800 Message-ID: <20170601122540.19492-1-fangying1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.223.127] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59300804.00B4, 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: 9d07029f19c4d5cc06cf9f3ccc54cac3 X-Greylist: Delayed for 00:06:08 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 01 Jun 2017 12:32:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 01 Jun 2017 12:32:57 +0000 (UTC) for IP:'45.249.212.188' DOMAIN:'szxga02-in.huawei.com' HELO:'szxga02-in.huawei.com' FROM:'fangying1@huawei.com' RCPT:'' X-RedHat-Spam-Score: 0.398 (BAYES_50, DCC_REPUT_00_12, RP_MATCHES_RCVD, SPF_PASS) 45.249.212.188 szxga02-in.huawei.com 45.249.212.188 szxga02-in.huawei.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: fangying1@huawei.com, wangxinxin.wang@huawei.com, herongguang.he@huawei.com, king.wang@huawei.com Subject: [libvirt] [PATCH] EventRegister: Fix double deference error in libvirt_virConnectDomainEventRegisterAny 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 01 Jun 2017 12:33:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As descriped at https://www.spinics.net/linux/fedora/libvir/msg148562.html, even when virConnectDomainEventRegisterAny returns -1 there is still a scenario in which it will trigger the free callback. We fix the problem in = the following way: (1) implement a function virObjectEventStateSetFreeCB to add freecallback. (2) call virObjectEventStateSetFreeCB only if the event is successfully add= ed. Signed-off-by: fangying --- src/conf/object_event.c | 34 ++++++++++++++++++++++++++++++++++ src/conf/object_event.h | 7 +++++++ src/libvirt_private.syms | 2 +- src/remote/remote_driver.c | 4 ++-- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/conf/object_event.c b/src/conf/object_event.c index e5f942f..a770978 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -923,6 +923,40 @@ virObjectEventStateRegisterID(virConnectPtr conn, =20 =20 /** + * virObjectEventStateSetFreeCB: + * @conn: connection to associate with callback + * @state: object event state + * @callbackID: ID of the function to remove from event + * @freecb: freecb to be added + * + * Add the callbalck function @freecb for @callbackID with connection @con= n, + * from @state, for events. + */ +void +virObjectEventStateSetFreeCB(virConnectPtr conn, + virObjectEventStatePtr state, + int callbackID, + virFreeCallback freecb) +{ + size_t i; + virObjectEventCallbackListPtr cbList; + + virObjectEventStateLock(state); + cbList =3D state->callbacks; + for (i =3D 0; i < cbList->count; i++) { + virObjectEventCallbackPtr cb =3D cbList->callbacks[i]; + + if (cb->callbackID =3D=3D callbackID && cb->conn =3D=3D conn) { + cb->freecb =3D freecb; + break; + } + } + + virObjectEventStateUnlock(state); +} + + +/** * virObjectEventStateDeregisterID: * @conn: connection to associate with callback * @state: object event state diff --git a/src/conf/object_event.h b/src/conf/object_event.h index 7a9995e..a7d29a0 100644 --- a/src/conf/object_event.h +++ b/src/conf/object_event.h @@ -90,4 +90,11 @@ virObjectEventStateSetRemote(virConnectPtr conn, int remoteID) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +void +virObjectEventStateSetFreeCB(virConnectPtr conn, + virObjectEventStatePtr state, + int callbackID, + virFreeCallback freecb) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); + #endif diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 429b095..e9d9cb6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -791,7 +791,7 @@ virObjectEventStateDeregisterID; virObjectEventStateEventID; virObjectEventStateNew; virObjectEventStateQueue; - +virObjectEventStateSetFreeCB; =20 # conf/secret_conf.h virSecretDefFormat; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d27e96f..71177bd 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5947,7 +5947,7 @@ remoteConnectDomainEventRegisterAny(virConnectPtr con= n, =20 if ((count =3D virDomainEventStateRegisterClient(conn, priv->eventStat= e, dom, eventID, callback, - opaque, freecb, false, + opaque, NULL, false, &callbackID, priv->serverEventFilter= )) < 0) goto done; @@ -5993,7 +5993,7 @@ remoteConnectDomainEventRegisterAny(virConnectPtr con= n, } =20 rv =3D callbackID; - + virObjectEventStateSetFreeCB(conn, priv->eventState, callbackID, freec= b); done: remoteDriverUnlock(priv); return rv; --=20 2.10.0.windows.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list