From nobody Mon Feb 9 01:31:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637687424; cv=none; d=zohomail.com; s=zohoarc; b=HhERid86/QrhpHOHS7cNts0u6YB5QppfS8L2zVOuCiyArhKHjUU1Yyb1+NK/wDdcOVXTTWJsVeRyDqm2RJb8kfbAbxthv6y1AJ87rTh6hETURxipt41w9IWmf2s735qLi9xhCUCVw1fF/nAXFBcw4Oxjzf7ntxLBswhACEfe+9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687424; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Bquw8oEzT8yqB7HulnY9MEwYn0/e/xczJI8FZ7kLan4=; b=ZeOv8M2fIarpe2PQg5GdE7xIxH/X6Nupgw6thaJHKo26ol6SF0Tct9AbEVQsZzWYj0dUgpnYJtmEyXjPEW5h6uZuHBLrNxRvDBXOh5eAtl8pHCjV1sbkMCQcV2OflSWZ5Mqsbo4syBTF2wFUhU2en661pxk12aAfGqd/Jp6IvsU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1637687424945850.9075732288746; Tue, 23 Nov 2021 09:10:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-545-Zr8l_f3cMWi-A-ZPNxpwig-1; Tue, 23 Nov 2021 12:10:19 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA40419611C9; Tue, 23 Nov 2021 17:10:00 +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 BC07760843; Tue, 23 Nov 2021 17:10:00 +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 887024E9F5; Tue, 23 Nov 2021 17:10:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ANH9ptg023118 for ; Tue, 23 Nov 2021 12:09:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id D26635C232; Tue, 23 Nov 2021 17:09:51 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 337146788C; Tue, 23 Nov 2021 17:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637687423; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Bquw8oEzT8yqB7HulnY9MEwYn0/e/xczJI8FZ7kLan4=; b=aC1FdiOW6/2Jy/z4pkg8GPnLwIutXXQ14eDMEsJh8gf9cUoaxW/zohtc36vLfWmiRUWa4W cNrauINIuFVHyIm6xEdO/cHCsxTE0+AX59uuu2FgFIpKTleAFFQ9gPEY2RvJC5tyU3FT73 1IZEvsnHFOt4T6QKK++/AWc9SNiz6Mg= X-MC-Unique: Zr8l_f3cMWi-A-ZPNxpwig-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] virInterfaceObjListAssignDef: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:37 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637687426935100001 Content-Type: text/plain; charset="utf-8" Upon successful return from virInterfaceObjListAssignDef() the virInterfaceObj is the owner of secret definition. To make this ownership transfer even more visible, lets pass the definition as a double pointer and use g_steal_pointer(). Signed-off-by: Michal Privoznik --- src/conf/virinterfaceobj.c | 25 +++++++++++++++++++------ src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 6 ++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index c5dfa6c7f5..daac74e88c 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -377,9 +377,8 @@ virInterfaceObjListCloneCb(void *payload, goto error; VIR_FREE(xml); =20 - if (!(obj =3D virInterfaceObjListAssignDef(data->dest, backup))) + if (!(obj =3D virInterfaceObjListAssignDef(data->dest, &backup))) goto error; - backup =3D NULL; virInterfaceObjEndAPI(&obj); =20 virObjectUnlock(srcObj); @@ -420,25 +419,39 @@ virInterfaceObjListClone(virInterfaceObjList *interfa= ces) } =20 =20 +/** + * virInterfaceObjListAssignDef: + * @interfaces: virInterface object list + * @def: new definition + * + * Assigns new definition to either an existing or newly created + * virInterface object. Upon successful return the virInterface + * object is the owner of @def and callers should use + * virInterfaceObjGetDef() if they need to access the definition + * as @def is set to NULL. + * + * Returns: a virInterface object instance on success, or + * NULL on error. + */ virInterfaceObj * virInterfaceObjListAssignDef(virInterfaceObjList *interfaces, - virInterfaceDef *def) + virInterfaceDef **def) { virInterfaceObj *obj; =20 virObjectRWLockWrite(interfaces); - if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, def->name= ))) { + if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, (*def)->n= ame))) { virInterfaceDefFree(obj->def); } else { if (!(obj =3D virInterfaceObjNew())) goto error; =20 - if (virHashAddEntry(interfaces->objsName, def->name, obj) < 0) + if (virHashAddEntry(interfaces->objsName, (*def)->name, obj) < 0) goto error; virObjectRef(obj); } =20 - obj->def =3D def; + obj->def =3D g_steal_pointer(def); virObjectRWUnlock(interfaces); =20 return obj; diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index d60faa95f2..5927484167 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -59,7 +59,7 @@ virInterfaceObjListClone(virInterfaceObjList *interfaces); =20 virInterfaceObj * virInterfaceObjListAssignDef(virInterfaceObjList *interfaces, - virInterfaceDef *def); + virInterfaceDef **def); =20 void virInterfaceObjListRemove(virInterfaceObjList *interfaces, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e45748c5fc..92c0462170 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1141,9 +1141,8 @@ testParseInterfaces(testDriver *privconn, if (!def) return -1; =20 - if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))) + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, &def)= )) return -1; - def =3D NULL; =20 virInterfaceObjSetActive(obj, true); virInterfaceObjEndAPI(&obj); @@ -6203,9 +6202,8 @@ testInterfaceDefineXML(virConnectPtr conn, if ((def =3D virInterfaceDefParseString(xmlStr, flags)) =3D=3D NULL) goto cleanup; =20 - if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) + if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, &def)) =3D= =3D NULL) goto cleanup; - def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); =20 ret =3D virGetInterface(conn, objdef->name, objdef->mac); --=20 2.32.0