On 3/24/21 6:27 AM, Michal Privoznik wrote:
Generated by the following spatch:

   @@
   expression a, b;
   @@

   + b = g_steal_pointer(&a);
   - b = a;
     ... when != a
   - a = NULL;

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
  src/conf/capabilities.c                 |  3 +--
  src/conf/domain_addr.c                  |  6 ++---
  src/conf/domain_conf.c                  |  3 +--
  src/conf/node_device_conf.c             |  3 +--
  src/conf/nwfilter_conf.c                |  3 +--
  src/conf/object_event.c                 |  3 +--
  src/conf/virdomainmomentobjlist.c       |  8 +++---
  src/conf/virinterfaceobj.c              |  3 +--
  src/conf/virnetworkobj.c                | 12 +++------
  src/conf/virstorageobj.c                |  3 +--
  src/esx/esx_driver.c                    |  9 +++----
  src/esx/esx_vi.c                        |  3 +--
  src/hypervisor/domain_driver.c          |  3 +--
  src/interface/interface_backend_netcf.c |  3 +--
  src/libxl/libxl_driver.c                | 12 +++------
  src/libxl/libxl_migration.c             |  6 ++---
  src/libxl/xen_xl.c                      |  6 ++---
  src/lxc/lxc_controller.c                |  3 +--
  src/lxc/lxc_driver.c                    | 12 +++------
  src/lxc/lxc_monitor.c                   |  3 +--
  src/lxc/lxc_native.c                    |  3 +--
  src/lxc/lxc_process.c                   |  3 +--
  src/node_device/node_device_udev.c      |  3 +--
  src/qemu/qemu_agent.c                   |  3 +--
  src/qemu/qemu_blockjob.c                |  6 ++---
  src/qemu/qemu_domain_address.c          |  6 ++---
  src/qemu/qemu_driver.c                  | 36 +++++++++----------------
  src/qemu/qemu_migration_cookie.c        |  3 +--
  src/qemu/qemu_monitor.c                 |  3 +--
  src/qemu/qemu_monitor_json.c            |  6 ++---
  src/remote/remote_daemon_dispatch.c     |  6 ++---
  src/remote/remote_driver.c              | 18 +++++--------
  src/rpc/virnetclient.c                  | 14 ++++------
  src/rpc/virnetclientstream.c            | 15 ++++-------
  src/rpc/virnetmessage.c                 |  3 +--
  src/rpc/virnetserverclient.c            |  6 ++---
  src/rpc/virnetsocket.c                  |  6 ++---
  src/rpc/virnetsshsession.c              |  3 +--
  src/rpc/virnettlscontext.c              |  3 +--
  src/security/security_dac.c             |  4 +--
  src/test/test_driver.c                  |  3 +--
  src/util/virconf.c                      |  3 +--
  src/util/virfdstream.c                  |  3 +--
  src/util/virjson.c                      |  3 +--
  src/vbox/vbox_common.c                  |  6 ++---
  src/vbox/vbox_snapshot_conf.c           |  7 ++---
  src/vmx/vmx.c                           | 29 ++++++--------------
  src/vz/vz_sdk.c                         | 18 +++++--------
  tools/virsh-domain.c                    |  6 ++---
  tools/vsh.c                             |  9 +++----
  50 files changed, 113 insertions(+), 231 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 573ac4e975..6c94d1c502 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1702,8 +1702,7 @@ virCapabilitiesInitPages(virCapsPtr caps)
                          &pages_size, NULL, NULL, &npages) < 0)
          goto cleanup;
- caps->host.pagesSize = pages_size;
-    pages_size = NULL;
+    caps->host.pagesSize = g_steal_pointer(&pages_size);
      caps->host.nPagesSize = npages;
      npages = 0;
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 9167b489d1..0dcd690a5f 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1995,8 +1995,7 @@ 
virDomainUSBAddressSetAddController(virDomainUSBAddressSetPtr addrs,
      if (!(hub = virDomainUSBAddressHubNew(nports)))
          goto cleanup;
- addrs->buses[cont->idx] = hub;
-    hub = NULL;
+    addrs->buses[cont->idx] = g_steal_pointer(&hub);
ret = 0;
   cleanup:
@@ -2112,8 +2111,7 @@ virDomainUSBAddressSetAddHub(virDomainUSBAddressSetPtr 
addrs,
          goto cleanup;
      }
      ignore_value(virBitmapSetBit(targetHub->portmap, targetPort));
-    targetHub->ports[targetPort] = newHub;
-    newHub = NULL;
+    targetHub->ports[targetPort] = g_steal_pointer(&newHub);
ret = 0;
   cleanup:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b7f9c01e88..aabd9f5c6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3961,9 +3961,8 @@ virDomainObjRemoveTransientDef(virDomainObjPtr domain)
          return;
virDomainDefFree(domain->def);
-    domain->def = domain->newDef;
+    domain->def = g_steal_pointer(&domain->newDef);
      domain->def->id = -1;
-    domain->newDef = NULL;
  }
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 298cb8fd37..b1739ceb01 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1866,8 +1866,7 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
          if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0)
              goto out;
- pci_dev->pci_express = pci_express;
-        pci_express = NULL;
+        pci_dev->pci_express = g_steal_pointer(&pci_express);
          pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCIE;
      }
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 3cc45394c0..dc1b879eb3 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2644,7 +2644,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
          name_prefix = virNWFilterIsAllowedChain(chain);
          if (name_prefix == NULL)
              goto cleanup;
-        ret->chainsuffix = chain;
+        ret->chainsuffix = g_steal_pointer(&chain);
if (chain_pri_s) {
              ret->chainPriority = chain_priority;
@@ -2656,7 +2656,6 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
                                        NWFILTER_MIN_FILTER_PRIORITY) / 2;
              }
          }
-        chain = NULL;
      } else {
          ret->chainsuffix = 
g_strdup(virNWFilterChainSuffixTypeToString(VIR_NWFILTER_CHAINSUFFIX_ROOT));
      }
diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index 5d7d45355e..4a9450dd9c 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -805,9 +805,8 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
      /* Copy the queue, so we're reentrant safe when dispatchFunc drops the
       * driver lock */
      tempQueue.count = state->queue->count;
-    tempQueue.events = state->queue->events;
+    tempQueue.events = g_steal_pointer(&state->queue->events);
      state->queue->count = 0;
-    state->queue->events = NULL;
      if (state->timer != -1)
          virEventUpdateTimeout(state->timer, -1);
diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
index 7d639c4e01..879bc56472 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -133,11 +133,10 @@ virDomainMomentDropParent(virDomainMomentObjPtr moment)
          curr = curr->sibling;
      }
      if (prev)
-        prev->sibling = moment->sibling;
+        prev->sibling = g_steal_pointer(&moment->sibling);
      else
-        moment->parent->first_child = moment->sibling;
+        moment->parent->first_child = g_steal_pointer(&moment->sibling);
      moment->parent = NULL;
-    moment->sibling = NULL;
  }
@@ -201,9 +200,8 @@ virDomainMomentMoveChildren(virDomainMomentObjPtr from,
          child = child->sibling;
      }
      to->nchildren += from->nchildren;
-    to->first_child = from->first_child;
+    to->first_child = g_steal_pointer(&from->first_child);
      from->nchildren = 0;
-    from->first_child = NULL;
  }
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index cc990a05cd..909075c029 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -330,8 +330,7 @@ virInterfaceObjListExport(virConnectPtr conn,
      if (data.ifaces) {
          /* trim the array to the final size */
          VIR_REALLOC_N(data.ifaces, data.nifaces + 1);
-        *ifaces = data.ifaces;
-        data.ifaces = NULL;
+        *ifaces = g_steal_pointer(&data.ifaces);
      }
ret = data.nifaces;
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 47739718a7..e2a6328d3d 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -696,8 +696,7 @@ virNetworkObjUnsetDefTransient(virNetworkObjPtr obj)
  {
      if (obj->newDef) {
          virNetworkDefFree(obj->def);
-        obj->def = obj->newDef;
-        obj->newDef = NULL;
+        obj->def = g_steal_pointer(&obj->newDef);
      }
  }
@@ -1309,8 +1308,7 @@ virNetworkObjUpdate(virNetworkObjPtr obj,
      if (livedef) {
          /* successfully modified copy, now replace original */
          virNetworkDefFree(obj->def);
-        obj->def = livedef;
-        livedef = NULL;
+        obj->def = g_steal_pointer(&livedef);
      }
ret = 0;
@@ -1429,8 +1427,7 @@ virNetworkObjListExport(virConnectPtr conn,
      if (data.nets) {
          /* trim the array to the final size */
          VIR_REALLOC_N(data.nets, data.nnets + 1);
-        *nets = data.nets;
-        data.nets = NULL;
+        *nets = g_steal_pointer(&data.nets);
      }
ret = data.nnets;
@@ -1817,8 +1814,7 @@ virNetworkObjPortListExport(virNetworkPtr net,
      if (data.ports) {
          /* trim the array to the final size */
          VIR_REALLOC_N(data.ports, data.nports + 1);
-        *ports = data.ports;
-        data.ports = NULL;
+        *ports = g_steal_pointer(&data.ports);
      }
ret = data.nports;
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 0e27b0ca65..ef1dad597c 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -270,8 +270,7 @@ void
  virStoragePoolObjDefUseNewDef(virStoragePoolObjPtr obj)
  {
      virStoragePoolDefFree(obj->def);
-    obj->def = obj->newDef;
-    obj->newDef = NULL;
+    obj->def = g_steal_pointer(&obj->newDef);
  }
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 1c68776c18..f2395abd74 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -911,8 +911,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
      if (!(priv->xmlopt = virVMXDomainXMLConfInit(priv->caps)))
          goto cleanup;
- conn->privateData = priv;
-    priv = NULL;
+    conn->privateData = g_steal_pointer(&priv);
      result = VIR_DRV_OPEN_SUCCESS;
cleanup:
@@ -3554,8 +3553,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
                  goto cleanup;
              }
- spec->cpuAllocation->shares = sharesInfo;
-            sharesInfo = NULL;
+            spec->cpuAllocation->shares = g_steal_pointer(&sharesInfo);
if (params[i].value.i >= 0) {
                  spec->cpuAllocation->shares->level = esxVI_SharesLevel_Custom;
@@ -4930,8 +4928,7 @@ esxConnectListAllDomains(virConnectPtr conn,
      }
if (doms) {
-        *domains = doms;
-        doms = NULL;
+        *domains = g_steal_pointer(&doms);
      }
      ret = count;
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index e535b28484..54f9a81d92 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -3511,8 +3511,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
          }
      }
- *fileInfo = searchResults->file;
-    searchResults->file = NULL;
+    *fileInfo = g_steal_pointer(&searchResults->file);
result = 0; diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index b861e0ef9b..945d375444 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -179,8 +179,7 @@ virDomainDriverMergeBlkioDevice(virBlkioDevicePtr 
*dest_array,
                  return -1;
              }
- dest->path = src->path;
-            src->path = NULL;
+            dest->path = g_steal_pointer(&src->path);
          }
      }
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index 54a141eaa9..feebf414a0 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -516,8 +516,7 @@ static int netcfConnectListInterfacesImpl(virConnectPtr 
conn,
          }
          virInterfaceDefFree(def);
- names[want++] = allnames[i];
-        allnames[i] = NULL;
+        names[want++] = g_steal_pointer(&allnames[i]);
      }
ret = want;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 830634b2bd..23ef55cf37 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2506,8 +2506,7 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int 
vcpu,
      }
virBitmapFree(vcpuinfo->cpumask);
-    vcpuinfo->cpumask = pcpumap;
-    pcpumap = NULL;
+    vcpuinfo->cpumask = g_steal_pointer(&pcpumap);
ret = 0; @@ -3530,7 +3529,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev) switch (dev->type) {
          case VIR_DOMAIN_DEVICE_DISK:
-            disk = dev->data.disk;
+            disk = g_steal_pointer(&dev->data.disk);
              if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) {
                  virReportError(VIR_ERR_INVALID_ARG,
                                 _("target %s already exists."), disk->dst);
@@ -3538,11 +3537,10 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
              }
              virDomainDiskInsert(vmdef, disk);
              /* vmdef has the pointer. Generic codes for vmdef will do all 
jobs */
-            dev->data.disk = NULL;
              break;

I think these two hunks will end up leaking the pointer if virDomainDiskIndexByName() returns true - before this change we would have returned with the disk still in place in dev->data.disk so it would eventually be freed, but after the change we now will have already NULLed out the original pointer, but the new pointer is just going to go out of scope with no further action.

case VIR_DOMAIN_DEVICE_CONTROLLER:
-            controller = dev->data.controller;
+            controller = g_steal_pointer(&dev->data.controller);
              if (controller->idx != -1 &&
                  virDomainControllerFind(vmdef, controller->type,
                                          controller->idx) >= 0) {
@@ -3552,11 +3550,10 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
              }
virDomainControllerInsert(vmdef, controller);
-            dev->data.controller = NULL;
              break;

Same thing with these two hunks.

          case VIR_DOMAIN_DEVICE_NET:
-            net = dev->data.net;
+            net = g_steal_pointer(&dev->data.net);
              if (virDomainHasNet(vmdef, net)) {
                  virReportError(VIR_ERR_INVALID_ARG,
                                 _("network device with mac %s already exists"),
@@ -3565,7 +3562,6 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
              }
              if (virDomainNetInsert(vmdef, net))
                  return -1;
-            dev->data.net = NULL;
              break;

... and these.

case VIR_DOMAIN_DEVICE_HOSTDEV:
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index a5a9df98ad..cb474123ea 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -602,11 +602,10 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
      args->conn = virObjectRef(dconn);
      args->vm = virObjectRef(vm);
      args->flags = flags;
-    args->migcookie = mig;
+    args->migcookie = g_steal_pointer(&mig);
      /* Receive from pipeOut */
      args->recvfd = dataFD[0];
      args->nsocks = 0;
-    mig = NULL;
VIR_FREE(priv->migrationDstReceiveThr);
      priv->migrationDstReceiveThr = g_new0(virThread, 1);
@@ -768,8 +767,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
      args->flags = flags;
      args->socks = socks;
      args->nsocks = nsocks;
-    args->migcookie = mig;
-    mig = NULL;
+    args->migcookie = g_steal_pointer(&mig);
for (i = 0; i < nsocks; i++) {
          if (virNetSocketSetBlocking(socks[i], true) < 0)
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index a043f298b4..65cd26bb21 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1071,8 +1071,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
              if (STRPREFIX(type, "socket")) {
                  channel->source->type = VIR_DOMAIN_CHR_TYPE_UNIX;
                  channel->source->data.nix.listen = 1;
-                channel->source->data.nix.path = path;
-                path = NULL;
+                channel->source->data.nix.path = g_steal_pointer(&path);
              } else if (STRPREFIX(type, "pty")) {
                  channel->source->type = VIR_DOMAIN_CHR_TYPE_PTY;
                  VIR_FREE(path);
@@ -1082,8 +1081,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
channel->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL;
              channel->targetType = VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN;
-            channel->target.name = name;
-            name = NULL;
+            channel->target.name = g_steal_pointer(&name);
if (VIR_APPEND_ELEMENT(def->channels, def->nchannels, channel) < 0)
                  goto cleanup;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 9c4ff5e107..ee3c77d31a 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -463,8 +463,7 @@ static int 
virLXCControllerSetupLoopDeviceFS(virDomainFSDefPtr fs)
       */
      fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
      g_free(fs->src->path);
-    fs->src->path = loname;
-    loname = NULL;
+    fs->src->path = g_steal_pointer(&loname);
return lofd;
  }
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 8e0ec82e0b..3fc15ff2ec 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3041,7 +3041,7 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
switch (dev->type) {
      case VIR_DOMAIN_DEVICE_DISK:
-        disk = dev->data.disk;
+        disk = g_steal_pointer(&dev->data.disk);
          if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) {
              virReportError(VIR_ERR_INVALID_ARG,
                             _("target %s already exists."), disk->dst);
@@ -3049,20 +3049,18 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          }
          virDomainDiskInsert(vmdef, disk);
          /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-        dev->data.disk = NULL;
          ret = 0;
          break;

Here we have the same problem as above.


case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
+        net = g_steal_pointer(&dev->data.net);
          if (virDomainNetInsert(vmdef, net) < 0)
              return -1;
-        dev->data.net = NULL;

and here.

          ret = 0;
          break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
-        hostdev = dev->data.hostdev;
+        hostdev = g_steal_pointer(&dev->data.hostdev);
          if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) {
              virReportError(VIR_ERR_INVALID_ARG, "%s",
                             _("device is already in the domain 
configuration"));
@@ -3070,7 +3068,6 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          }
          if (virDomainHostdevInsert(vmdef, hostdev) < 0)
              return -1;
-        dev->data.hostdev = NULL;
          ret = 0;
          break;

and here.

@@ -3095,7 +3092,7 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef, switch (dev->type) {
      case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
+        net = g_steal_pointer(&dev->data.net);
          if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
              return -1;
@@ -3109,7 +3106,6 @@ lxcDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
              return -1;
virDomainNetDefFree(oldDev.data.net);
-        dev->data.net = NULL;

and here.

The same problem exists in qemu_driver.c. I'll just say that here rather than continuing with the same here same here comments...

          ret = 0;
break;
diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 96c325af49..4e7fa3422b 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -211,8 +211,7 @@ void virLXCMonitorClose(virLXCMonitorPtr mon)
           */
          VIR_DEBUG("Clear EOF callback mon=%p", mon);
          vm = mon->vm;
-        client = mon->client;
-        mon->client = NULL;
+        client = g_steal_pointer(&mon->client);
          mon->cb.eofNotify = NULL;
virObjectRef(vm);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 36ae821dee..c5f2898a57 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1007,8 +1007,7 @@ lxcBlkioDeviceWalkCallback(const char *name, 
virConfValuePtr value, void *data)
      if (!device) {
          VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1);
          device = &def->blkio.devices[def->blkio.ndevices - 1];
-        device->path = path;
-        path = NULL;
+        device->path = g_steal_pointer(&path);
      }
/* Set the value */
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index d0b1d80523..bdf96eed3d 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -113,8 +113,7 @@ virLXCProcessReboot(virLXCDriverPtr driver,
       * to use the current 'def', and not switch to 'newDef'.
       * So temporarily hide the newDef and then reinstate it
       */
-    savedDef = vm->newDef;
-    vm->newDef = NULL;
+    savedDef = g_steal_pointer(&vm->newDef);
      virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
      vm->newDef = savedDef;
      if (virLXCProcessStart(conn, driver, vm,
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index 010ebf4e74..3f288589db 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -451,8 +451,7 @@ udevProcessPCI(struct udev_device *device,
                  pci_express->link_sta->port = -1; /* PCIe can't negotiate 
port. Yet :) */
              }
              pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCIE;
-            pci_dev->pci_express = pci_express;
-            pci_express = NULL;
+            pci_dev->pci_express = g_steal_pointer(&pci_express);
          }
      }
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 02793edd02..290f91176c 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -305,9 +305,8 @@ qemuAgentIOProcessLine(qemuAgentPtr agent,
                      goto cleanup;
                  }
              }
-            msg->rxObject = obj;
+            msg->rxObject = g_steal_pointer(&obj);
              msg->finished = true;
-            obj = NULL;
          } else {
              /* we are out of sync */
              VIR_DEBUG("Ignoring delayed reply");
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index aa065b1319..66268a365a 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -1219,8 +1219,7 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr 
driver,
      job->data.commit.top = NULL;
if (cfgbaseparent) {
-        cfgbase = cfgbaseparent->backingStore;
-        cfgbaseparent->backingStore = NULL;
+        cfgbase = g_steal_pointer(&cfgbaseparent->backingStore);
if (cfgtopparent)
              cfgtopparent->backingStore = cfgbase;
@@ -1289,8 +1288,7 @@ 
qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriverPtr driver,
           */
          qemuBlockJobRewriteConfigDiskSource(vm, job->disk, 
job->data.commit.base);
      } else {
-        cfgbase = cfgbaseparent->backingStore;
-        cfgbaseparent->backingStore = NULL;
+        cfgbase = g_steal_pointer(&cfgbaseparent->backingStore);
          cfgdisk->src = cfgbase;
          cfgdisk->src->readonly = cfgtop->readonly;
          virObjectUnref(cfgtop);
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 68dbf9e95b..0dbf203cd0 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -2920,8 +2920,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
      if (obj && obj->privateData) {
          priv = obj->privateData;
          /* if this is the live domain object, we persist the PCI addresses */
-        priv->pciaddrs = addrs;
-        addrs = NULL;
+        priv->pciaddrs = g_steal_pointer(&addrs);
      }
ret = 0;
@@ -3231,8 +3230,7 @@ qemuDomainAssignUSBAddresses(virDomainDefPtr def,
if (obj && obj->privateData) {
          priv = obj->privateData;
-        priv->usbaddrs = addrs;
-        addrs = NULL;
+        priv->usbaddrs = g_steal_pointer(&addrs);
      }
      ret = 0;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f3f8caab44..b31be76f91 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7238,7 +7238,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
switch ((virDomainDeviceType)dev->type) {
      case VIR_DOMAIN_DEVICE_DISK:
-        disk = dev->data.disk;
+        disk = g_steal_pointer(&dev->data.disk);
          if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) {
              virReportError(VIR_ERR_OPERATION_INVALID,
                             _("target %s already exists"), disk->dst);
@@ -7250,25 +7250,22 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
              return -1;
          virDomainDiskInsert(vmdef, disk);
          /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-        dev->data.disk = NULL;
          break;
case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
+        net = g_steal_pointer(&dev->data.net);
          if (virDomainNetInsert(vmdef, net))
              return -1;
-        dev->data.net = NULL;
          break;
case VIR_DOMAIN_DEVICE_SOUND:
-        sound = dev->data.sound;
+        sound = g_steal_pointer(&dev->data.sound);
          if (VIR_APPEND_ELEMENT(vmdef->sounds, vmdef->nsounds, sound) < 0)
              return -1;
-        dev->data.sound = NULL;
          break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
-        hostdev = dev->data.hostdev;
+        hostdev = g_steal_pointer(&dev->data.hostdev);
          if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) {
              virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                             _("device is already in the domain 
configuration"));
@@ -7276,11 +7273,10 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          }
          if (virDomainHostdevInsert(vmdef, hostdev))
              return -1;
-        dev->data.hostdev = NULL;
          break;
case VIR_DOMAIN_DEVICE_LEASE:
-        lease = dev->data.lease;
+        lease = g_steal_pointer(&dev->data.lease);
          if (virDomainLeaseIndex(vmdef, lease) >= 0) {
              virReportError(VIR_ERR_OPERATION_INVALID,
                             _("Lease %s in lockspace %s already exists"),
@@ -7290,11 +7286,10 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          virDomainLeaseInsert(vmdef, lease);
/* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-        dev->data.lease = NULL;
          break;
case VIR_DOMAIN_DEVICE_CONTROLLER:
-        controller = dev->data.controller;
+        controller = g_steal_pointer(&dev->data.controller);
          if (controller->idx != -1 &&
              virDomainControllerFind(vmdef, controller->type,
                                      controller->idx) >= 0) {
@@ -7305,7 +7300,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          }
virDomainControllerInsert(vmdef, controller);
-        dev->data.controller = NULL;
break; @@ -7316,7 +7310,7 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          break;
case VIR_DOMAIN_DEVICE_FS:
-        fs = dev->data.fs;
+        fs = g_steal_pointer(&dev->data.fs);
          if (virDomainFSIndexByName(vmdef, fs->dst) >= 0) {
              virReportError(VIR_ERR_OPERATION_INVALID,
                           "%s", _("Target already exists"));
@@ -7325,7 +7319,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
if (virDomainFSInsert(vmdef, fs) < 0)
              return -1;
-        dev->data.fs = NULL;
          break;
case VIR_DOMAIN_DEVICE_RNG:
@@ -7357,15 +7350,14 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          break;
case VIR_DOMAIN_DEVICE_REDIRDEV:
-        redirdev = dev->data.redirdev;
+        redirdev = g_steal_pointer(&dev->data.redirdev);
if (VIR_APPEND_ELEMENT(vmdef->redirdevs, vmdef->nredirdevs, redirdev) < 0)
              return -1;
-        dev->data.redirdev = NULL;
          break;
case VIR_DOMAIN_DEVICE_SHMEM:
-        shmem = dev->data.shmem;
+        shmem = g_steal_pointer(&dev->data.shmem);
          if (virDomainShmemDefFind(vmdef, shmem) >= 0) {
              virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                             _("device is already in the domain 
configuration"));
@@ -7373,7 +7365,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
          }
          if (virDomainShmemDefInsert(vmdef, shmem) < 0)
              return -1;
-        dev->data.shmem = NULL;
          break;
case VIR_DOMAIN_DEVICE_WATCHDOG:
@@ -7645,7 +7636,7 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
switch ((virDomainDeviceType)dev->type) {
      case VIR_DOMAIN_DEVICE_DISK:
-        newDisk = dev->data.disk;
+        newDisk = g_steal_pointer(&dev->data.disk);
          if ((pos = virDomainDiskIndexByName(vmdef, newDisk->dst, false)) < 0) 
{
              virReportError(VIR_ERR_INVALID_ARG,
                             _("target %s doesn't exist."), newDisk->dst);
@@ -7660,11 +7651,10 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
virDomainDiskDefFree(vmdef->disks[pos]);
          vmdef->disks[pos] = newDisk;
-        dev->data.disk = NULL;
          break;
case VIR_DOMAIN_DEVICE_GRAPHICS:
-        newGraphics = dev->data.graphics;
+        newGraphics = g_steal_pointer(&dev->data.graphics);
          pos = qemuDomainFindGraphicsIndex(vmdef, newGraphics);
          if (pos < 0) {
              virReportError(VIR_ERR_INVALID_ARG,
@@ -7681,11 +7671,10 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
virDomainGraphicsDefFree(vmdef->graphics[pos]);
          vmdef->graphics[pos] = newGraphics;
-        dev->data.graphics = NULL;
          break;
case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
+        net = g_steal_pointer(&dev->data.net);
          if ((pos = virDomainNetFindIdx(vmdef, net)) < 0)
              return -1;
@@ -7699,7 +7688,6 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
              return -1;
virDomainNetDefFree(oldDev.data.net);
-        dev->data.net = NULL;
          break;
case VIR_DOMAIN_DEVICE_FS:
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 07a97b75ff..15eaf994a9 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -423,8 +423,7 @@ qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
      if (!def || !*def)
          return 0;
- mig->persistent = *def;
-    *def = NULL;
+    mig->persistent = g_steal_pointer(&*def);
      mig->flags |= QEMU_MIGRATION_COOKIE_PERSISTENT;
      mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_PERSISTENT;
      return 0;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index ec05ac6c43..fede34210d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1069,8 +1069,7 @@ qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon,
      for (i = 0; i < nprops; i++) {
          if (STREQ(bprops[i]->name, "guest-stats-polling-interval")) {
              VIR_DEBUG("Found Balloon Object Path %s", path);
-            mon->balloonpath = path;
-            path = NULL;
+            mon->balloonpath = g_steal_pointer(&path);
              goto cleanup;
          }
      }
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index c87a4c6ed1..0602d8e0dd 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -241,9 +241,8 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
          PROBE(QEMU_MONITOR_RECV_REPLY,
                "mon=%p reply=%s", mon, line);
          if (msg) {
-            msg->rxObject = obj;
+            msg->rxObject = g_steal_pointer(&obj);
              msg->finished = 1;
-            obj = NULL;
              ret = 0;
          } else {
              virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -7670,8 +7669,7 @@ qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
      alias = *aliases;
      for (i = 0; i < n; i++) {
          if (STRPREFIX(paths[i]->type, "child<")) {
-            *alias = paths[i]->name;
-            paths[i]->name = NULL;
+            *alias = g_steal_pointer(&paths[i]->name);
              alias++;
          }
      }
diff --git a/src/remote/remote_daemon_dispatch.c 
b/src/remote/remote_daemon_dispatch.c
index 9700dba450..d9181c0ca6 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -3061,8 +3061,7 @@ remoteDispatchDomainMigratePrepare(virNetServerPtr server 
G_GNUC_UNUSED,
      if (*uri_out == NULL) {
          ret->uri_out = NULL;
      } else {
-        ret->uri_out = uri_out;
-        uri_out = NULL;
+        ret->uri_out = g_steal_pointer(&uri_out);
      }
rv = 0;
@@ -5871,9 +5870,8 @@ remoteDispatchConnectGetCPUModelNames(virNetServerPtr 
server G_GNUC_UNUSED,
      }
if (len && models) {
-        ret->models.models_val = models;
+        ret->models.models_val = g_steal_pointer(&models);
          ret->models.models_len = len;
-        models = NULL;
      } else {
          ret->models.models_val = NULL;
          ret->models.models_len = 0;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 494f4b6dc5..62ada08344 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3472,8 +3472,7 @@ remoteConnectFindStoragePoolSources(virConnectPtr conn,
               (xdrproc_t) xdr_remote_connect_find_storage_pool_sources_ret, (char 
*) &ret) == -1)
          goto done;
- rv = ret.xml;
-    ret.xml = NULL; /* To stop xdr_free free'ing it */
+    rv = g_steal_pointer(&ret.xml); /* To stop xdr_free free'ing it */
xdr_free((xdrproc_t) xdr_remote_connect_find_storage_pool_sources_ret, (char *) &ret); @@ -6203,9 +6202,8 @@ remoteDomainMigrateFinish3(virConnectPtr dconn,
                             _("caller ignores cookieout or cookieoutlen"));
              goto error;
          }
-        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
+        *cookieout = g_steal_pointer(&ret.cookie_out.cookie_out_val); /* 
Caller frees. */
          *cookieoutlen = ret.cookie_out.cookie_out_len;
-        ret.cookie_out.cookie_out_val = NULL;
          ret.cookie_out.cookie_out_len = 0;
      }
@@ -6296,8 +6294,7 @@ remoteConnectGetCPUModelNames(virConnectPtr conn,
          retmodels = g_new0(char *, ret.models.models_len + 1);
for (i = 0; i < ret.models.models_len; i++) {
-            retmodels[i] = ret.models.models_val[i];
-            ret.models.models_val[i] = NULL;
+            retmodels[i] = g_steal_pointer(&ret.models.models_val[i]);
          }
          *models = g_steal_pointer(&retmodels);
      }
@@ -7159,9 +7156,8 @@ remoteDomainMigrateFinish3Params(virConnectPtr dconn,
                             _("caller ignores cookieout or cookieoutlen"));
              goto error;
          }
-        *cookieout = ret.cookie_out.cookie_out_val; /* Caller frees. */
+        *cookieout = g_steal_pointer(&ret.cookie_out.cookie_out_val); /* 
Caller frees. */
          *cookieoutlen = ret.cookie_out.cookie_out_len;
-        ret.cookie_out.cookie_out_val = NULL;
          ret.cookie_out.cookie_out_len = 0;
      }
@@ -7549,8 +7545,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
                                        &elem->nparams))
              goto cleanup;
- tmpret[i] = elem;
-        elem = NULL;
+        tmpret[i] = g_steal_pointer(&elem);
      }
*retStats = g_steal_pointer(&tmpret);
@@ -7880,8 +7875,7 @@ remoteDomainRename(virDomainPtr dom, const char 
*new_name, unsigned int flags)
if (rv == 0) {
          VIR_FREE(dom->name);
-        dom->name = tmp;
-        tmp = NULL;
+        dom->name = g_steal_pointer(&tmp);
      }
done:
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1ac6bc08de..9195cb555d 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -189,10 +189,9 @@ static void virNetClientCallRemove(virNetClientCallPtr 
*head,
      while (tmp) {
          if (tmp == call) {
              if (prev)
-                prev->next = tmp->next;
+                prev->next = g_steal_pointer(&tmp->next);
              else
-                *head = tmp->next;
-            tmp->next = NULL;
+                *head = g_steal_pointer(&tmp->next);
              return;
          }
          prev = tmp;
@@ -304,8 +303,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
      if (!(client = virObjectLockableNew(virNetClientClass)))
          goto error;
- client->sock = sock;
-    sock = NULL;
+    client->sock = g_steal_pointer(&sock);
client->eventCtx = g_main_context_new();
      client->eventLoop = g_main_loop_new(client->eventCtx, FALSE);
@@ -803,8 +801,7 @@ virNetClientCloseLocked(virNetClientPtr client)
      virObjectUnref(client->sasl);
      client->sasl = NULL;
  #endif
-    ka = client->keepalive;
-    client->keepalive = NULL;
+    ka = g_steal_pointer(&client->keepalive);
      client->wantClose = false;
virFreeError(client->error);
@@ -1162,9 +1159,8 @@ virNetClientCallDispatchReply(virNetClientPtr client)
      thecall->msg->bufferOffset = client->msg.bufferOffset;
thecall->msg->nfds = client->msg.nfds;
-    thecall->msg->fds = client->msg.fds;
+    thecall->msg->fds = g_steal_pointer(&client->msg.fds);
      client->msg.nfds = 0;
-    client->msg.fds = NULL;
thecall->mode = VIR_NET_CLIENT_MODE_COMPLETE; diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index f904eaba31..3bc22230b3 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -286,22 +286,18 @@ int virNetClientStreamSetError(virNetClientStreamPtr st,
          st->err.code = err.code;
      }
      if (err.message) {
-        st->err.message = *err.message;
-        *err.message = NULL;
+        st->err.message = g_steal_pointer(&*err.message);
      }
      st->err.domain = err.domain;
      st->err.level = err.level;
      if (err.str1) {
-        st->err.str1 = *err.str1;
-        *err.str1 = NULL;
+        st->err.str1 = g_steal_pointer(&*err.str1);
      }
      if (err.str2) {
-        st->err.str2 = *err.str2;
-        *err.str2 = NULL;
+        st->err.str2 = g_steal_pointer(&*err.str2);
      }
      if (err.str3) {
-        st->err.str3 = *err.str3;
-        *err.str3 = NULL;
+        st->err.str3 = g_steal_pointer(&*err.str3);
      }
      st->err.int1 = err.int1;
      st->err.int2 = err.int2;
@@ -343,10 +339,9 @@ int virNetClientStreamQueuePacket(virNetClientStreamPtr st,
      memcpy(&tmp_msg->header, &msg->header, sizeof(msg->header));
/* Steal message buffer */
-    tmp_msg->buffer = msg->buffer;
+    tmp_msg->buffer = g_steal_pointer(&msg->buffer);
      tmp_msg->bufferLength = msg->bufferLength;
      tmp_msg->bufferOffset = msg->bufferOffset;
-    msg->buffer = NULL;
      msg->bufferLength = msg->bufferOffset = 0;
virObjectLock(st);
diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
index f2b8526817..3eecc6599d 100644
--- a/src/rpc/virnetmessage.c
+++ b/src/rpc/virnetmessage.c
@@ -110,8 +110,7 @@ virNetMessagePtr virNetMessageQueueServe(virNetMessagePtr 
*queue)
      virNetMessagePtr tmp = *queue;
if (tmp) {
-        *queue = tmp->next;
-        tmp->next = NULL;
+        *queue = g_steal_pointer(&tmp->next);
      }
return tmp;
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 6b9c1bbc64..c443673eab 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -999,8 +999,7 @@ virNetServerClientCloseLocked(virNetServerClientPtr client)
if (client->keepalive) {
          virKeepAliveStop(client->keepalive);
-        ka = client->keepalive;
-        client->keepalive = NULL;
+        ka = g_steal_pointer(&client->keepalive);
          virObjectRef(client);
          virObjectUnlock(client);
          virObjectUnref(ka);
@@ -1398,8 +1397,7 @@ virNetServerClientDispatchWrite(virNetServerClientPtr 
client)
                      virNetMessageClear(msg);
                      msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
                      msg->buffer = g_new0(char, msg->bufferLength);
-                    client->rx = msg;
-                    msg = NULL;
+                    client->rx = g_steal_pointer(&msg);
                      client->nrequests++;
                  }
              }
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 0b4e21c3c9..5675c0769d 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -2156,11 +2156,9 @@ static void virNetSocketEventFree(void *opaque)
      void *eopaque;
virObjectLock(sock);
-    ff = sock->ff;
-    eopaque = sock->opaque;
+    ff = g_steal_pointer(&sock->ff);
+    eopaque = g_steal_pointer(&sock->opaque);
      sock->func = NULL;
-    sock->ff = NULL;
-    sock->opaque = NULL;
      virObjectUnlock(sock);
if (ff)
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index a42549dcf4..fe77594f65 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -240,8 +240,7 @@ virNetSSHKbIntCb(const char *name G_GNUC_UNUSED,
/* copy retrieved data back */
      for (i = 0; i < num_prompts; i++) {
-        responses[i].text = askcred[i].result;
-        askcred[i].result = NULL; /* steal the pointer */
+        responses[i].text = g_steal_pointer(&askcred[i].result); /* steal the 
pointer */
          responses[i].length = askcred[i].resultlen;
      }
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 2936b8ba57..c1d8cdeaae 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -924,8 +924,7 @@ int virNetTLSContextReloadForServer(virNetTLSContextPtr 
ctxt,
      g_autofree char *cert = NULL;
      g_autofree char *key = NULL;
- x509credBak = ctxt->x509cred;
-    ctxt->x509cred = NULL;
+    x509credBak = g_steal_pointer(&ctxt->x509cred);
if (virNetTLSContextLocateCredentials(NULL, tryUserPkiPath, true,
                                            &cacert, &cacrl, &cert, &key))
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 344bd6fc5f..4b7eda2e68 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -112,7 +112,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr 
list,
tmp = g_strdup(path); - item->path = tmp;
+    item->path = g_steal_pointer(&tmp);
      item->src = src;
      item->uid = uid;
      item->gid = gid;
@@ -122,8 +122,6 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr 
list,
      if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
          goto cleanup;
- tmp = NULL;
-

moving the NULLification of tmp up to the same point as assigning it to item->path *theoretically* means that it would be leaked if VIR_APPEND_ELEMENT() failed (only theoretical because VIR_APPEND_ELEMENT can't fail, which points out that we really should make VIR_APPEND_ELEMENT ignore the return value of virInsertElementsN())

I guess since we know that failure can't occur, this change is okay, but I should probably take the time to modify VIR_APPEND_ELEMENT() (even though it's supposed to be retired in favor of some sort of glib thing)


      ret = 0;
   cleanup:
      VIR_FREE(tmp);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 01b3e7bc82..0c2ebddd22 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5829,8 +5829,7 @@ testInterfaceChangeRollback(virConnectPtr conn,
      }
virObjectUnref(privconn->ifaces);
-    privconn->ifaces = privconn->backupIfaces;
-    privconn->backupIfaces = NULL;
+    privconn->ifaces = g_steal_pointer(&privconn->backupIfaces);
privconn->transaction_running = false; diff --git a/src/util/virconf.c b/src/util/virconf.c
index 25a3bad50d..572fe31049 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -131,8 +131,7 @@ virConfFreeList(virConfValuePtr list)
      virConfValuePtr next;
while (list != NULL) {
-        next = list->next;
-        list->next = NULL;
+        next = g_steal_pointer(&list->next);
          virConfFreeValue(list);
          list = next;
      }
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 6a2c6844e1..3cf3a3b46a 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -173,8 +173,7 @@ virFDStreamMsgQueuePop(virFDStreamDataPtr fdst,
      char c;
if (tmp) {
-        fdst->msg = tmp->next;
-        tmp->next = NULL;
+        fdst->msg = g_steal_pointer(&tmp->next);
      }
virCondSignal(&fdst->threadCond);
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 9eb4dc4f18..82081db870 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -944,8 +944,7 @@ virJSONValueObjectRemoveKey(virJSONValuePtr object,
      for (i = 0; i < object->data.object.npairs; i++) {
          if (STREQ(object->data.object.pairs[i].key, key)) {
              if (value) {
-                *value = object->data.object.pairs[i].value;
-                object->data.object.pairs[i].value = NULL;
+                *value = g_steal_pointer(&object->data.object.pairs[i].value);
              }
              VIR_FREE(object->data.object.pairs[i].key);
              virJSONValueFree(object->data.object.pairs[i].value);
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 2ac22120d8..5a5de85eab 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3519,14 +3519,12 @@ vboxDumpDisplay(virDomainDefPtr def, vboxDriverPtr 
data, IMachine *machine)
if (STREQ_NULLABLE(valueTypeUtf8, "sdl")) {
              graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
-            graphics->data.sdl.display = valueDisplayUtf8;
-            valueDisplayUtf8 = NULL;
+            graphics->data.sdl.display = g_steal_pointer(&valueDisplayUtf8);
          }
if (STREQ_NULLABLE(valueTypeUtf8, "gui")) {
              graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
-            graphics->data.desktop.display = valueDisplayUtf8;
-            valueDisplayUtf8 = NULL;
+            graphics->data.desktop.display = 
g_steal_pointer(&valueDisplayUtf8);
          }
          VBOX_UTF8_FREE(valueDisplayUtf8);
      } else if (STRNEQ_NULLABLE(valueTypeUtf8, "vrdp")) {
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index f9637a65ab..1e6ef81bf4 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -879,9 +879,7 @@ 
virVBoxSnapshotConfRemoveSnapshot(virVBoxSnapshotConfMachinePtr machine,
return 0;
      }
-    parentSnapshot = snapshot->parent;
-
-    snapshot->parent = NULL;
+    parentSnapshot = g_steal_pointer(&snapshot->parent);
      while (i < parentSnapshot->nchildren && parentSnapshot->children[i] != 
snapshot)
          ++i;
      if (VIR_DELETE_ELEMENT(parentSnapshot->children, i, 
parentSnapshot->nchildren) < 0)
@@ -936,11 +934,10 @@ 
virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegis
          return 0;
      }
- parentHardDisk = hardDisk->parent;
+    parentHardDisk = g_steal_pointer(&hardDisk->parent);
      i = 0;
      while (i < parentHardDisk->nchildren && parentHardDisk->children[i] != 
hardDisk)
          ++i;
-    hardDisk->parent = NULL;
      if (VIR_DELETE_ELEMENT(parentHardDisk->children, i, 
parentHardDisk->nchildren) < 0)
          return -1;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 76d01a36de..0b12b5dd7d 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2604,15 +2604,13 @@ virVMXParseFileSystem(virConfPtr conf, int number, 
virDomainFSDefPtr *def)
      if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0)
          goto cleanup;
- (*def)->src->path = hostPath;
-    hostPath = NULL;
+    (*def)->src->path = g_steal_pointer(&hostPath);
/* vmx:guestName */
      if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0)
          goto cleanup;
- (*def)->dst = guestName;
-    guestName = NULL;
+    (*def)->dst = g_steal_pointer(&guestName);
/* vmx:writeAccess */
      if (virVMXGetConfigBoolean(conf, writeAccess_name, &writeAccess, false,
@@ -2819,9 +2817,7 @@ virVMXParseEthernet(virConfPtr conf, int controller, 
virDomainNetDefPtr *def)
      /* Setup virDomainNetDef */
      if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) {
          (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
-        (*def)->data.bridge.brname = networkName;
-
-        networkName = NULL;
+        (*def)->data.bridge.brname = g_steal_pointer(&networkName);
      } else if (STRCASEEQ(connectionType, "hostonly")) {
          /* FIXME */
          virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2833,11 +2829,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, 
virDomainNetDefPtr *def)
} else if (STRCASEEQ(connectionType, "custom")) {
          (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
-        (*def)->data.bridge.brname = networkName;
-        (*def)->ifname = vnet;
-
-        networkName = NULL;
-        vnet = NULL;
+        (*def)->data.bridge.brname = g_steal_pointer(&networkName);
+        (*def)->ifname = g_steal_pointer(&vnet);
      } else {
          virReportError(VIR_ERR_INTERNAL_ERROR,
                         _("Invalid value '%s' for VMX entry '%s'"), 
connectionType,
@@ -2952,9 +2945,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, 
int port,
      if (!fileType || STRCASEEQ(fileType, "device")) {
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_DEV;
-        (*def)->source->data.file.path = fileName;
-
-        fileName = NULL;
+        (*def)->source->data.file.path = g_steal_pointer(&fileName);
      } else if (STRCASEEQ(fileType, "file")) {
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_FILE;
@@ -2970,9 +2961,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, 
int port,
           */
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_PIPE;
-        (*def)->source->data.file.path = fileName;
-
-        fileName = NULL;
+        (*def)->source->data.file.path = g_steal_pointer(&fileName);
      } else if (STRCASEEQ(fileType, "network")) {
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_TCP;
@@ -3118,9 +3107,7 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, 
int port,
      if (STRCASEEQ(fileType, "device")) {
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_DEV;
-        (*def)->source->data.file.path = fileName;
-
-        fileName = NULL;
+        (*def)->source->data.file.path = g_steal_pointer(&fileName);
      } else if (STRCASEEQ(fileType, "file")) {
          (*def)->target.port = port;
          (*def)->source->type = VIR_DOMAIN_CHR_TYPE_FILE;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index ea21181c25..ac00ed214e 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -768,14 +768,12 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
          if (!(buf = prlsdkGetStringParamVar(PrlVmDev_GetImagePath, prldisk)))
              goto cleanup;
- fs->src->path = buf;
-        buf = NULL;
+        fs->src->path = g_steal_pointer(&buf);
      }
      if (!(buf = prlsdkGetStringParamVar(PrlVmDevHd_GetMountPoint, prldisk)))
          goto cleanup;
- fs->dst = buf;
-    buf = NULL;
+    fs->dst = g_steal_pointer(&buf);
ret = 0; @@ -1176,19 +1174,16 @@ prlsdkGetSerialInfo(PRL_HANDLE serialPort, virDomainChrDefPtr chr)
      switch (emulatedType) {
      case PDT_USE_OUTPUT_FILE:
          chr->source->type = VIR_DOMAIN_CHR_TYPE_FILE;
-        chr->source->data.file.path = friendlyName;
-        friendlyName = NULL;
+        chr->source->data.file.path = g_steal_pointer(&friendlyName);
          break;
      case PDT_USE_SERIAL_PORT_SOCKET_MODE:
          chr->source->type = VIR_DOMAIN_CHR_TYPE_UNIX;
-        chr->source->data.nix.path = friendlyName;
+        chr->source->data.nix.path = g_steal_pointer(&friendlyName);
          chr->source->data.nix.listen = socket_mode == 
PSP_SERIAL_SOCKET_SERVER;
-        friendlyName = NULL;
          break;
      case PDT_USE_REAL_DEVICE:
          chr->source->type = VIR_DOMAIN_CHR_TYPE_DEV;
-        chr->source->data.file.path = friendlyName;
-        friendlyName = NULL;
+        chr->source->data.file.path = g_steal_pointer(&friendlyName);
          break;
      case PDT_USE_TCP:
          chr->source->type = VIR_DOMAIN_CHR_TYPE_TCP;
@@ -1319,8 +1314,7 @@ prlsdkAddVNCInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
          goto error;
if (*passwd != '\0') {
-        gr->data.vnc.auth.passwd = passwd;
-        passwd = NULL;
+        gr->data.vnc.auth.passwd = g_steal_pointer(&passwd);
      }
pret = PrlVmCfg_GetVNCPort(sdkdom, &port);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f5e98a19f8..a778421b66 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3857,10 +3857,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
                  continue;
              }
- vol.source = source;
-            vol.target = target;
-            source = NULL;
-            target = NULL;
+            vol.source = g_steal_pointer(&source);
+            vol.target = g_steal_pointer(&target);
              if (VIR_APPEND_ELEMENT(vols, nvols, vol) < 0)
                  goto cleanup;
          }
diff --git a/tools/vsh.c b/tools/vsh.c
index 1ffc13d443..552ed29ab9 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1425,8 +1425,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser, vshCmd **partial)
                          if (partial) {
                              vshCmdOpt *arg = g_new0(vshCmdOpt, 1);
                              arg->def = opt;
-                            arg->data = tkdata;
-                            tkdata = NULL;
+                            arg->data = g_steal_pointer(&tkdata);
                              arg->next = NULL;
if (parser->pos - parser->originalLine == parser->point - 1)
@@ -1479,9 +1478,8 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser, vshCmd **partial)
                  vshCmdOpt *arg = g_new0(vshCmdOpt, 1);
arg->def = opt;
-                arg->data = tkdata;
+                arg->data = g_steal_pointer(&tkdata);
                  arg->next = NULL;
-                tkdata = NULL;
if (parser->pos - parser->originalLine == parser->point)
                      arg->completeThis = true;
@@ -1526,10 +1524,9 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser, vshCmd **partial)
                  break;
              }
- c->opts = first;
+            c->opts = g_steal_pointer(&first);
              c->def = cmd;
              c->next = NULL;
-            first = NULL;
if (!partial &&
                  vshCommandCheckOpts(ctl, c, opts_required, opts_seen) < 0) {


Reply via email to