mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
lib: Use more of VIR_STEAL_PTR()
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>
This commit is contained in:
parent
7c700108d6
commit
5772885d28
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -394,8 +394,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
|
||||
virObjectRef(obj);
|
||||
}
|
||||
|
||||
ret = obj;
|
||||
obj = NULL;
|
||||
VIR_STEAL_PTR(ret, obj);
|
||||
|
||||
cleanup:
|
||||
virSecretObjEndAPI(&obj);
|
||||
|
@ -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(¶ms, &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
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 */
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -406,8 +406,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file)
|
||||
}
|
||||
|
||||
VIR_FREE(nextpath);
|
||||
nextpath = thispath;
|
||||
thispath = NULL;
|
||||
VIR_STEAL_PTR(nextpath, thispath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user