From nobody Sun Feb 8 23:41:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1643640863; cv=none; d=zohomail.com; s=zohoarc; b=H6SbGUlr3MQJGDFbNCuHiQkTpxneJREJiapuxlqpljFhwwRQPXplftGqg+6L13sGc6J01tldlKMXb94xPqJxROt9GrNEQ9Iqvpw75HQuE1WNuhXuu08Jrcx7mkFSMt0DhN0J9l6FQRa8vVc86r6cYtJ5IVR4yfp8pfx7riUiiIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643640863; 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=m2zXp2iE3NNi7PA0Q5kFWtoXNhRqpgVciQ8RyMuHDNI=; b=PfkozlxIa9FpedgNoTkgRDDnPq+1AJVwhz2NB8wOcDI4781vrBknXpVzSKisvwyPLjwGaCztw967q5vLQVNDjUhmhv4tlQnkFuFoeZ7k7AI69Wkd2o9GVaR7IbXFp4aWF3G8jH2PhK0hjPrpWsNTODONMAsFmWqs2xXo0RaLJYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 164364086300750.77561450417522; Mon, 31 Jan 2022 06:54:23 -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-362-KMTQ6LLIOcOTfdvZPxA6IA-1; Mon, 31 Jan 2022 09:54:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E58884B9AC; Mon, 31 Jan 2022 14:54:07 +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 EFE652E058; Mon, 31 Jan 2022 14:54:06 +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 616901806D03; Mon, 31 Jan 2022 14:54:06 +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 20VErwHE004689 for ; Mon, 31 Jan 2022 09:53:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6E32684A3E; Mon, 31 Jan 2022 14:53:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id E42C284A1A for ; Mon, 31 Jan 2022 14:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643640862; 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=m2zXp2iE3NNi7PA0Q5kFWtoXNhRqpgVciQ8RyMuHDNI=; b=UWfN/WCjDKOBaAQgSZSRkYXiocndiBp3aozvXY4aU0vy9jEXuBDMBCgg6LRySJBBBRUpGo F/PKfBlgaoo9HgKnSnLwzq0TcFMHXdVz7PClgtyGxQyUIIqke5IMt4IpsrSYy2IeLS7jFI 4+L49moi251PhX6EC1dTHVHujXclTZc= X-MC-Unique: KMTQ6LLIOcOTfdvZPxA6IA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] src: Use g_steal_pointer() more Date: Mon, 31 Jan 2022 15:53:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.84 on 10.5.11.23 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: 1643640864889100001 Content-Type: text/plain; charset="utf-8" There are few places where the g_steal_pointer() is open coded. Switch them to calling the g_steal_pointer() function instead. Generated by the following spatch: @ rule1 @ expression a, b; @@ <... - b =3D a; ... when !=3D b - a =3D NULL; + b =3D g_steal_pointer(&a); ...> Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/esx/esx_vi.c | 6 ++---- src/hyperv/hyperv_driver.c | 8 +++----- src/hyperv/hyperv_wmi.c | 3 +-- src/hypervisor/virhostdev.c | 3 +-- src/libxl/xen_common.c | 12 ++++-------- src/qemu/qemu_hotplug.c | 6 ++---- src/qemu/qemu_migration.c | 9 +++------ src/storage/storage_backend_gluster.c | 9 +++------ src/storage/storage_util.c | 6 ++---- src/util/virfile.c | 3 +-- src/util/virlease.c | 3 +-- src/util/virnuma.c | 9 +++------ 12 files changed, 26 insertions(+), 51 deletions(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 80ed6199e3..17401f0a36 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -1033,8 +1033,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Contex= t *ctx, const char *path) if (root !=3D ctx->service->rootFolder) esxVI_ManagedObjectReference_Free(&root); =20 - root =3D folder->_reference; - folder->_reference =3D NULL; + root =3D g_steal_pointer(&folder->_reference); } else { /* Try to lookup item as a datacenter */ if (esxVI_LookupDatacenter(ctx, item, root, NULL, &ctx->datace= nter, @@ -1087,8 +1086,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Contex= t *ctx, const char *path) if (root !=3D ctx->datacenter->hostFolder) esxVI_ManagedObjectReference_Free(&root); =20 - root =3D folder->_reference; - folder->_reference =3D NULL; + root =3D g_steal_pointer(&folder->_reference); } else { /* Try to lookup item as a compute resource */ if (esxVI_LookupComputeResource(ctx, item, root, NULL, diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7b684e04ba..52851ac507 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1780,8 +1780,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthP= tr auth, =20 priv->version =3D g_strdup(os->data->Version); =20 - conn->privateData =3D priv; - priv =3D NULL; + conn->privateData =3D g_steal_pointer(&priv); result =3D VIR_DRV_OPEN_SUCCESS; =20 cleanup: @@ -3518,9 +3517,8 @@ hypervConnectListAllDomains(virConnectPtr conn, doms[count++] =3D domain; } =20 - if (doms) - *domains =3D doms; - doms =3D NULL; + if (domains) + *domains =3D g_steal_pointer(&doms); ret =3D count; =20 cleanup: diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 6712ef4835..83d28b22aa 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -994,8 +994,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQuery *= wqlQuery, response =3D NULL; } =20 - *list =3D head; - head =3D NULL; + *list =3D g_steal_pointer(&head); =20 return 0; } diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index e44eb7f1d3..bcd5e96c2c 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -586,8 +586,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDef *hostdev, */ if (MAC) { VIR_FREE(adminMAC); - adminMAC =3D MAC; - MAC =3D NULL; + adminMAC =3D g_steal_pointer(&MAC); } =20 ignore_value(virNetDevSetNetConfig(linkdev, vf, diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index fc975f1299..b97ba0a199 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -682,9 +682,8 @@ xenParseVfb(virConf *conf, virDomainDef *def) if (xenConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc= .keymap) < 0) goto cleanup; def->graphics =3D g_new0(virDomainGraphicsDef *, 1); - def->graphics[0] =3D graphics; + def->graphics[0] =3D g_steal_pointer(&graphics); def->ngraphics =3D 1; - graphics =3D NULL; } else { if (xenConfigGetBool(conf, "sdl", &val, 0) < 0) goto cleanup; @@ -696,9 +695,8 @@ xenParseVfb(virConf *conf, virDomainDef *def) if (xenConfigCopyStringOpt(conf, "xauthority", &graphics->= data.sdl.xauth) < 0) goto cleanup; def->graphics =3D g_new0(virDomainGraphicsDef *, 1); - def->graphics[0] =3D graphics; + def->graphics[0] =3D g_steal_pointer(&graphics); def->ngraphics =3D 1; - graphics =3D NULL; } } } @@ -774,9 +772,8 @@ xenParseVfb(virConf *conf, virDomainDef *def) VIR_FREE(listenAddr); } def->graphics =3D g_new0(virDomainGraphicsDef *, 1); - def->graphics[0] =3D graphics; + def->graphics[0] =3D g_steal_pointer(&graphics); def->ngraphics =3D 1; - graphics =3D NULL; } else { if (xenHandleConfGetValueStringListErrors(rc) < 0) goto cleanup; @@ -953,9 +950,8 @@ xenParseCharDev(virConf *conf, virDomainDef *def, const= char *nativeFormat) =20 chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port =3D 0; - def->parallels[0] =3D chr; + def->parallels[0] =3D g_steal_pointer(&chr); def->nparallels++; - chr =3D NULL; } =20 /* Try to get the list of values to support multiple serial ports = */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d801559057..c9548d7f35 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4297,8 +4297,7 @@ qemuDomainChangeGraphics(virQEMUDriver *driver, =20 /* Steal the new dev's char * reference */ VIR_FREE(olddev->data.vnc.auth.passwd); - olddev->data.vnc.auth.passwd =3D dev->data.vnc.auth.passwd; - dev->data.vnc.auth.passwd =3D NULL; + olddev->data.vnc.auth.passwd =3D g_steal_pointer(&dev->data.vn= c.auth.passwd); olddev->data.vnc.auth.validTo =3D dev->data.vnc.auth.validTo; olddev->data.vnc.auth.expires =3D dev->data.vnc.auth.expires; olddev->data.vnc.auth.connected =3D dev->data.vnc.auth.connect= ed; @@ -4345,8 +4344,7 @@ qemuDomainChangeGraphics(virQEMUDriver *driver, =20 /* Steal the new dev's char * reference */ VIR_FREE(olddev->data.spice.auth.passwd); - olddev->data.spice.auth.passwd =3D dev->data.spice.auth.passwd; - dev->data.spice.auth.passwd =3D NULL; + olddev->data.spice.auth.passwd =3D g_steal_pointer(&dev->data.= spice.auth.passwd); olddev->data.spice.auth.validTo =3D dev->data.spice.auth.valid= To; olddev->data.spice.auth.expires =3D dev->data.spice.auth.expir= es; olddev->data.spice.auth.connected =3D dev->data.spice.auth.con= nected; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2635ef1162..09b8c415f4 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3029,8 +3029,7 @@ qemuMigrationDstPrepareAny(virQEMUDriver *driver, if (mig->lockState) { VIR_DEBUG("Received lockstate %s", mig->lockState); VIR_FREE(priv->lockState); - priv->lockState =3D mig->lockState; - mig->lockState =3D NULL; + priv->lockState =3D g_steal_pointer(&mig->lockState); } else { VIR_DEBUG("Received no lockstate"); } @@ -5598,8 +5597,7 @@ qemuMigrationDstPersist(virQEMUDriver *driver, error: virDomainDefFree(vm->newDef); vm->persistent =3D oldPersist; - vm->newDef =3D oldDef; - oldDef =3D NULL; + vm->newDef =3D g_steal_pointer(&oldDef); return -1; } =20 @@ -5778,8 +5776,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver, } =20 if (mig->jobInfo) { - jobInfo =3D mig->jobInfo; - mig->jobInfo =3D NULL; + jobInfo =3D g_steal_pointer(&mig->jobInfo); =20 if (jobInfo->sent && timeReceived) { jobInfo->timeDelta =3D timeReceived - jobInfo->sent; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index aacc23663e..52007db2ba 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -290,13 +290,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterState *state, if (meta->capacity) vol->target.capacity =3D meta->capacity; if (meta->encryption) { - vol->target.encryption =3D meta->encryption; - meta->encryption =3D NULL; + vol->target.encryption =3D g_steal_pointer(&meta->encryption); } - vol->target.features =3D meta->features; - meta->features =3D NULL; - vol->target.compat =3D meta->compat; - meta->compat =3D NULL; + vol->target.features =3D g_steal_pointer(&meta->features); + vol->target.compat =3D g_steal_pointer(&meta->compat); =20 *volptr =3D g_steal_pointer(&vol); ret =3D 0; diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a680f14afc..f88d225e96 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3443,8 +3443,7 @@ storageBackendProbeTarget(virStorageSource *target, =20 target->backingStore =3D virStorageSourceNew(); target->backingStore->type =3D VIR_STORAGE_TYPE_NETWORK; - target->backingStore->path =3D meta->backingStoreRaw; - meta->backingStoreRaw =3D NULL; + target->backingStore->path =3D g_steal_pointer(&meta->backingS= toreRaw); target->backingStore->format =3D VIR_STORAGE_FILE_RAW; } =20 @@ -3479,8 +3478,7 @@ storageBackendProbeTarget(virStorageSource *target, if (meta->encryption->payload_offset !=3D -1) target->capacity -=3D meta->encryption->payload_offset * 512; =20 - *encryption =3D meta->encryption; - meta->encryption =3D NULL; + *encryption =3D g_steal_pointer(&meta->encryption); =20 /* XXX ideally we'd fill in secret UUID here * but we cannot guarantee 'conn' is non-NULL diff --git a/src/util/virfile.c b/src/util/virfile.c index d6faf7e3d2..2d9c89ebbe 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -967,8 +967,7 @@ int virFileNBDDeviceAssociate(const char *file, =20 VIR_DEBUG("Associated NBD device %s with file %s and format %s", nbddev, file, fmtstr); - *dev =3D nbddev; - nbddev =3D NULL; + *dev =3D g_steal_pointer(&nbddev); =20 return 0; } diff --git a/src/util/virlease.c b/src/util/virlease.c index 0e28a47dd2..48b0f6fe57 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -254,7 +254,6 @@ virLeaseNew(virJSONValue **lease_ret, if (virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expir= ytime) < 0) return -1; =20 - *lease_ret =3D lease_new; - lease_new =3D NULL; + *lease_ret =3D g_steal_pointer(&lease_new); return 0; } diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 7c892d6267..2306ab0cb1 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -839,16 +839,13 @@ virNumaGetPages(int node, } while (exchange); =20 if (pages_size) { - *pages_size =3D tmp_size; - tmp_size =3D NULL; + *pages_size =3D g_steal_pointer(&tmp_size); } if (pages_avail) { - *pages_avail =3D tmp_avail; - tmp_avail =3D NULL; + *pages_avail =3D g_steal_pointer(&tmp_avail); } if (pages_free) { - *pages_free =3D tmp_free; - tmp_free =3D NULL; + *pages_free =3D g_steal_pointer(&tmp_free); } *npages =3D ntmp; return 0; --=20 2.34.1