[PATCH] Use g_steal_pointer where possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Via coccinelle (not the hanbag!)
spatches used:
@ rule1 @
identifier a, b;
symbol NULL;
@@

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

@@

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

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/admin/admin_server.c                |  6 ++----
 src/conf/capabilities.c                 |  3 +--
 src/conf/netdev_bandwidth_conf.c        |  3 +--
 src/conf/virdomainobjlist.c             |  3 +--
 src/conf/virnwfilterobj.c               |  3 +--
 src/interface/interface_backend_netcf.c |  3 +--
 src/interface/interface_backend_udev.c  |  3 +--
 src/qemu/qemu_driver.c                  | 12 ++++-------
 src/qemu/qemu_monitor_json.c            | 27 +++++++++----------------
 src/remote/remote_driver.c              | 12 ++++-------
 src/rpc/virnetserver.c                  |  3 +--
 src/util/virfile.c                      |  9 +++------
 src/util/virlog.c                       |  6 ++----
 src/util/virmdev.c                      |  3 +--
 src/util/virsysinfo.c                   | 21 +++++++------------
 src/util/virtypedparam.c                |  3 +--
 src/vbox/vbox_common.c                  |  3 +--
 src/vz/vz_driver.c                      |  3 +--
 tests/commandhelper.c                   |  3 +--
 tools/virsh-checkpoint.c                |  3 +--
 tools/virsh-domain.c                    |  3 +--
 21 files changed, 45 insertions(+), 90 deletions(-)

diff --git a/src/admin/admin_server.c b/src/admin/admin_server.c
index ebc0cfb045..7d1a21a678 100644
--- a/src/admin/admin_server.c
+++ b/src/admin/admin_server.c
@@ -50,8 +50,7 @@ adminConnectListServers(virNetDaemonPtr dmn,
         goto cleanup;
 
     if (servers) {
-        *servers = srvs;
-        srvs = NULL;
+        *servers = g_steal_pointer(&srvs);
     }
  cleanup:
     if (ret > 0)
@@ -179,8 +178,7 @@ adminServerListClients(virNetServerPtr srv,
         return -1;
 
     if (clients) {
-        *clients = clts;
-        clts = NULL;
+        *clients = g_steal_pointer(&clts);
     }
 
     virObjectListFreeCount(clts, ret);
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 69d9bb0e38..f610975ae5 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1501,9 +1501,8 @@ virCapabilitiesGetNUMASiblingInfo(int node,
     if (VIR_REALLOC_N(tmp, tmp_size) < 0)
         goto cleanup;
 
-    *siblings = tmp;
     *nsiblings = tmp_size;
-    tmp = NULL;
+    *siblings = g_steal_pointer(&tmp);
     tmp_size = 0;
     ret = 0;
  cleanup:
diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c
index 4fb7aa4e3d..ff25641b2c 100644
--- a/src/conf/netdev_bandwidth_conf.c
+++ b/src/conf/netdev_bandwidth_conf.c
@@ -205,8 +205,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
     if (!def->in && !def->out)
         VIR_FREE(def);
 
-    *bandwidth = def;
-    def = NULL;
+    *bandwidth = g_steal_pointer(&def);
     ret = 0;
 
  cleanup:
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 2521cd56c2..d37bbc94a6 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -1083,8 +1083,7 @@ virDomainObjListExport(virDomainObjListPtr domlist,
                 goto cleanup;
         }
 
-        *domains = doms;
-        doms = NULL;
+        *domains = g_steal_pointer(&doms);
     }
 
     ret = nvms;
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 3157522eb2..f4bf1b083d 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -464,8 +464,7 @@ virNWFilterObjListExport(virConnectPtr conn,
         virNWFilterObjUnlock(obj);
     }
 
-    *filters = tmp_filters;
-    tmp_filters = NULL;
+    *filters = g_steal_pointer(&tmp_filters);
     ret = nfilters;
 
  cleanup:
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index e40a4cb108..f8613fea86 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -715,8 +715,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
     if (tmp_iface_objs) {
         /* trim the array to the final size */
         ignore_value(VIR_REALLOC_N(tmp_iface_objs, niface_objs + 1));
-        *ifaces = tmp_iface_objs;
-        tmp_iface_objs = NULL;
+        *ifaces = g_steal_pointer(&tmp_iface_objs);
     }
 
     ret = niface_objs;
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 6a94a45044..ab95b2e3ff 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -394,8 +394,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
     /* Trim the array to its final size */
     if (ifaces) {
         ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
-        *ifaces = ifaces_list;
-        ifaces_list = NULL;
+        *ifaces = g_steal_pointer(&ifaces_list);
     }
 
     return count;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b9bbdf8d48..d1a3659774 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5097,8 +5097,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef,
         bitmap = NULL;
     }
 
-    *info = info_ret;
-    info_ret = NULL;
+    *info = g_steal_pointer(&info_ret);
     ret = targetDef->niothreadids;
 
  cleanup:
@@ -9133,9 +9132,8 @@ qemuDomainGetPerfEvents(virDomainPtr dom,
             goto endjob;
     }
 
-    *params = par;
     *nparams = npar;
-    par = NULL;
+    *params = g_steal_pointer(&par);
     npar = 0;
     ret = 0;
 
@@ -18729,8 +18727,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
         virObjectUnlock(vm);
     }
 
-    *retStats = tmpstats;
-    tmpstats = NULL;
+    *retStats = g_steal_pointer(&tmpstats);
 
     ret = nstats;
 
@@ -19259,9 +19256,8 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
 
 #undef ADD_BITMAP
 
-    *params = par;
     *nparams = npar;
-    par = NULL;
+    *params = g_steal_pointer(&par);
     ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f8c78d9093..819389f5f9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5820,8 +5820,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *machines = infolist;
-    infolist = NULL;
+    *machines = g_steal_pointer(&infolist);
 
  cleanup:
     if (infolist) {
@@ -6268,8 +6267,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *commands = commandlist;
-    commandlist = NULL;
+    *commands = g_steal_pointer(&commandlist);
 
 
  cleanup:
@@ -6327,8 +6325,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *events = eventlist;
-    eventlist = NULL;
+    *events = g_steal_pointer(&eventlist);
 
  cleanup:
     g_strfreev(eventlist);
@@ -6472,8 +6469,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *types = typelist;
-    typelist = NULL;
+    *types = g_steal_pointer(&typelist);
 
  cleanup:
     g_strfreev(typelist);
@@ -6542,8 +6538,7 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *paths = pathlist;
-    pathlist = NULL;
+    *paths = g_steal_pointer(&pathlist);
 
  cleanup:
     if (pathlist) {
@@ -6779,8 +6774,7 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
     }
 
     ret = count;
-    *props = proplist;
-    proplist = NULL;
+    *props = g_steal_pointer(&proplist);
 
  cleanup:
     g_strfreev(proplist);
@@ -6962,8 +6956,7 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *capabilities = list;
-    list = NULL;
+    *capabilities = g_steal_pointer(&list);
 
  cleanup:
     g_strfreev(list);
@@ -7091,8 +7084,7 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
     }
 
     ret = n;
-    *capabilities = list;
-    list = NULL;
+    *capabilities = g_steal_pointer(&list);
 
  cleanup:
     VIR_FREE(list);
@@ -8157,8 +8149,7 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
     }
 
     *niothreads = n;
-    *iothreads = infolist;
-    infolist = NULL;
+    *iothreads = g_steal_pointer(&infolist);
     ret = 0;
 
  cleanup:
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a83cd866e7..31868269b1 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -6299,8 +6299,7 @@ remoteConnectGetCPUModelNames(virConnectPtr conn,
             retmodels[i] = ret.models.models_val[i];
             ret.models.models_val[i] = NULL;
         }
-        *models = retmodels;
-        retmodels = NULL;
+        *models = g_steal_pointer(&retmodels);
     }
 
     rv = ret.ret;
@@ -7464,8 +7463,7 @@ remoteNetworkGetDHCPLeases(virNetworkPtr net,
                 goto cleanup;
         }
 
-        *leases = leases_ret;
-        leases_ret = NULL;
+        *leases = g_steal_pointer(&leases_ret);
     }
 
     rv = ret.ret;
@@ -7555,8 +7553,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn,
         elem = NULL;
     }
 
-    *retStats = tmpret;
-    tmpret = NULL;
+    *retStats = g_steal_pointer(&tmpret);
     rv = ret.retStats.retStats_len;
 
  cleanup:
@@ -7774,8 +7771,7 @@ remoteDomainInterfaceAddresses(virDomainPtr dom,
             }
         }
     }
-    *ifaces = ifaces_ret;
-    ifaces_ret = NULL;
+    *ifaces = g_steal_pointer(&ifaces_ret);
 
     rv = ret.ifaces.ifaces_len;
 
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index f0b866a962..265400ecfa 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -1146,8 +1146,7 @@ virNetServerGetClients(virNetServerPtr srv,
         }
     }
 
-    *clts = list;
-    list = NULL;
+    *clts = g_steal_pointer(&list);
     ret = nclients;
 
  cleanup:
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 5710495bbf..7cb60e66d3 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -840,8 +840,7 @@ int virFileLoopDeviceAssociate(const char *file,
     }
 
     VIR_DEBUG("Attached loop device  %s %d to %s", file, lofd, loname);
-    *dev = loname;
-    loname = NULL;
+    *dev = g_steal_pointer(&loname);
 
     ret = 0;
 
@@ -3200,8 +3199,7 @@ virFileOpenTty(int *ttyprimary, char **ttyName, int rawmode)
             errno = rc;
             goto cleanup;
         }
-        *ttyName = name;
-        name = NULL;
+        *ttyName = g_steal_pointer(&name);
     }
 
     ret = 0;
@@ -3637,9 +3635,8 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
         tmp->deflt = tmp->size == default_hugepagesz;
     }
 
-    *ret_fs = fs;
     *ret_nfs = nfs;
-    fs = NULL;
+    *ret_fs = g_steal_pointer(&fs);
     nfs = 0;
     ret = 0;
 
diff --git a/src/util/virlog.c b/src/util/virlog.c
index cdfeba8251..00c0fcc457 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1658,8 +1658,7 @@ virLogParseOutputs(const char *src, virLogOutputPtr **outputs)
     }
 
     ret = noutputs;
-    *outputs = list;
-    list = NULL;
+    *outputs = g_steal_pointer(&list);
  cleanup:
     g_strfreev(strings);
     return ret;
@@ -1708,8 +1707,7 @@ virLogParseFilters(const char *src, virLogFilterPtr **filters)
     }
 
     ret = nfilters;
-    *filters = list;
-    list = NULL;
+    *filters = g_steal_pointer(&list);
  cleanup:
     g_strfreev(strings);
     return ret;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index db40fe8cc3..2b7f730bd1 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -95,8 +95,7 @@ virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr dev,
     if ((tmp = strchr(buf, '\n')))
         *tmp = '\0';
 
-    *device_api = buf;
-    buf = NULL;
+    *device_api = g_steal_pointer(&buf);
 
     return 0;
 }
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 995650334c..0016028254 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -258,8 +258,7 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
         def = NULL;
     }
 
-    *sysdef = def;
-    def = NULL;
+    *sysdef = g_steal_pointer(&def);
     ret = 0;
     virSysinfoSystemDefFree(def);
     return ret;
@@ -381,8 +380,7 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSystemDefPtr *sysdef)
         def = NULL;
     }
 
-    *sysdef = def;
-    def = NULL;
+    *sysdef = g_steal_pointer(&def);
     ret = 0;
     virSysinfoSystemDefFree(def);
     return ret;
@@ -521,8 +519,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef)
         def = NULL;
     }
 
-    *sysdef = def;
-    def = NULL;
+    *sysdef = g_steal_pointer(&def);
     ret = 0;
  cleanup:
     virSysinfoSystemDefFree(def);
@@ -686,8 +683,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
         def = NULL;
     }
 
-    *bios = def;
-    def = NULL;
+    *bios = g_steal_pointer(&def);
     ret = 0;
     virSysinfoBIOSDefFree(def);
     return ret;
@@ -763,8 +759,7 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
         def = NULL;
     }
 
-    *sysdef = def;
-    def = NULL;
+    *sysdef = g_steal_pointer(&def);
     ret = 0;
     virSysinfoSystemDefFree(def);
     return ret;
@@ -845,9 +840,8 @@ virSysinfoParseX86BaseBoard(const char *base,
         ignore_value(VIR_REALLOC_N(boards, nboards));
     }
 
-    *baseBoard = boards;
     *nbaseBoard = nboards;
-    boards = NULL;
+    *baseBoard = g_steal_pointer(&boards);
     nboards = 0;
     ret = 0;
  cleanup:
@@ -915,8 +909,7 @@ virSysinfoParseX86Chassis(const char *base,
         def = NULL;
     }
 
-    *chassisdef = def;
-    def = NULL;
+    *chassisdef = g_steal_pointer(&def);
     ret = 0;
     virSysinfoChassisDefFree(def);
     return ret;
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index f9ab6f6042..c4c26a1183 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -706,9 +706,8 @@ virTypedParamsSerialize(virTypedParameterPtr params,
         j++;
     }
 
-    *remote_params_val = params_val;
     *remote_params_len = params_len;
-    params_val = NULL;
+    *remote_params_val = g_steal_pointer(&params_val);
     rv = 0;
 
  cleanup:
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 138403b034..0c4126bd38 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7583,8 +7583,7 @@ vboxConnectListAllDomains(virConnectPtr conn,
         /* safe to ignore, new size will be equal or less than
          * previous allocation */
         ignore_value(VIR_REALLOC_N(doms, count + 1));
-        *domains = doms;
-        doms = NULL;
+        *domains = g_steal_pointer(&doms);
     }
 
     ret = count;
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 0ebcb06234..60ed286cee 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -3817,8 +3817,7 @@ vzConnectGetAllDomainStats(virConnectPtr conn,
         tmpstats[nstats++] = tmp;
     }
 
-    *retStats = tmpstats;
-    tmpstats = NULL;
+    *retStats = g_steal_pointer(&tmpstats);
     ret = nstats;
 
  cleanup:
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index b3c65ab3cc..ee06339392 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -116,8 +116,7 @@ static struct Arguments *parseArguments(int argc, char** argv)
         }
     }
 
-    ret = args;
-    args = NULL;
+    ret = g_steal_pointer(&args);
     return ret;
 }
 
diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c
index 6e68ba66ff..91f7c963c1 100644
--- a/tools/virsh-checkpoint.c
+++ b/tools/virsh-checkpoint.c
@@ -633,8 +633,7 @@ virshCheckpointListCollect(vshControl *ctl,
         qsort(checkpointlist->chks, checkpointlist->nchks,
               sizeof(*checkpointlist->chks), virshChkSorter);
 
-    ret = checkpointlist;
-    checkpointlist = NULL;
+    ret = g_steal_pointer(&checkpointlist);
 
  cleanup:
     virshCheckpointListFree(checkpointlist);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d40995f44d..3597190523 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5187,8 +5187,7 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
         goto cleanup;
 
     ret = nparams;
-    *update_params = params;
-    params = NULL;
+    *update_params = g_steal_pointer(&params);
 
  cleanup:
     VIR_FREE(set_field);
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux