From nobody Sun Apr 28 18:09:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1568879830; cv=none; d=zoho.com; s=zohoarc; b=GQED4z+nQlrAj40j2K+QbFtL4Vu1Vu1nhoKqqV1CKt8B4icHPuDcTh1WtdGM0BITck51TmZfQ5bRclcRDb2/fKRFkqK0Yzt6OdhPGqTNuxscJn0H6p7NxfXpQ37vvBvR6mbjuFs2MhgUciaBJb0uFRniFSpHHRYcXefxKJcin2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568879830; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=cliwUnoeooK9HFM3NY9S+bbFefZ/Bfq+5XhokUQgmlw=; b=Fb2Cs8PbaRzLHPcgD2iYIjta0Ruc6ZXD4vkDWz0a1Y0uYLos3BtavgaDjZbn9Y6i8zrdIWeVTzfN1P6GQya4LhB0yVy1v/YAbT9R/EkmWYG3K/qJtaNE1OmQ5WuG6MwWbMZTz+aAczY1f/ZtbnxYIzctii5UXMlGnOEBpr9vzVM= ARC-Authentication-Results: i=1; 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 1568879830983463.9991596218066; Thu, 19 Sep 2019 00:57:10 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6822C308218D; Thu, 19 Sep 2019 07:57:09 +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 3AFA460606; Thu, 19 Sep 2019 07:57:09 +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 EAA80180BA98; Thu, 19 Sep 2019 07:57:08 +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 x8J7v8vB032727 for ; Thu, 19 Sep 2019 03:57:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 025AE60167; Thu, 19 Sep 2019 07:57:08 +0000 (UTC) Received: from mx1.redhat.com (ext-mx25.extmail.prod.ext.phx2.redhat.com [10.5.110.66]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1CB66012E for ; Thu, 19 Sep 2019 07:57:02 +0000 (UTC) Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B41010C0938 for ; Thu, 19 Sep 2019 07:57:02 +0000 (UTC) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A347DACD1DBD0662F258 for ; Thu, 19 Sep 2019 15:57:00 +0800 (CST) Received: from localhost (10.175.124.177) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Thu, 19 Sep 2019 15:56:51 +0800 From: Xu Yandong To: Date: Thu, 19 Sep 2019 04:02:15 -0400 Message-ID: <1568880135-88269-1-git-send-email-xuyandong2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.177] X-CFilter-Loop: Reflected X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 238 matched, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 19 Sep 2019 07:57:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 19 Sep 2019 07:57:02 +0000 (UTC) for IP:'45.249.212.32' DOMAIN:'szxga06-in.huawei.com' HELO:'huawei.com' FROM:'xuyandong2@huawei.com' RCPT:'' X-RedHat-Spam-Score: -2.302 (RCVD_IN_DNSWL_MED, SPF_HELO_PASS, SPF_PASS) 45.249.212.32 szxga06-in.huawei.com 45.249.212.32 szxga06-in.huawei.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.66 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Xu Yandong , zhang.zhanghailiang@huawei.com Subject: [libvirt] [PATCH] event: reference state only when virEventAddTimeout success 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 19 Sep 2019 07:57:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Reference state is not necessary when virEventAddTimeout failed, this may cause a memory leak, so reference state only when virEventAddTimeout success. Signed-off-by: Xu Yandong Reviewed-by: Daniel Henrique Barboza --- src/conf/object_event.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/conf/object_event.c b/src/conf/object_event.c index 5d84598d59..ee5def5910 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -891,20 +891,21 @@ virObjectEventStateRegisterID(virConnectPtr conn, virObjectLock(state); =20 if ((state->callbacks->count =3D=3D 0) && - (state->timer =3D=3D -1) && - (state->timer =3D virEventAddTimeout(-1, - virObjectEventTimer, - state, - virObjectFreeCallback)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("could not initialize domain event timer")); - goto cleanup; + (state->timer =3D=3D -1)) { + if ((state->timer =3D virEventAddTimeout(-1, + virObjectEventTimer, + state, + virObjectFreeCallback)) < 0= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not initialize domain event timer")); + goto cleanup; + } else { + /* event loop has one reference, but we need one more for the + * timer's opaque argument */ + virObjectRef(state); + } } =20 - /* event loop has one reference, but we need one more for the - * timer's opaque argument */ - virObjectRef(state); - ret =3D virObjectEventCallbackListAddID(conn, state->callbacks, key, filter, filter_opaque, klass, eventID, --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list