]> xenbits.xensource.com Git - libvirt.git/commitdiff
lib: Use more of VIR_STEAL_PTR()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 28 Jan 2019 13:41:37 +0000 (14:41 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 28 Jan 2019 13:46:58 +0000 (14:46 +0100)
We have this very handy macro called VIR_STEAL_PTR() which steals
one pointer into the other and sets the other to NULL. The
following coccinelle patch was used to create this commit:

  @ rule1 @
  identifier a, b;
  @@

  - b = a;
    ...
  - a = NULL;
  + VIR_STEAL_PTR(b, a);

Some places were clean up afterwards to make syntax-check happy
(e.g. some curly braces were removed where the body become a one
liner).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
22 files changed:
src/conf/domain_addr.c
src/conf/domain_conf.c
src/conf/secret_conf.c
src/conf/storage_conf.c
src/conf/virnetworkobj.c
src/conf/virsecretobj.c
src/libvirt-domain.c
src/phyp/phyp_driver.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/security/virt-aa-helper.c
src/storage/storage_driver.c
src/test/test_driver.c
src/util/virdbus.c
src/util/virrotatingfile.c
src/util/virstoragefile.c
src/vz/vz_driver.c
src/vz/vz_sdk.c
tests/networkxml2conftest.c
tools/virsh-domain.c
tools/virsh-snapshot.c

index 618fce44f08df4250c37ee9f1718bf971104e6d3..04c4e6d7e1c9c0bece4ab015e7ebf71820df3ff7 100644 (file)
@@ -1757,8 +1757,7 @@ virDomainVirtioSerialAddrSetCreateFromDomain(virDomainDefPtr def)
                                    addrs) < 0)
         goto cleanup;
 
-    ret = addrs;
-    addrs = NULL;
+    VIR_STEAL_PTR(ret, addrs);
  cleanup:
     virDomainVirtioSerialAddrSetFree(addrs);
     return ret;
@@ -2095,8 +2094,7 @@ virDomainUSBAddressHubNew(size_t nports)
         goto cleanup;
     hub->nports = nports;
 
-    ret = hub;
-    hub = NULL;
+    VIR_STEAL_PTR(ret, hub);
  cleanup:
     virDomainUSBAddressHubFree(hub);
     return ret;
index 22979e6c4ed9451823d82878da3c06771df4c499..9409d93c23b57f4ba727318249f7a858200a0d17 100644 (file)
@@ -7900,8 +7900,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
         goto cleanup;
     }
 
-    ret = ip;
-    ip = NULL;
+    VIR_STEAL_PTR(ret, ip);
 
  cleanup:
     VIR_FREE(prefixStr);
@@ -13482,10 +13481,8 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
             goto error;
         }
 
-        if (!address) {
-            address = addressCompat;
-            addressCompat = NULL;
-        }
+        if (!address)
+            VIR_STEAL_PTR(address, addressCompat);
     }
 
     if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) {
@@ -13497,10 +13494,8 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
             goto error;
         }
 
-        if (!socketPath) {
-            socketPath = socketCompat;
-            socketCompat = NULL;
-        }
+        if (!socketPath)
+            VIR_STEAL_PTR(socketPath, socketCompat);
     }
 
     if (address && address[0] &&
@@ -14747,8 +14742,7 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto cleanup;
 
 
-    ret = def;
-    def = NULL;
+    VIR_STEAL_PTR(ret, def);
  cleanup:
     ctxt->node = save;
     VIR_FREE(tmp);
@@ -16187,8 +16181,7 @@ virDomainIOMMUDefParseXML(xmlNodePtr node,
         }
     }
 
-    ret = iommu;
-    iommu = NULL;
+    VIR_STEAL_PTR(ret, iommu);
 
  cleanup:
     ctxt->node = save;
index 3a5aa725631d9df5745be57f15fdf6234ddbaf8d..ca6cc194a215a921d3474be35cbc0e2b9b783d53 100644 (file)
@@ -193,8 +193,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
     if (virXPathNode("./usage", ctxt) != NULL
         && virSecretDefParseUsage(ctxt, def) < 0)
         goto cleanup;
-    ret = def;
-    def = NULL;
+    VIR_STEAL_PTR(ret, def);
 
  cleanup:
     VIR_FREE(prop);
index 55db7a96f5dbb7c59f670fc76b17d74c58746b7d..ba5b1f1783ec8fe7579002bbd0c27b9318d85b6f 100644 (file)
@@ -587,8 +587,7 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
                                      node) < 0)
         goto cleanup;
 
-    ret = def;
-    def = NULL;
+    VIR_STEAL_PTR(ret, def);
  cleanup:
     virStoragePoolSourceFree(def);
     xmlFreeDoc(doc);
index e6b01388f51c1b48d3aab2e0fad9935a68b769c9..3749dda751079aecd8ec0b1e52ae7b4506d9cf7a 100644 (file)
@@ -602,8 +602,7 @@ virNetworkObjAssignDefLocked(virNetworkObjListPtr nets,
         obj->persistent = !(flags & VIR_NETWORK_OBJ_LIST_ADD_LIVE);
     }
 
-    ret = obj;
-    obj = NULL;
+    VIR_STEAL_PTR(ret, obj);
 
  cleanup:
     virNetworkObjEndAPI(&obj);
index 78911c09086dd56ce6c256e6e26f8c8212540d43..c4e7b06eca0deed5213779e9c13b0d79fd767673 100644 (file)
@@ -394,8 +394,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
         virObjectRef(obj);
     }
 
-    ret = obj;
-    obj = NULL;
+    VIR_STEAL_PTR(ret, obj);
 
  cleanup:
     virSecretObjEndAPI(&obj);
index 75c9014c0ecdff3a1f4fc99e7bd18748e743fe61..b04929a6edc8306f25d54423b59f412105fffdfa 100644 (file)
@@ -3046,9 +3046,8 @@ virDomainMigrateVersion3Full(virDomainPtr domain,
                           VIR_MIGRATE_AUTO_CONVERGE);
 
     VIR_DEBUG("Prepare3 %p flags=0x%x", dconn, destflags);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     if (useParams) {
         if (virTypedParamsReplaceString(&params, &nparams,
@@ -3111,9 +3110,8 @@ virDomainMigrateVersion3Full(virDomainPtr domain,
      */
     VIR_DEBUG("Perform3 %p uri=%s", domain->conn, uri);
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     /* dconnuri not relevant in non-P2P modes, so left NULL here */
     if (useParams) {
@@ -3150,9 +3148,8 @@ virDomainMigrateVersion3Full(virDomainPtr domain,
      */
     VIR_DEBUG("Finish3 %p ret=%d", dconn, ret);
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     if (useParams) {
         if (virTypedParamsGetString(params, nparams,
@@ -3227,9 +3224,8 @@ virDomainMigrateVersion3Full(virDomainPtr domain,
     if (notify_source) {
         VIR_DEBUG("Confirm3 %p ret=%d domain=%p", domain->conn, ret, domain);
         VIR_FREE(cookiein);
-        cookiein = cookieout;
+        VIR_STEAL_PTR(cookiein, cookieout);
         cookieinlen = cookieoutlen;
-        cookieout = NULL;
         cookieoutlen = 0;
         if (useParams) {
             ret = domain->conn->driver->domainMigrateConfirm3Params
index 4acc6ce73481c8648ec2ef20b6c256e5e601707c..4ffa08ff43337881874242d4542e949aa85db11d 100644 (file)
@@ -1468,8 +1468,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
         if (VIR_STRDUP(backing_device, char_ptr) < 0)
             goto cleanup;
     } else {
-        backing_device = ret;
-        ret = NULL;
+        VIR_STEAL_PTR(backing_device, ret);
     }
 
     char_ptr = strchr(backing_device, '\n');
index f42903a34304e9c34db72d2d673c5679e34c5e57..6eeabe0df11b9cc53d048da5414c6bca57badee0 100644 (file)
@@ -11645,8 +11645,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
             }
             VIR_FREE(devTmp);
             VIR_FREE(target);
-            target = tmp;
-            tmp = NULL;
+            VIR_STEAL_PTR(target, tmp);
         }
 
         if (qemuDomainCreateDeviceRecursive(target, data,
@@ -12601,8 +12600,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
             }
             VIR_FREE(fileTmp);
             VIR_FREE(target);
-            target = tmp;
-            tmp = NULL;
+            VIR_STEAL_PTR(target, tmp);
         }
 
         data.target = target;
index 2d8e4618bdcd9c1947ec82e04b22a99825aeccac..5387150bbd214a97617ef7d1831e326e8f1234c4 100644 (file)
@@ -6655,11 +6655,9 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver,
         virFreeError(err);
 
         /* use the user provided XML */
-        ret = newdef;
-        newdef = NULL;
+        VIR_STEAL_PTR(ret, newdef);
     } else {
-        ret = newdef_migr;
-        newdef_migr = NULL;
+        VIR_STEAL_PTR(ret, newdef_migr);
     }
 
  cleanup:
@@ -12705,10 +12703,8 @@ qemuDomainMigratePerform(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (flags & VIR_MIGRATE_PEER2PEER) {
-        dconnuri = uri;
-        uri = NULL;
-    }
+    if (flags & VIR_MIGRATE_PEER2PEER)
+        VIR_STEAL_PTR(dconnuri, uri);
 
     /* Do not output cookies in v2 protocol, since the cookie
      * length was not sufficiently large, causing failures
index 950d9cd615bac566fdf389d4f10308b30973ccc4..52aa6656404a4d712822b2ba9b9b7ff21f0fb825 100644 (file)
@@ -4170,9 +4170,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
                           VIR_MIGRATE_AUTO_CONVERGE);
 
     VIR_DEBUG("Prepare3 %p", dconn);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     if (flags & VIR_MIGRATE_TUNNELLED) {
         if (!(st = virStreamNew(dconn, 0)))
@@ -4239,9 +4238,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
     VIR_DEBUG("Perform3 %p uri=%s", sconn, NULLSTR(uri));
     qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PERFORM3);
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     if (flags & VIR_MIGRATE_TUNNELLED) {
         ret = qemuMigrationSrcPerformTunnel(driver, vm, st, persist_xml,
@@ -4281,9 +4279,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
      */
     VIR_DEBUG("Finish3 %p ret=%d", dconn, ret);
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
 
     if (useParams) {
@@ -4362,9 +4359,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
      */
     VIR_DEBUG("Confirm3 %p cancelled=%d vm=%p", sconn, cancelled, vm);
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     ret = qemuMigrationSrcConfirmPhase(driver, vm,
                                        cookiein, cookieinlen,
index 56d7cfadf12c5732abc211bcecfeecc46346a2bf..8e22e9978a9d65d656b664e5153475de6bbe0a64 100644 (file)
@@ -355,8 +355,7 @@ create_profile(const char *profile, const char *profile_name,
         if (!(tmp = virStringReplace(pcontent, template_end, replace_files)))
             goto clean_all;
         VIR_FREE(pcontent);
-        pcontent = tmp;
-        tmp = NULL;
+        VIR_STEAL_PTR(pcontent, tmp);
     }
 
     /* write the file */
index 4a13e90481a0a88acd170dbfe3089e5b3556d6c0..878a40cac57c03ae0145c225bb96274cd39ce9e8 100644 (file)
@@ -1936,8 +1936,7 @@ storageVolCreateXML(virStoragePoolPtr pool,
 
     VIR_INFO("Creating volume '%s' in storage pool '%s'",
              newvol->name, def->name);
-    vol = newvol;
-    newvol = NULL;
+    VIR_STEAL_PTR(vol, newvol);
     voldef = NULL;
 
  cleanup:
@@ -2130,8 +2129,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool,
 
     VIR_INFO("Creating volume '%s' in storage pool '%s'",
              newvol->name, def->name);
-    vol = newvol;
-    newvol = NULL;
+    VIR_STEAL_PTR(vol, newvol);
     voldef = NULL;
 
  cleanup:
index 1d81772a46442a062028258fc8d27e27b77f8310..568c52aa2846f47291559c2920bdecefa546faba 100644 (file)
@@ -5595,8 +5595,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
     if (VIR_STRDUP(dev->parentName, def->parent) < 0)
         goto cleanup;
 
-    ret = dev;
-    dev = NULL;
+    VIR_STEAL_PTR(ret, dev);
 
  cleanup:
     virNodeDeviceObjEndAPI(&obj);
index 691f1823876546affed8d6931daa39a9dd15d7e2..6725e0edb034d40239881091bc44c46b4348fcd7 100644 (file)
@@ -762,8 +762,7 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
                 goto cleanup;
             }
             VIR_FREE(contsig);
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = t + 1;
             nstruct = skiplen;
             narray = (size_t)va_arg(args, int);
@@ -789,8 +788,7 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
                 VIR_FREE(newiter);
                 goto cleanup;
             }
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = vsig;
             nstruct = strlen(types);
             narray = (size_t)-1;
@@ -821,8 +819,7 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
                 goto cleanup;
             }
             VIR_FREE(contsig);
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = t + 1;
             nstruct = skiplen - 2;
             narray = (size_t)-1;
@@ -1059,8 +1056,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
                                      nstruct, narray) < 0)
                 goto cleanup;
             VIR_FREE(contsig);
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = t + 1;
             nstruct = skiplen;
             if (arrayref) {
@@ -1090,8 +1086,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
                 VIR_DEBUG("Push failed");
                 goto cleanup;
             }
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = vsig;
             nstruct = strlen(types);
             narray = (size_t)-1;
@@ -1118,8 +1113,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
                                      nstruct, narray) < 0)
                 goto cleanup;
             VIR_FREE(contsig);
-            iter = newiter;
-            newiter = NULL;
+            VIR_STEAL_PTR(iter, newiter);
             types = t + 1;
             nstruct = skiplen - 2;
             narray = (size_t)-1;
index d7dc3bd1ce0f1cd01d85ab0d76dc451a8a63d51c..7a268319a6f717151ba60fa5532b57ebf9904e88 100644 (file)
@@ -406,8 +406,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file)
             }
 
             VIR_FREE(nextpath);
-            nextpath = thispath;
-            thispath = NULL;
+            VIR_STEAL_PTR(nextpath, thispath);
         }
     }
 
index bd4b0274dfc96e87a0228e1dd07d354229db4146..70fe551e5f0812a10cf0f35680141f7ad4cfab38 100644 (file)
@@ -1233,8 +1233,7 @@ virStorageFileGetMetadataFromFD(const char *path,
          * update the metadata.*/
         meta->type = VIR_STORAGE_TYPE_DIR;
         meta->format = VIR_STORAGE_FILE_DIR;
-        ret = meta;
-        meta = NULL;
+        VIR_STEAL_PTR(ret, meta);
         goto cleanup;
     }
 
@@ -1256,8 +1255,7 @@ virStorageFileGetMetadataFromFD(const char *path,
     else if (S_ISBLK(sb.st_mode))
         meta->type = VIR_STORAGE_TYPE_BLOCK;
 
-    ret = meta;
-    meta = NULL;
+    VIR_STEAL_PTR(ret, meta);
 
  cleanup:
     virStorageSourceFree(meta);
index 7e9ef932dc6bdca6329ac5bd8e1f6bff30b7ab4c..8eaeb79f3c69a739444dc55782592859dafab9c3 100644 (file)
@@ -182,12 +182,8 @@ vzDestroyDriverConnection(void)
     vzConnPtr privconn_list;
 
     virMutexLock(&vz_driver_lock);
-    driver = vz_driver;
-    vz_driver = NULL;
-
-    privconn_list = vz_conn_list;
-    vz_conn_list = NULL;
-
+    VIR_STEAL_PTR(driver, vz_driver);
+    VIR_STEAL_PTR(privconn_list, vz_conn_list);
     virMutexUnlock(&vz_driver_lock);
 
     while (privconn_list) {
@@ -3203,9 +3199,8 @@ vzDomainMigratePerformP2P(virDomainObjPtr dom,
                                 VIR_MIGRATE_PARAM_DEST_XML, dom_xml) < 0)
         goto done;
 
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     virObjectUnlock(dom);
     ret = dconn->driver->domainMigratePrepare3Params
@@ -3226,9 +3221,8 @@ vzDomainMigratePerformP2P(virDomainObjPtr dom,
     }
 
     VIR_FREE(cookiein);
-    cookiein = cookieout;
+    VIR_STEAL_PTR(cookiein, cookieout);
     cookieinlen = cookieoutlen;
-    cookieout = NULL;
     cookieoutlen = 0;
     if (vzDomainMigratePerformStep(dom, driver, params, nparams, cookiein,
                                    cookieinlen, flags) < 0) {
index 63d013deac6058bdd0257e796a986dbfa1d0739a..b9fd03c0d2d8bea7b439c2fd41fa3f452b3cfc54 100644 (file)
@@ -928,8 +928,7 @@ prlsdkParseNetAddress(char *addr)
         goto cleanup;
     ip->prefix = nbits;
 
-    ret = ip;
-    ip = NULL;
+    VIR_STEAL_PTR(ret, ip);
 
  cleanup:
     if (!ret)
@@ -4768,8 +4767,7 @@ prlsdkParseSnapshotTree(const char *treexml)
         goto cleanup;
     }
 
-    ret = snapshots;
-    snapshots = NULL;
+    VIR_STEAL_PTR(ret, snapshots);
 
  cleanup:
     virDomainSnapshotObjListFree(snapshots);
index 367e30b994455a32a8c71edae4ab518f37cfeebb..c362149c296bedc6af0da6719fbd10958d41b56c 100644 (file)
@@ -51,8 +51,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr
                                  "except-interface=lo\n")))
         goto fail;
     VIR_FREE(actual);
-    actual = tmp;
-    tmp = NULL;
+    VIR_STEAL_PTR(actual, tmp);
 #endif
 
     if (virTestCompareToFile(actual, outconf) < 0)
index e63fc028b9ed45cd8ffdebe90ee88d1ac47c11a9..34f9e6b5c6f909d60e406d7a3a0ed5f1bc7a568d 100644 (file)
@@ -8423,8 +8423,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
             }
 
             VIR_FREE(desc);
-            desc = desc_edited;
-            desc_edited = NULL;
+            VIR_STEAL_PTR(desc, desc_edited);
         }
 
         if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) {
index e3d4cda0fc8e6f138471daa7c762bdd4e27319a1..6d8e2b299bb89f17a4a53841317c91af147b3d6a 100644 (file)
@@ -1356,8 +1356,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
           virshSnapSorter);
     snaplist->nsnaps -= deleted;
 
-    ret = snaplist;
-    snaplist = NULL;
+    VIR_STEAL_PTR(ret, snaplist);
 
  cleanup:
     virshSnapshotListFree(snaplist);