From nobody Sun Feb 8 21:33:44 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538148523744600.3558673516508; Fri, 28 Sep 2018 08:28:43 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9B4E07F6D0; Fri, 28 Sep 2018 15:28:41 +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 51DF9106A7A1; Fri, 28 Sep 2018 15:28:41 +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 ED8D44A46E; Fri, 28 Sep 2018 15:28:40 +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 w8SFSGNv029705 for ; Fri, 28 Sep 2018 11:28:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 89F8B600C7; Fri, 28 Sep 2018 15:28:16 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-116.phx2.redhat.com [10.3.116.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41C84600C1 for ; Fri, 28 Sep 2018 15:28:16 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 28 Sep 2018 11:28:05 -0400 Message-Id: <20180928152810.27537-3-jferlan@redhat.com> In-Reply-To: <20180928152810.27537-1-jferlan@redhat.com> References: <20180928152810.27537-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] libxl: Fix possible object refcnt issue 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 28 Sep 2018 15:28:42 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When libxlDomainMigrationDstPrepare adds the @args to an virNetSocketAddIOCallback using libxlMigrateDstReceive as the target of the virNetSocketIOFunc @func with the knowledge that the libxlMigrateDstReceive will virObjectUnref @args at the end thus not needing to Unref during normal processing for libxlDomainMigrationDstPrepare. However, Coverity believes there's an issue with this. The problem is there can be @nsocks virNetSocketAddIOCallback's added, but only one virObjectUnref. That means the first one done will Unref and the subsequent callers may not get the @args (or @opaque) as they expected. If there's only one socket returned from virNetSocketNewListenTCP, then sure that works. However, if it returned more than one there's going to be a problem. To resolve this, since we start with 1 reference from the virObjectNew for @args, we will add 1 reference for each time @args is used for virNetSocketAddIOCallback. Then since libxlDomainMigrationDstPrepare would be done with @args, move it's virObjectUnref from the error: label to the done: label (since error: falls through). That way once the last IOCallback is done, then @args will be freed. Signed-off-by: John Ferlan --- src/libxl/libxl_migration.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index fc7ccb53d0..88d7ecf2ce 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -793,7 +793,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, if (virNetSocketAddIOCallback(socks[i], VIR_EVENT_HANDLE_READABLE, libxlMigrateDstReceive, - args, + virObjectRef(args), NULL) < 0) continue; =20 @@ -815,7 +815,6 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, virObjectUnref(socks[i]); } VIR_FREE(socks); - virObjectUnref(args); if (priv) { virPortAllocatorRelease(priv->migrationPort); priv->migrationPort =3D 0; @@ -831,6 +830,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, VIR_FREE(hostname); else virURIFree(uri); + virObjectUnref(args); virDomainObjEndAPI(&vm); virObjectUnref(cfg); return ret; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list