mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
src: Use g_steal_pointer() more
There are few places where the g_steal_pointer() is open coded. Switch them to calling the g_steal_pointer() function instead. Generated by the following spatch: @ rule1 @ expression a, b; @@ <... - b = a; ... when != b - a = NULL; + b = g_steal_pointer(&a); ...> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
a7c016e4cb
commit
2c0898ff4e
@ -1033,8 +1033,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
|
||||
if (root != ctx->service->rootFolder)
|
||||
esxVI_ManagedObjectReference_Free(&root);
|
||||
|
||||
root = folder->_reference;
|
||||
folder->_reference = NULL;
|
||||
root = g_steal_pointer(&folder->_reference);
|
||||
} else {
|
||||
/* Try to lookup item as a datacenter */
|
||||
if (esxVI_LookupDatacenter(ctx, item, root, NULL, &ctx->datacenter,
|
||||
@ -1087,8 +1086,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
|
||||
if (root != ctx->datacenter->hostFolder)
|
||||
esxVI_ManagedObjectReference_Free(&root);
|
||||
|
||||
root = folder->_reference;
|
||||
folder->_reference = NULL;
|
||||
root = g_steal_pointer(&folder->_reference);
|
||||
} else {
|
||||
/* Try to lookup item as a compute resource */
|
||||
if (esxVI_LookupComputeResource(ctx, item, root, NULL,
|
||||
|
@ -1780,8 +1780,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
||||
|
||||
priv->version = g_strdup(os->data->Version);
|
||||
|
||||
conn->privateData = priv;
|
||||
priv = NULL;
|
||||
conn->privateData = g_steal_pointer(&priv);
|
||||
result = VIR_DRV_OPEN_SUCCESS;
|
||||
|
||||
cleanup:
|
||||
@ -3519,8 +3518,7 @@ hypervConnectListAllDomains(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if (doms)
|
||||
*domains = doms;
|
||||
doms = NULL;
|
||||
*domains = g_steal_pointer(&doms);
|
||||
ret = count;
|
||||
|
||||
cleanup:
|
||||
|
@ -994,8 +994,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQuery *wqlQuery,
|
||||
response = NULL;
|
||||
}
|
||||
|
||||
*list = head;
|
||||
head = NULL;
|
||||
*list = g_steal_pointer(&head);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -586,8 +586,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDef *hostdev,
|
||||
*/
|
||||
if (MAC) {
|
||||
VIR_FREE(adminMAC);
|
||||
adminMAC = MAC;
|
||||
MAC = NULL;
|
||||
adminMAC = g_steal_pointer(&MAC);
|
||||
}
|
||||
|
||||
ignore_value(virNetDevSetNetConfig(linkdev, vf,
|
||||
|
@ -682,9 +682,8 @@ xenParseVfb(virConf *conf, virDomainDef *def)
|
||||
if (xenConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0)
|
||||
goto cleanup;
|
||||
def->graphics = g_new0(virDomainGraphicsDef *, 1);
|
||||
def->graphics[0] = graphics;
|
||||
def->graphics[0] = g_steal_pointer(&graphics);
|
||||
def->ngraphics = 1;
|
||||
graphics = NULL;
|
||||
} else {
|
||||
if (xenConfigGetBool(conf, "sdl", &val, 0) < 0)
|
||||
goto cleanup;
|
||||
@ -696,9 +695,8 @@ xenParseVfb(virConf *conf, virDomainDef *def)
|
||||
if (xenConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0)
|
||||
goto cleanup;
|
||||
def->graphics = g_new0(virDomainGraphicsDef *, 1);
|
||||
def->graphics[0] = graphics;
|
||||
def->graphics[0] = g_steal_pointer(&graphics);
|
||||
def->ngraphics = 1;
|
||||
graphics = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -774,9 +772,8 @@ xenParseVfb(virConf *conf, virDomainDef *def)
|
||||
VIR_FREE(listenAddr);
|
||||
}
|
||||
def->graphics = g_new0(virDomainGraphicsDef *, 1);
|
||||
def->graphics[0] = graphics;
|
||||
def->graphics[0] = g_steal_pointer(&graphics);
|
||||
def->ngraphics = 1;
|
||||
graphics = NULL;
|
||||
} else {
|
||||
if (xenHandleConfGetValueStringListErrors(rc) < 0)
|
||||
goto cleanup;
|
||||
@ -953,9 +950,8 @@ xenParseCharDev(virConf *conf, virDomainDef *def, const char *nativeFormat)
|
||||
|
||||
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
|
||||
chr->target.port = 0;
|
||||
def->parallels[0] = chr;
|
||||
def->parallels[0] = g_steal_pointer(&chr);
|
||||
def->nparallels++;
|
||||
chr = NULL;
|
||||
}
|
||||
|
||||
/* Try to get the list of values to support multiple serial ports */
|
||||
|
@ -4297,8 +4297,7 @@ qemuDomainChangeGraphics(virQEMUDriver *driver,
|
||||
|
||||
/* Steal the new dev's char * reference */
|
||||
VIR_FREE(olddev->data.vnc.auth.passwd);
|
||||
olddev->data.vnc.auth.passwd = dev->data.vnc.auth.passwd;
|
||||
dev->data.vnc.auth.passwd = NULL;
|
||||
olddev->data.vnc.auth.passwd = g_steal_pointer(&dev->data.vnc.auth.passwd);
|
||||
olddev->data.vnc.auth.validTo = dev->data.vnc.auth.validTo;
|
||||
olddev->data.vnc.auth.expires = dev->data.vnc.auth.expires;
|
||||
olddev->data.vnc.auth.connected = dev->data.vnc.auth.connected;
|
||||
@ -4345,8 +4344,7 @@ qemuDomainChangeGraphics(virQEMUDriver *driver,
|
||||
|
||||
/* Steal the new dev's char * reference */
|
||||
VIR_FREE(olddev->data.spice.auth.passwd);
|
||||
olddev->data.spice.auth.passwd = dev->data.spice.auth.passwd;
|
||||
dev->data.spice.auth.passwd = NULL;
|
||||
olddev->data.spice.auth.passwd = g_steal_pointer(&dev->data.spice.auth.passwd);
|
||||
olddev->data.spice.auth.validTo = dev->data.spice.auth.validTo;
|
||||
olddev->data.spice.auth.expires = dev->data.spice.auth.expires;
|
||||
olddev->data.spice.auth.connected = dev->data.spice.auth.connected;
|
||||
|
@ -3029,8 +3029,7 @@ qemuMigrationDstPrepareAny(virQEMUDriver *driver,
|
||||
if (mig->lockState) {
|
||||
VIR_DEBUG("Received lockstate %s", mig->lockState);
|
||||
VIR_FREE(priv->lockState);
|
||||
priv->lockState = mig->lockState;
|
||||
mig->lockState = NULL;
|
||||
priv->lockState = g_steal_pointer(&mig->lockState);
|
||||
} else {
|
||||
VIR_DEBUG("Received no lockstate");
|
||||
}
|
||||
@ -5598,8 +5597,7 @@ qemuMigrationDstPersist(virQEMUDriver *driver,
|
||||
error:
|
||||
virDomainDefFree(vm->newDef);
|
||||
vm->persistent = oldPersist;
|
||||
vm->newDef = oldDef;
|
||||
oldDef = NULL;
|
||||
vm->newDef = g_steal_pointer(&oldDef);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -5778,8 +5776,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
|
||||
}
|
||||
|
||||
if (mig->jobInfo) {
|
||||
jobInfo = mig->jobInfo;
|
||||
mig->jobInfo = NULL;
|
||||
jobInfo = g_steal_pointer(&mig->jobInfo);
|
||||
|
||||
if (jobInfo->sent && timeReceived) {
|
||||
jobInfo->timeDelta = timeReceived - jobInfo->sent;
|
||||
|
@ -290,13 +290,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterState *state,
|
||||
if (meta->capacity)
|
||||
vol->target.capacity = meta->capacity;
|
||||
if (meta->encryption) {
|
||||
vol->target.encryption = meta->encryption;
|
||||
meta->encryption = NULL;
|
||||
vol->target.encryption = g_steal_pointer(&meta->encryption);
|
||||
}
|
||||
vol->target.features = meta->features;
|
||||
meta->features = NULL;
|
||||
vol->target.compat = meta->compat;
|
||||
meta->compat = NULL;
|
||||
vol->target.features = g_steal_pointer(&meta->features);
|
||||
vol->target.compat = g_steal_pointer(&meta->compat);
|
||||
|
||||
*volptr = g_steal_pointer(&vol);
|
||||
ret = 0;
|
||||
|
@ -3443,8 +3443,7 @@ storageBackendProbeTarget(virStorageSource *target,
|
||||
|
||||
target->backingStore = virStorageSourceNew();
|
||||
target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
|
||||
target->backingStore->path = meta->backingStoreRaw;
|
||||
meta->backingStoreRaw = NULL;
|
||||
target->backingStore->path = g_steal_pointer(&meta->backingStoreRaw);
|
||||
target->backingStore->format = VIR_STORAGE_FILE_RAW;
|
||||
}
|
||||
|
||||
@ -3479,8 +3478,7 @@ storageBackendProbeTarget(virStorageSource *target,
|
||||
if (meta->encryption->payload_offset != -1)
|
||||
target->capacity -= meta->encryption->payload_offset * 512;
|
||||
|
||||
*encryption = meta->encryption;
|
||||
meta->encryption = NULL;
|
||||
*encryption = g_steal_pointer(&meta->encryption);
|
||||
|
||||
/* XXX ideally we'd fill in secret UUID here
|
||||
* but we cannot guarantee 'conn' is non-NULL
|
||||
|
@ -967,8 +967,7 @@ int virFileNBDDeviceAssociate(const char *file,
|
||||
|
||||
VIR_DEBUG("Associated NBD device %s with file %s and format %s",
|
||||
nbddev, file, fmtstr);
|
||||
*dev = nbddev;
|
||||
nbddev = NULL;
|
||||
*dev = g_steal_pointer(&nbddev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -254,7 +254,6 @@ virLeaseNew(virJSONValue **lease_ret,
|
||||
if (virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0)
|
||||
return -1;
|
||||
|
||||
*lease_ret = lease_new;
|
||||
lease_new = NULL;
|
||||
*lease_ret = g_steal_pointer(&lease_new);
|
||||
return 0;
|
||||
}
|
||||
|
@ -839,16 +839,13 @@ virNumaGetPages(int node,
|
||||
} while (exchange);
|
||||
|
||||
if (pages_size) {
|
||||
*pages_size = tmp_size;
|
||||
tmp_size = NULL;
|
||||
*pages_size = g_steal_pointer(&tmp_size);
|
||||
}
|
||||
if (pages_avail) {
|
||||
*pages_avail = tmp_avail;
|
||||
tmp_avail = NULL;
|
||||
*pages_avail = g_steal_pointer(&tmp_avail);
|
||||
}
|
||||
if (pages_free) {
|
||||
*pages_free = tmp_free;
|
||||
tmp_free = NULL;
|
||||
*pages_free = g_steal_pointer(&tmp_free);
|
||||
}
|
||||
*npages = ntmp;
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user