lib: Use g_clear_pointer() more

This change was generated using the following spatch:

  @ rule1 @
  expression a;
  identifier f;
  @@
    <...
  - f(*a);
    ... when != a;
  - *a = NULL;
  + g_clear_pointer(a, f);
    ...>

  @ rule2 @
  expression a;
  identifier f;
  @@
    <...
  - f(a);
    ... when != a;
  - a = NULL;
  + g_clear_pointer(&a, f);
    ...>

Then, I left some of the changes out, like tools/nss/ (which
doesn't link with glib) and put back a comment in
qemuBlockJobProcessEventCompletedActiveCommit() which coccinelle
decided to remove (I have no idea why).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-28 18:42:45 +01:00
parent 1688d2527f
commit 87a43a907f
100 changed files with 252 additions and 501 deletions

View File

@ -871,8 +871,7 @@ static int chStateCleanup(void)
virObjectUnref(ch_driver->caps);
virObjectUnref(ch_driver->config);
virMutexDestroy(&ch_driver->lock);
g_free(ch_driver);
ch_driver = NULL;
g_clear_pointer(&ch_driver, g_free);
return 0;
}
@ -1401,8 +1400,7 @@ chDomainPinEmulator(virDomainPtr dom,
if (virProcessSetAffinity(vm->pid, pcpumap, false) < 0)
goto endjob;
virBitmapFree(def->cputune.emulatorpin);
def->cputune.emulatorpin = NULL;
g_clear_pointer(&def->cputune.emulatorpin, virBitmapFree);
if (!(def->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
goto endjob;

View File

@ -553,8 +553,7 @@ virCHProcessStop(virCHDriver *driver G_GNUC_UNUSED,
vm->def->name, (int)vm->pid, (int)reason);
if (priv->monitor) {
virCHMonitorClose(priv->monitor);
priv->monitor = NULL;
g_clear_pointer(&priv->monitor, virCHMonitorClose);
}
retry:

View File

@ -417,8 +417,7 @@ virCapabilitiesFreeMachines(virCapsGuestMachine **machines,
if (!machines)
return;
for (i = 0; i < nmachines && machines[i]; i++) {
virCapabilitiesFreeGuestMachine(machines[i]);
machines[i] = NULL;
g_clear_pointer(&machines[i], virCapabilitiesFreeGuestMachine);
}
g_free(machines);
}
@ -2132,8 +2131,7 @@ virCapabilitiesInitResctrlMemory(virCaps *caps)
VIR_APPEND_ELEMENT(caps->host.memBW.nodes, caps->host.memBW.nnodes, node);
}
virCapsHostMemBWNodeFree(node);
node = NULL;
g_clear_pointer(&node, virCapsHostMemBWNodeFree);
}
if (virResctrlInfoGetMonitorPrefix(caps->host.resctrl, prefix,
@ -2252,8 +2250,7 @@ virCapabilitiesInitCaches(virCaps *caps)
VIR_APPEND_ELEMENT(caps->host.cache.banks, caps->host.cache.nbanks, bank);
}
virCapsHostCacheBankFree(bank);
bank = NULL;
g_clear_pointer(&bank, virCapsHostCacheBankFree);
}
if (rv < 0)
goto cleanup;

View File

@ -3168,12 +3168,10 @@ static void
virDomainHostdevSubsysSCSIClear(virDomainHostdevSubsysSCSI *scsisrc)
{
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
virObjectUnref(scsisrc->u.iscsi.src);
scsisrc->u.iscsi.src = NULL;
g_clear_pointer(&scsisrc->u.iscsi.src, virObjectUnref);
} else {
VIR_FREE(scsisrc->u.host.adapter);
virObjectUnref(scsisrc->u.host.src);
scsisrc->u.host.src = NULL;
g_clear_pointer(&scsisrc->u.host.src, virObjectUnref);
}
}
@ -3938,8 +3936,7 @@ virDomainObjEndAPI(virDomainObj **vm)
return;
virObjectUnlock(*vm);
virObjectUnref(*vm);
*vm = NULL;
g_clear_pointer(vm, virObjectUnref);
}
@ -4842,8 +4839,8 @@ virDomainDefPostParseMemtune(virDomainDef *def)
nextBit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, 0);
if (nextBit < 0) {
virBitmapFree(def->mem.hugepages[i].nodemask);
def->mem.hugepages[i].nodemask = NULL;
g_clear_pointer(&def->mem.hugepages[i].nodemask,
virBitmapFree);
}
}
}
@ -4907,8 +4904,7 @@ virDomainDefAddConsoleCompat(virDomainDef *def)
/* if the console source doesn't match */
if (!virDomainChrSourceDefIsEqual(def->serials[0]->source,
def->consoles[0]->source)) {
virDomainChrDefFree(def->consoles[0]);
def->consoles[0] = NULL;
g_clear_pointer(&def->consoles[0], virDomainChrDefFree);
}
}
@ -5737,8 +5733,7 @@ virDomainDefRemoveOfflineVcpuPin(virDomainDef *def)
vcpu = virDomainDefGetVcpu(def, i);
if (vcpu && !vcpu->online && vcpu->cpumask) {
virBitmapFree(vcpu->cpumask);
vcpu->cpumask = NULL;
g_clear_pointer(&vcpu->cpumask, virBitmapFree);
VIR_WARN("Ignoring unsupported vcpupin for offline vcpu '%zu'", i);
}
@ -10887,8 +10882,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
return def;
error:
virDomainNetDefFree(def);
def = NULL;
g_clear_pointer(&def, virDomainNetDefFree);
goto cleanup;
}
@ -11398,8 +11392,7 @@ virDomainChrSourceDefNew(virDomainXMLOption *xmlopt)
if (xmlopt && xmlopt->privateData.chrSourceNew &&
!(def->privateData = xmlopt->privateData.chrSourceNew())) {
virObjectUnref(def);
def = NULL;
g_clear_pointer(&def, virObjectUnref);
}
return def;
@ -12773,8 +12766,7 @@ virDomainNetDefNew(virDomainXMLOption *xmlopt)
if (xmlopt && xmlopt->privateData.networkNew &&
!(def->privateData = xmlopt->privateData.networkNew())) {
virDomainNetDefFree(def);
def = NULL;
g_clear_pointer(&def, virDomainNetDefFree);
}
return def;
@ -12828,8 +12820,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOption *xmlopt,
return def;
error:
virDomainGraphicsDefFree(def);
def = NULL;
g_clear_pointer(&def, virDomainGraphicsDefFree);
return NULL;
}
@ -13395,8 +13386,7 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
return def;
error:
virDomainRNGDefFree(def);
def = NULL;
g_clear_pointer(&def, virDomainRNGDefFree);
return NULL;
}
@ -13601,8 +13591,7 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
if (!def->vendor && !def->version &&
!def->date && !def->release) {
virSysinfoBIOSDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoBIOSDefFree);
}
*bios = g_steal_pointer(&def);
@ -13675,8 +13664,7 @@ virSysinfoSystemParseXML(xmlNodePtr node,
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
virSysinfoSystemDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
*sysdef = g_steal_pointer(&def);
@ -13806,8 +13794,7 @@ virSysinfoChassisParseXML(xmlNodePtr node,
if (!def->manufacturer && !def->version &&
!def->serial && !def->asset && !def->sku) {
virSysinfoChassisDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoChassisDefFree);
}
*chassisdef = g_steal_pointer(&def);
@ -30588,8 +30575,7 @@ virDomainNetCreatePort(virConnectPtr conn,
return -1;
/* prepare to re-use portdef */
virNetworkPortDefFree(portdef);
portdef = NULL;
g_clear_pointer(&portdef, virNetworkPortDefFree);
if (!(port = virNetworkPortCreateXML(net, portxml, flags)))
return -1;
@ -30992,8 +30978,7 @@ virDomainStorageSourceTranslateSourcePool(virStorageSource *src,
virStorageNetHostDefFree(src->nhosts, src->hosts);
src->nhosts = 0;
src->hosts = NULL;
virStorageAuthDefFree(src->auth);
src->auth = NULL;
g_clear_pointer(&src->auth, virStorageAuthDefFree);
switch ((virStoragePoolType) pooldef->type) {
case VIR_STORAGE_POOL_DIR:

View File

@ -118,9 +118,8 @@ virPortGroupDefClear(virPortGroupDef *def)
{
VIR_FREE(def->name);
VIR_FREE(def->virtPortProfile);
virNetDevBandwidthFree(def->bandwidth);
g_clear_pointer(&def->bandwidth, virNetDevBandwidthFree);
virNetDevVlanClear(&def->vlan);
def->bandwidth = NULL;
}

View File

@ -554,8 +554,7 @@ virDomainNumatuneSet(virDomainNuma *numa,
/* setting nodeset when placement auto is invalid */
if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO &&
numa->memory.nodeset) {
virBitmapFree(numa->memory.nodeset);
numa->memory.nodeset = NULL;
g_clear_pointer(&numa->memory.nodeset, virBitmapFree);
}
if (placement != -1)

View File

@ -2514,8 +2514,7 @@ virNWFilterRuleParse(xmlNodePtr node)
return ret;
err_exit:
virNWFilterRuleDefFree(ret);
ret = NULL;
g_clear_pointer(&ret, virNWFilterRuleDefFree);
goto cleanup;
}

View File

@ -94,8 +94,7 @@ static void
virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDef *disk)
{
VIR_FREE(disk->name);
virObjectUnref(disk->src);
disk->src = NULL;
g_clear_pointer(&disk->src, virObjectUnref);
}
void

View File

@ -1097,8 +1097,7 @@ virStorageSourceBackingStoreClear(virStorageSource *def)
VIR_FREE(def->backingStoreRaw);
/* recursively free backing chain */
virObjectUnref(def->backingStore);
def->backingStore = NULL;
g_clear_pointer(&def->backingStore, virObjectUnref);
}

View File

@ -103,8 +103,7 @@ virInterfaceObjEndAPI(virInterfaceObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}

View File

@ -131,8 +131,7 @@ virNetworkObjEndAPI(virNetworkObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}
@ -250,8 +249,7 @@ virNetworkObjSetMacMap(virNetworkObj *obj,
void
virNetworkObjUnrefMacMap(virNetworkObj *obj)
{
virObjectUnref(obj->macmap);
obj->macmap = NULL;
g_clear_pointer(&obj->macmap, virObjectUnref);
}

View File

@ -108,8 +108,7 @@ virNodeDeviceObjEndAPI(virNodeDeviceObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}

View File

@ -134,8 +134,7 @@ virNWFilterBindingObjEndAPI(virNWFilterBindingObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}

View File

@ -103,8 +103,7 @@ virSecretObjEndAPI(virSecretObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}
@ -882,8 +881,7 @@ virSecretLoad(virSecretObjList *secrets,
if (virSecretLoadValue(obj) < 0) {
virSecretObjListRemove(secrets, obj);
virObjectUnref(obj);
obj = NULL;
g_clear_pointer(&obj, virObjectUnref);
}
cleanup:

View File

@ -145,8 +145,7 @@ virStorageVolObjEndAPI(virStorageVolObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}
@ -233,8 +232,7 @@ virStoragePoolObjEndAPI(virStoragePoolObj **obj)
return;
virObjectUnlock(*obj);
virObjectUnref(*obj);
*obj = NULL;
g_clear_pointer(obj, virObjectUnref);
}

View File

@ -187,8 +187,7 @@ virConnectCloseCallbackDataReset(virConnectCloseCallbackData *closeData)
closeData->freeCallback = NULL;
closeData->opaque = NULL;
virObjectUnref(closeData->conn);
closeData->conn = NULL;
g_clear_pointer(&closeData->conn, virObjectUnref);
}
/**
@ -1141,8 +1140,7 @@ virAdmConnectCloseCallbackDataReset(virAdmConnectCloseCallbackData *cbdata)
if (cbdata->freeCallback)
cbdata->freeCallback(cbdata->opaque);
virObjectUnref(cbdata->conn);
cbdata->conn = NULL;
g_clear_pointer(&cbdata->conn, virObjectUnref);
cbdata->freeCallback = NULL;
cbdata->callback = NULL;
cbdata->opaque = NULL;

View File

@ -925,8 +925,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQuery *wqlQuery,
enumContext = wsmc_get_enum_context(response);
ws_xml_destroy_doc(response);
response = NULL;
g_clear_pointer(&response, ws_xml_destroy_doc);
while (enumContext != NULL && *enumContext != '\0') {
XML_TYPE_PTR data = NULL;
@ -990,8 +989,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQuery *wqlQuery,
VIR_FREE(enumContext);
enumContext = wsmc_get_enum_context(response);
ws_xml_destroy_doc(response);
response = NULL;
g_clear_pointer(&response, ws_xml_destroy_doc);
}
*list = g_steal_pointer(&head);

View File

@ -136,8 +136,7 @@ netcfStateInitialize(bool privileged,
return VIR_DRV_STATE_INIT_COMPLETE;
error:
virObjectUnref(driver);
driver = NULL;
g_clear_pointer(&driver, virObjectUnref);
return VIR_DRV_STATE_INIT_ERROR;
}
@ -148,8 +147,7 @@ netcfStateCleanup(void)
if (!driver)
return -1;
virObjectUnref(driver);
driver = NULL;
g_clear_pointer(&driver, virObjectUnref);
return 0;
}
@ -685,8 +683,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
goto cleanup;
if (!virConnectListAllInterfacesCheckACL(conn, def)) {
ncf_if_free(iface);
iface = NULL;
g_clear_pointer(&iface, ncf_if_free);
continue;
}
@ -698,8 +695,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
}
niface_objs++;
ncf_if_free(iface);
iface = NULL;
g_clear_pointer(&iface, ncf_if_free);
}
if (tmp_iface_objs) {

View File

@ -3205,8 +3205,7 @@ virDomainMigrateVersion3Full(virDomainPtr domain,
if (err &&
err->domain == VIR_FROM_QEMU &&
err->code != VIR_ERR_MIGRATE_FINISH_OK) {
virFreeError(orig_err);
orig_err = NULL;
g_clear_pointer(&orig_err, virFreeError);
}
}
}

View File

@ -305,8 +305,7 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps)
for (i = 0; cpus && i < nr_nodes; i++)
VIR_FREE(cpus[i]);
if (caps->host.numa) {
virCapabilitiesHostNUMAUnref(caps->host.numa);
caps->host.numa = NULL;
g_clear_pointer(&caps->host.numa, virCapabilitiesHostNUMAUnref);
}
VIR_FREE(distances);
}

View File

@ -262,8 +262,7 @@ libxlDoMigrateDstReceive(void *opaque)
for (i = 0; i < nsocks; i++) {
virNetSocketRemoveIOCallback(socks[i]);
virNetSocketClose(socks[i]);
virObjectUnref(socks[i]);
socks[i] = NULL;
g_clear_pointer(&socks[i], virObjectUnref);
}
args->nsocks = 0;
VIR_FORCE_CLOSE(recvfd);
@ -323,8 +322,7 @@ libxlMigrateDstReceive(virNetSocket *sock,
for (i = 0; i < nsocks; i++) {
virNetSocketUpdateIOCallback(socks[i], 0);
virNetSocketRemoveIOCallback(socks[i]);
virNetSocketClose(socks[i]);
socks[i] = NULL;
g_clear_pointer(&socks[i], virNetSocketClose);
}
args->nsocks = 0;
VIR_FORCE_CLOSE(recvfd);

View File

@ -136,8 +136,7 @@ virLockDaemonNew(virLockDaemonConfig *config, bool privileged)
if (virNetDaemonAddServer(lockd->dmn, srv) < 0)
goto error;
virObjectUnref(srv);
srv = NULL;
g_clear_pointer(&srv, virObjectUnref);
if (!(srv = virNetServerNew("admin", 1,
0, 0, 0, config->admin_max_clients,
@ -150,8 +149,7 @@ virLockDaemonNew(virLockDaemonConfig *config, bool privileged)
if (virNetDaemonAddServer(lockd->dmn, srv) < 0)
goto error;
virObjectUnref(srv);
srv = NULL;
g_clear_pointer(&srv, virObjectUnref);
lockd->lockspaces = virHashNew(virLockDaemonLockSpaceDataFree);

View File

@ -372,8 +372,7 @@ static void virLockManagerLockDaemonFree(virLockManager *lock)
if (!lock)
return;
virLockManagerLockDaemonPrivateFree(lock->privateData);
lock->privateData = NULL;
g_clear_pointer(&lock->privateData, virLockManagerLockDaemonPrivateFree);
}

View File

@ -134,8 +134,7 @@ virLogDaemonNew(virLogDaemonConfig *config, bool privileged)
if (virNetDaemonAddServer(logd->dmn, srv) < 0)
goto error;
virObjectUnref(srv);
srv = NULL;
g_clear_pointer(&srv, virObjectUnref);
if (!(srv = virNetServerNew("admin", 1,
0, 0, 0, config->admin_max_clients,
@ -148,8 +147,7 @@ virLogDaemonNew(virLogDaemonConfig *config, bool privileged)
if (virNetDaemonAddServer(logd->dmn, srv) < 0)
goto error;
virObjectUnref(srv);
srv = NULL;
g_clear_pointer(&srv, virObjectUnref);
if (!(logd->handler = virLogHandlerNew(privileged,
config->max_size,

View File

@ -220,8 +220,7 @@ static virLXCController *virLXCControllerNew(const char *name)
return ctrl;
error:
virLXCControllerFree(ctrl);
ctrl = NULL;
g_clear_pointer(&ctrl, virLXCControllerFree);
goto cleanup;
}
@ -951,8 +950,7 @@ static int virLXCControllerSetupServer(virLXCController *ctrl)
if (virNetServerAddService(srv, svc) < 0)
goto error;
virObjectUnref(svc);
svc = NULL;
g_clear_pointer(&svc, virObjectUnref);
if (!(ctrl->prog = virNetServerProgramNew(VIR_LXC_MONITOR_PROGRAM,
VIR_LXC_MONITOR_PROGRAM_VERSION,
@ -969,8 +967,7 @@ static int virLXCControllerSetupServer(virLXCController *ctrl)
error:
virObjectUnref(srv);
virObjectUnref(ctrl->daemon);
ctrl->daemon = NULL;
g_clear_pointer(&ctrl->daemon, virObjectUnref);
virObjectUnref(svc);
return -1;
}
@ -2067,8 +2064,7 @@ lxcCreateTty(virLXCController *ctrl, int *ttyprimary,
cleanup:
if (ret != 0) {
VIR_FORCE_CLOSE(*ttyprimary);
g_free(*ttyName);
*ttyName = NULL;
g_clear_pointer(ttyName, g_free);
}
return ret;

View File

@ -490,9 +490,7 @@ virLXCDomainSetRunlevel(virDomainObj *vm,
lxcDomainInitctlCallback,
&data);
cleanup:
g_free(data.st);
data.st = NULL;
g_free(data.st_valid);
data.st_valid = NULL;
g_clear_pointer(&data.st, g_free);
g_clear_pointer(&data.st_valid, g_free);
return ret;
}

View File

@ -1472,8 +1472,7 @@ static int lxcStateInitialize(bool privileged,
lxc_driver = g_new0(virLXCDriver, 1);
lxc_driver->lockFD = -1;
if (virMutexInit(&lxc_driver->lock) < 0) {
g_free(lxc_driver);
lxc_driver = NULL;
g_clear_pointer(&lxc_driver, g_free);
return VIR_DRV_STATE_INIT_ERROR;
}
@ -1611,8 +1610,7 @@ static int lxcStateCleanup(void)
virObjectUnref(lxc_driver->config);
virMutexDestroy(&lxc_driver->lock);
g_free(lxc_driver);
lxc_driver = NULL;
g_clear_pointer(&lxc_driver, g_free);
return 0;
}

View File

@ -262,8 +262,7 @@ static void lxcFuseDestroy(struct virLXCFuse *fuse)
{
virMutexLock(&fuse->lock);
fuse_unmount(fuse->mountpoint, fuse->ch);
fuse_destroy(fuse->fuse);
fuse->fuse = NULL;
g_clear_pointer(&fuse->fuse, fuse_destroy);
virMutexUnlock(&fuse->lock);
}

View File

@ -518,8 +518,7 @@ lxcAddNetworkDefinition(virDomainDef *def, lxcNetworkParseData *data)
error:
for (i = 0; i < data->nips; i++)
g_free(data->ips[i]);
g_free(data->ips);
data->ips = NULL;
g_clear_pointer(&data->ips, g_free);
virDomainNetDefFree(net);
virDomainHostdevDefFree(hostdev);
return -1;
@ -743,8 +742,7 @@ lxcConvertNetworkSettings(virDomainDef *def, virConf *properties)
cleanup:
for (i = 0; i < networks.ndata; i++)
g_free(networks.parseData[i]);
g_free(networks.parseData);
networks.parseData = NULL;
g_clear_pointer(&networks.parseData, g_free);
return ret;
error:
@ -752,8 +750,7 @@ lxcConvertNetworkSettings(virDomainDef *def, virConf *properties)
lxcNetworkParseData *data = networks.parseData[i];
for (j = 0; j < data->nips; j++)
g_free(data->ips[j]);
g_free(data->ips);
data->ips = NULL;
g_clear_pointer(&data->ips, g_free);
}
goto cleanup;
}
@ -854,8 +851,7 @@ lxcSetMemTune(virDomainDef *def, virConf *properties)
size = size / 1024;
virDomainDefSetMemoryTotal(def, size);
def->mem.hard_limit = virMemoryLimitTruncate(size);
g_free(value);
value = NULL;
g_clear_pointer(&value, g_free);
}
if (virConfGetValueString(properties,
@ -864,8 +860,7 @@ lxcSetMemTune(virDomainDef *def, virConf *properties)
if (lxcConvertSize(value, &size) < 0)
return -1;
def->mem.soft_limit = virMemoryLimitTruncate(size / 1024);
g_free(value);
value = NULL;
g_clear_pointer(&value, g_free);
}
if (virConfGetValueString(properties,
@ -888,16 +883,14 @@ lxcSetCpuTune(virDomainDef *def, virConf *properties)
if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0)
goto error;
def->cputune.sharesSpecified = true;
g_free(value);
value = NULL;
g_clear_pointer(&value, g_free);
}
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us",
&value) > 0) {
if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0)
goto error;
g_free(value);
value = NULL;
g_clear_pointer(&value, g_free);
}
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us",
@ -1111,8 +1104,7 @@ lxcParseConfigString(const char *config,
else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64"))
arch = VIR_ARCH_X86_64;
vmdef->os.arch = arch;
g_free(value);
value = NULL;
g_clear_pointer(&value, g_free);
}
vmdef->os.init = g_strdup("/sbin/init");

View File

@ -201,12 +201,9 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
/* Clear out dynamically assigned labels */
if (vm->def->nseclabels &&
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) {
g_free(vm->def->seclabels[0]->model);
g_free(vm->def->seclabels[0]->label);
g_free(vm->def->seclabels[0]->imagelabel);
vm->def->seclabels[0]->model = NULL;
vm->def->seclabels[0]->label = NULL;
vm->def->seclabels[0]->imagelabel = NULL;
g_clear_pointer(&vm->def->seclabels[0]->model, g_free);
g_clear_pointer(&vm->def->seclabels[0]->label, g_free);
g_clear_pointer(&vm->def->seclabels[0]->imagelabel, g_free);
}
/* Stop autodestroy in case guest is restarted */
@ -215,8 +212,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
if (priv->monitor) {
virLXCMonitorClose(priv->monitor);
virObjectUnref(priv->monitor);
priv->monitor = NULL;
g_clear_pointer(&priv->monitor, virObjectUnref);
}
virPidFileDelete(cfg->stateDir, vm->def->name);
@ -254,8 +250,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
if (priv->cgroup) {
virCgroupRemove(priv->cgroup);
virCgroupFree(priv->cgroup);
priv->cgroup = NULL;
g_clear_pointer(&priv->cgroup, virCgroupFree);
}
/* Get machined to terminate the machine as it may not have cleaned it
@ -263,8 +258,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
* the bug we are working around here.
*/
virCgroupTerminateMachine(priv->machineName);
g_free(priv->machineName);
priv->machineName = NULL;
g_clear_pointer(&priv->machineName, g_free);
/* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
@ -680,8 +674,7 @@ virLXCProcessCleanInterfaces(virDomainDef *def)
size_t i;
for (i = 0; i < def->nnets; i++) {
g_free(def->nets[i]->ifname_guest_actual);
def->nets[i]->ifname_guest_actual = NULL;
g_clear_pointer(&def->nets[i]->ifname_guest_actual, g_free);
VIR_DEBUG("Cleared net names: %s", def->nets[i]->ifname_guest);
}
}

View File

@ -50,10 +50,8 @@ static void networkSetupPrivateChains(void)
VIR_DEBUG("Setting up global firewall chains");
virFreeError(errInitV4);
errInitV4 = NULL;
virFreeError(errInitV6);
errInitV6 = NULL;
g_clear_pointer(&errInitV4, virFreeError);
g_clear_pointer(&errInitV6, virFreeError);
rc = iptablesSetupPrivateChains(VIR_FIREWALL_LAYER_IPV4);
if (rc < 0) {

View File

@ -1409,8 +1409,7 @@ virNWFilterDHCPSnoopThread(void *req0)
}
if (++errcount > PCAP_READ_MAXERRS) {
pcap_close(pcapConf[i].handle);
pcapConf[i].handle = NULL;
g_clear_pointer(&pcapConf[i].handle, pcap_close);
/* protect req->binding->portdevname */
virNWFilterSnoopReqLock(req);
@ -1542,8 +1541,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriver *techdriver,
virNWFilterSnoopReqPut(req);
return 0;
}
virNWFilterBindingDefFree(req->binding);
req->binding = NULL;
g_clear_pointer(&req->binding, virNWFilterBindingDefFree);
} else {
req = virNWFilterSnoopReqNew(ifkey);
if (!req)

View File

@ -762,8 +762,7 @@ nwfilterBindingCreateXML(virConnectPtr conn,
if (virNWFilterInstantiateFilter(driver, def) < 0) {
virNWFilterBindingObjListRemove(driver->bindings, obj);
virObjectUnref(ret);
ret = NULL;
g_clear_pointer(&ret, virObjectUnref);
goto cleanup;
}
virNWFilterBindingObjSave(obj, driver->bindingDir);

View File

@ -452,9 +452,8 @@ static void
qemuAgentUnregister(qemuAgent *agent)
{
if (agent->watch) {
g_source_destroy(agent->watch);
vir_g_source_unref(agent->watch, agent->context);
agent->watch = NULL;
g_clear_pointer(&agent->watch, g_source_destroy);
}
}
@ -697,8 +696,7 @@ void qemuAgentClose(qemuAgent *agent)
if (agent->socket) {
qemuAgentUnregister(agent);
g_object_unref(agent->socket);
agent->socket = NULL;
g_clear_pointer(&agent->socket, g_object_unref);
agent->fd = -1;
}

View File

@ -616,8 +616,7 @@ qemuBackupJobTerminate(virDomainObj *vm,
qemuDomainEventEmitJobCompleted(priv->driver, vm);
}
virDomainBackupDefFree(priv->backup);
priv->backup = NULL;
g_clear_pointer(&priv->backup, virDomainBackupDefFree);
if (priv->job.asyncJob == QEMU_ASYNC_JOB_BACKUP)
qemuDomainObjEndAsyncJob(priv->driver, vm);

View File

@ -209,8 +209,7 @@ qemuBlockJobUnregister(qemuBlockJobData *job,
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(job->disk);
if (job == diskPriv->blockjob) {
virObjectUnref(diskPriv->blockjob);
diskPriv->blockjob = NULL;
g_clear_pointer(&diskPriv->blockjob, virObjectUnref);
}
job->disk = NULL;
@ -698,8 +697,7 @@ qemuBlockJobRewriteConfigDiskSource(virDomainObj *vm,
/* discard any detected backing store */
if (virStorageSourceIsBacking(n->backingStore) &&
n->backingStore->detected) {
virObjectUnref(n->backingStore);
n->backingStore = NULL;
g_clear_pointer(&n->backingStore, virObjectUnref);
break;
}
}
@ -827,8 +825,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriver *driver,
* Remove security driver metadata so that they are not leaked. */
qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
virObjectUnref(disk->mirror);
disk->mirror = NULL;
g_clear_pointer(&disk->mirror, virObjectUnref);
}
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
@ -940,8 +937,7 @@ qemuBlockJobClearConfigChain(virDomainObj *vm,
if (!virStorageSourceIsSameLocation(disk->src, cfgdisk->src))
return;
virObjectUnref(cfgdisk->src->backingStore);
cfgdisk->src->backingStore = NULL;
g_clear_pointer(&cfgdisk->src->backingStore, virObjectUnref);
}
@ -1232,8 +1228,7 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriver *driver,
if (job->data.commit.deleteCommittedImages)
qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
virObjectUnref(job->data.commit.top);
job->data.commit.top = NULL;
g_clear_pointer(&job->data.commit.top, virObjectUnref);
if (cfgbaseparent) {
cfgbase = g_steal_pointer(&cfgbaseparent->backingStore);
@ -1327,11 +1322,9 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriver *driver,
if (job->data.commit.deleteCommittedImages)
qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
virObjectUnref(job->data.commit.top);
job->data.commit.top = NULL;
g_clear_pointer(&job->data.commit.top, virObjectUnref);
/* the mirror element does not serve functional purpose for the commit job */
virObjectUnref(job->disk->mirror);
job->disk->mirror = NULL;
g_clear_pointer(&job->disk->mirror, virObjectUnref);
}
@ -1422,8 +1415,7 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDriver *driver,
/* activeWrite bitmap is removed automatically here */
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->mirror);
virObjectUnref(job->disk->mirror);
job->disk->mirror = NULL;
g_clear_pointer(&job->disk->mirror, virObjectUnref);
}
@ -1455,8 +1447,7 @@ qemuBlockJobProcessEventFailedActiveCommit(virQEMUDriver *driver,
* not leaking security driver metadata is more important. */
qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
virObjectUnref(disk->mirror);
disk->mirror = NULL;
g_clear_pointer(&disk->mirror, virObjectUnref);
}
@ -1472,8 +1463,7 @@ qemuBlockJobProcessEventConcludedCreate(virQEMUDriver *driver,
* it will handle further hotplug of the created volume and also that
* the 'chain' which was registered is under their control */
if (job->synchronous) {
virObjectUnref(job->chain);
job->chain = NULL;
g_clear_pointer(&job->chain, virObjectUnref);
return;
}

View File

@ -124,8 +124,7 @@ qemuJobResetPrivate(void *opaque)
priv->spiceMigration = false;
priv->spiceMigrated = false;
priv->dumpCompleted = false;
qemuMigrationParamsFree(priv->migParams);
priv->migParams = NULL;
g_clear_pointer(&priv->migParams, qemuMigrationParamsFree);
}
@ -1618,19 +1617,13 @@ qemuDomainObjStopWorker(virDomainObj *dom)
void
qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv)
{
g_strfreev(priv->qemuDevices);
priv->qemuDevices = NULL;
virCgroupFree(priv->cgroup);
priv->cgroup = NULL;
virPerfFree(priv->perf);
priv->perf = NULL;
g_clear_pointer(&priv->qemuDevices, g_strfreev);
g_clear_pointer(&priv->cgroup, virCgroupFree);
g_clear_pointer(&priv->perf, virPerfFree);
VIR_FREE(priv->machineName);
virObjectUnref(priv->qemuCaps);
priv->qemuCaps = NULL;
g_clear_pointer(&priv->qemuCaps, virObjectUnref);
VIR_FREE(priv->pidfile);
@ -1640,41 +1633,25 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv)
priv->memPrealloc = false;
/* remove automatic pinning data */
virBitmapFree(priv->autoNodeset);
priv->autoNodeset = NULL;
virBitmapFree(priv->autoCpuset);
priv->autoCpuset = NULL;
/* remove address data */
virDomainPCIAddressSetFree(priv->pciaddrs);
priv->pciaddrs = NULL;
virDomainUSBAddressSetFree(priv->usbaddrs);
priv->usbaddrs = NULL;
virCPUDefFree(priv->origCPU);
priv->origCPU = NULL;
/* clear previously used namespaces */
virBitmapFree(priv->namespaces);
priv->namespaces = NULL;
g_clear_pointer(&priv->autoNodeset, virBitmapFree);
g_clear_pointer(&priv->autoCpuset, virBitmapFree);
g_clear_pointer(&priv->pciaddrs, virDomainPCIAddressSetFree);
g_clear_pointer(&priv->usbaddrs, virDomainUSBAddressSetFree);
g_clear_pointer(&priv->origCPU, virCPUDefFree);
g_clear_pointer(&priv->namespaces, virBitmapFree);
priv->rememberOwner = false;
priv->reconnectBlockjobs = VIR_TRISTATE_BOOL_ABSENT;
priv->allowReboot = VIR_TRISTATE_BOOL_ABSENT;
virBitmapFree(priv->migrationCaps);
priv->migrationCaps = NULL;
g_clear_pointer(&priv->migrationCaps, virBitmapFree);
virHashRemoveAll(priv->blockjobs);
virObjectUnref(priv->pflash0);
priv->pflash0 = NULL;
virObjectUnref(priv->pflash1);
priv->pflash1 = NULL;
virDomainBackupDefFree(priv->backup);
priv->backup = NULL;
g_clear_pointer(&priv->pflash0, virObjectUnref);
g_clear_pointer(&priv->pflash1, virObjectUnref);
g_clear_pointer(&priv->backup, virDomainBackupDefFree);
/* reset node name allocator */
qemuDomainStorageIdReset(priv);
@ -2962,8 +2939,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
if (priv->namespaces &&
virBitmapIsAllClear(priv->namespaces)) {
virBitmapFree(priv->namespaces);
priv->namespaces = NULL;
g_clear_pointer(&priv->namespaces, virBitmapFree);
}
priv->rememberOwner = virXPathBoolean("count(./rememberOwner) > 0", ctxt);
@ -3100,12 +3076,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
return 0;
error:
virBitmapFree(priv->namespaces);
priv->namespaces = NULL;
virObjectUnref(priv->monConfig);
priv->monConfig = NULL;
g_strfreev(priv->qemuDevices);
priv->qemuDevices = NULL;
g_clear_pointer(&priv->namespaces, virBitmapFree);
g_clear_pointer(&priv->monConfig, virObjectUnref);
g_clear_pointer(&priv->qemuDevices, g_strfreev);
return -1;
}
@ -3557,9 +3530,8 @@ qemuDomainDefClearDefaultAudioBackend(virQEMUDriver *driver,
if (virDomainAudioIsEqual(def->audios[0], audio)) {
virDomainAudioDefFree(def->audios[0]);
g_free(def->audios);
g_clear_pointer(&def->audios, g_free);
def->naudios = 0;
def->audios = NULL;
}
virDomainAudioDefFree(audio);

View File

@ -2738,8 +2738,7 @@ qemuDomainAssignPCIAddresses(virDomainDef *def,
}
nbuses = addrs->nbuses;
virDomainPCIAddressSetFree(addrs);
addrs = NULL;
g_clear_pointer(&addrs, virDomainPCIAddressSetFree);
}
if (!(addrs = qemuDomainPCIAddressSetCreate(def, qemuCaps, nbuses, false)))

View File

@ -3921,8 +3921,7 @@ processSerialChangedEvent(virQEMUDriver *driver,
goto endjob;
} else {
if (priv->agent) {
qemuAgentClose(priv->agent);
priv->agent = NULL;
g_clear_pointer(&priv->agent, qemuAgentClose);
}
priv->agentError = false;
}
@ -7492,8 +7491,7 @@ qemuDomainDetachDeviceConfig(virDomainDef *vmdef,
_("domain has no watchdog"));
return -1;
}
virDomainWatchdogDefFree(vmdef->watchdog);
vmdef->watchdog = NULL;
g_clear_pointer(&vmdef->watchdog, virDomainWatchdogDefFree);
break;
case VIR_DOMAIN_DEVICE_INPUT:
@ -7512,8 +7510,7 @@ qemuDomainDetachDeviceConfig(virDomainDef *vmdef,
_("matching vsock device not found"));
return -1;
}
virDomainVsockDefFree(vmdef->vsock);
vmdef->vsock = NULL;
g_clear_pointer(&vmdef->vsock, virDomainVsockDefFree);
break;
case VIR_DOMAIN_DEVICE_VIDEO:

View File

@ -645,8 +645,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver,
ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, oldsrc));
/* media was changed, so we can remove the old media definition now */
virObjectUnref(oldsrc);
oldsrc = NULL;
g_clear_pointer(&oldsrc, virObjectUnref);
ret = 0;
@ -4426,8 +4425,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver,
if (diskPriv->blockjob) {
/* the block job keeps reference to the disk chain */
diskPriv->blockjob->disk = NULL;
virObjectUnref(diskPriv->blockjob);
diskPriv->blockjob = NULL;
g_clear_pointer(&diskPriv->blockjob, virObjectUnref);
} else {
if (!(diskBackend = qemuBlockStorageSourceChainDetachPrepareBlockdev(disk->src)))
goto cleanup;
@ -5013,8 +5011,7 @@ qemuDomainRemoveWatchdog(virDomainObj *vm,
watchdog->info.alias, vm, vm->def->name);
qemuDomainReleaseDeviceAddress(vm, &watchdog->info);
virDomainWatchdogDefFree(vm->def->watchdog);
vm->def->watchdog = NULL;
g_clear_pointer(&vm->def->watchdog, virDomainWatchdogDefFree);
return 0;
}
@ -5056,8 +5053,7 @@ qemuDomainRemoveVsockDevice(virDomainObj *vm,
dev->info.alias, vm, vm->def->name);
qemuDomainReleaseDeviceAddress(vm, &dev->info);
virDomainVsockDefFree(vm->def->vsock);
vm->def->vsock = NULL;
g_clear_pointer(&vm->def->vsock, virDomainVsockDefFree);
return 0;
}

View File

@ -845,8 +845,7 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriver *driver,
qemuBlockStorageSourceDetachOneBlockdev(driver, vm, asyncJob,
diskPriv->migrSource);
virObjectUnref(diskPriv->migrSource);
diskPriv->migrSource = NULL;
g_clear_pointer(&diskPriv->migrSource, virObjectUnref);
}
ret = failed ? -1 : 0;
@ -3659,8 +3658,7 @@ static void qemuMigrationSrcIOFunc(void *arg)
abrt:
virErrorPreserveLast(&err);
if (err && err->code == VIR_ERR_OK) {
virFreeError(err);
err = NULL;
g_clear_pointer(&err, virFreeError);
}
virStreamAbort(data->st);
virErrorRestore(&err);
@ -4988,8 +4986,7 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriver *driver,
if (err &&
err->domain == VIR_FROM_QEMU &&
err->code != VIR_ERR_MIGRATE_FINISH_OK) {
virFreeError(orig_err);
orig_err = NULL;
g_clear_pointer(&orig_err, virFreeError);
}
}
}

View File

@ -818,9 +818,8 @@ void
qemuMonitorUnregister(qemuMonitor *mon)
{
if (mon->watch) {
g_source_destroy(mon->watch);
vir_g_source_unref(mon->watch, mon->context);
mon->watch = NULL;
g_clear_pointer(&mon->watch, g_source_destroy);
}
}
@ -837,8 +836,7 @@ qemuMonitorClose(qemuMonitor *mon)
if (mon->socket) {
qemuMonitorUnregister(mon);
g_object_unref(mon->socket);
mon->socket = NULL;
g_clear_pointer(&mon->socket, g_object_unref);
mon->fd = -1;
}
@ -1557,8 +1555,7 @@ qemuMonitorCPUInfoClear(qemuMonitorCPUInfo *cpus,
VIR_FREE(cpus[i].qom_path);
VIR_FREE(cpus[i].alias);
VIR_FREE(cpus[i].type);
virJSONValueFree(cpus[i].props);
cpus[i].props = NULL;
g_clear_pointer(&cpus[i].props, virJSONValueFree);
}
}

View File

@ -833,8 +833,7 @@ qemuDomainDisableNamespace(virDomainObj *vm,
if (priv->namespaces) {
ignore_value(virBitmapClearBit(priv->namespaces, ns));
if (virBitmapIsAllClear(priv->namespaces)) {
virBitmapFree(priv->namespaces);
priv->namespaces = NULL;
g_clear_pointer(&priv->namespaces, virBitmapFree);
}
}
}

View File

@ -8065,21 +8065,18 @@ void qemuProcessStop(virQEMUDriver *driver,
priv->nbdPort = 0;
if (priv->agent) {
qemuAgentClose(priv->agent);
priv->agent = NULL;
g_clear_pointer(&priv->agent, qemuAgentClose);
}
priv->agentError = false;
if (priv->mon) {
qemuMonitorClose(priv->mon);
priv->mon = NULL;
g_clear_pointer(&priv->mon, qemuMonitorClose);
}
if (priv->monConfig) {
if (priv->monConfig->type == VIR_DOMAIN_CHR_TYPE_UNIX)
unlink(priv->monConfig->data.nix.path);
virObjectUnref(priv->monConfig);
priv->monConfig = NULL;
g_clear_pointer(&priv->monConfig, virObjectUnref);
}
qemuDomainObjStopWorker(vm);
@ -8277,9 +8274,8 @@ void qemuProcessStop(virQEMUDriver *driver,
for (i = 0; i < vm->ndeprecations; i++)
g_free(vm->deprecations[i]);
g_free(vm->deprecations);
g_clear_pointer(&vm->deprecations, g_free);
vm->ndeprecations = 0;
vm->deprecations = NULL;
vm->taint = 0;
vm->pid = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
@ -9091,14 +9087,12 @@ qemuProcessQMPStop(qemuProcessQMP *proc)
{
if (proc->mon) {
virObjectUnlock(proc->mon);
qemuMonitorClose(proc->mon);
proc->mon = NULL;
g_clear_pointer(&proc->mon, qemuMonitorClose);
}
if (proc->cmd) {
virCommandAbort(proc->cmd);
virCommandFree(proc->cmd);
proc->cmd = NULL;
g_clear_pointer(&proc->cmd, virCommandFree);
}
if (proc->monpath)

View File

@ -1841,8 +1841,7 @@ remoteOpenConn(const char *uri,
error:
if (*conn) {
virConnectClose(*conn);
*conn = NULL;
g_clear_pointer(conn, virConnectClose);
}
goto cleanup;
}
@ -2191,8 +2190,7 @@ remoteDispatchConnectOpen(virNetServer *server G_GNUC_UNUSED,
if (rv < 0) {
virNetMessageSaveError(rerr);
if (priv->conn) {
virObjectUnref(priv->conn);
priv->conn = NULL;
g_clear_pointer(&priv->conn, virObjectUnref);
}
}
virMutexUnlock(&priv->lock);
@ -3763,8 +3761,7 @@ remoteSASLFinish(virNetServer *server,
"client=%p auth=%d identity=%s",
client, REMOTE_AUTH_SASL, identity);
virObjectUnref(priv->sasl);
priv->sasl = NULL;
g_clear_pointer(&priv->sasl, virObjectUnref);
return 0;
}
@ -3856,8 +3853,7 @@ remoteDispatchAuthSaslStart(virNetServer *server,
goto error;
error:
virObjectUnref(priv->sasl);
priv->sasl = NULL;
g_clear_pointer(&priv->sasl, virObjectUnref);
virResetLastError();
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("authentication failed"));
@ -3951,8 +3947,7 @@ remoteDispatchAuthSaslStep(virNetServer *server,
goto error;
error:
virObjectUnref(priv->sasl);
priv->sasl = NULL;
g_clear_pointer(&priv->sasl, virObjectUnref);
virResetLastError();
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("authentication failed"));

View File

@ -1193,12 +1193,9 @@ doRemoteOpen(virConnectPtr conn,
virObjectUnref(priv->lxcProgram);
virObjectUnref(priv->qemuProgram);
virNetClientClose(priv->client);
virObjectUnref(priv->client);
priv->client = NULL;
virObjectUnref(priv->closeCallback);
priv->closeCallback = NULL;
virObjectUnref(priv->tls);
priv->tls = NULL;
g_clear_pointer(&priv->client, virObjectUnref);
g_clear_pointer(&priv->closeCallback, virObjectUnref);
g_clear_pointer(&priv->tls, virObjectUnref);
VIR_FREE(priv->hostname);
return VIR_DRV_OPEN_ERROR;
@ -1302,18 +1299,15 @@ doRemoteClose(virConnectPtr conn, struct private_data *priv)
(xdrproc_t) xdr_void, (char *) NULL) == -1)
ret = -1;
virObjectUnref(priv->tls);
priv->tls = NULL;
g_clear_pointer(&priv->tls, virObjectUnref);
virNetClientSetCloseCallback(priv->client,
NULL,
priv->closeCallback, virObjectFreeCallback);
virNetClientClose(priv->client);
virObjectUnref(priv->client);
priv->client = NULL;
virObjectUnref(priv->closeCallback);
priv->closeCallback = NULL;
g_clear_pointer(&priv->client, virObjectUnref);
g_clear_pointer(&priv->closeCallback, virObjectUnref);
virObjectUnref(priv->remoteProgram);
virObjectUnref(priv->lxcProgram);
virObjectUnref(priv->qemuProgram);
@ -1325,8 +1319,7 @@ doRemoteClose(virConnectPtr conn, struct private_data *priv)
/* See comment for remoteType. */
VIR_FREE(priv->type);
virObjectUnref(priv->eventState);
priv->eventState = NULL;
g_clear_pointer(&priv->eventState, virObjectUnref);
return ret;
}

View File

@ -63,8 +63,7 @@ virRemoteSSHHelperShutdown(virRemoteSSHHelper *proxy)
if (proxy->sock) {
virNetSocketRemoveIOCallback(proxy->sock);
virNetSocketClose(proxy->sock);
virObjectUnref(proxy->sock);
proxy->sock = NULL;
g_clear_pointer(&proxy->sock, virObjectUnref);
}
VIR_FREE(proxy->sockToTerminal.data);
VIR_FREE(proxy->terminalToSock.data);

View File

@ -791,19 +791,15 @@ virNetClientCloseLocked(virNetClient *client)
if (!client->sock)
return;
virObjectUnref(client->sock);
client->sock = NULL;
virObjectUnref(client->tls);
client->tls = NULL;
g_clear_pointer(&client->sock, virObjectUnref);
g_clear_pointer(&client->tls, virObjectUnref);
#if WITH_SASL
virObjectUnref(client->sasl);
client->sasl = NULL;
g_clear_pointer(&client->sasl, virObjectUnref);
#endif
ka = g_steal_pointer(&client->keepalive);
client->wantClose = false;
virFreeError(client->error);
client->error = NULL;
g_clear_pointer(&client->error, virFreeError);
if (ka || client->closeCb) {
virNetClientCloseFunc closeCb = client->closeCb;
@ -1025,8 +1021,7 @@ int virNetClientSetTLSSession(virNetClient *client,
return 0;
error:
virObjectUnref(client->tls);
client->tls = NULL;
g_clear_pointer(&client->tls, virObjectUnref);
virObjectUnlock(client);
return -1;
}

View File

@ -1018,8 +1018,7 @@ virNetServerClientCloseLocked(virNetServerClient *client)
virNetSocketRemoveIOCallback(client->sock);
if (client->tls) {
virObjectUnref(client->tls);
client->tls = NULL;
g_clear_pointer(&client->tls, virObjectUnref);
}
client->wantClose = true;
@ -1035,8 +1034,7 @@ virNetServerClientCloseLocked(virNetServerClient *client)
}
if (client->sock) {
virObjectUnref(client->sock);
client->sock = NULL;
g_clear_pointer(&client->sock, virObjectUnref);
}
}
@ -1255,9 +1253,8 @@ static virNetMessage *virNetServerClientDispatchRead(virNetServerClient *client)
msg->header.type, msg->header.status, msg->header.serial);
if (virKeepAliveCheckMessage(client->keepalive, msg, &response)) {
virNetMessageFree(msg);
g_clear_pointer(&msg, virNetMessageFree);
client->nrequests--;
msg = NULL;
if (response &&
virNetServerClientSendMessageLocked(client, response) < 0)
@ -1270,8 +1267,7 @@ static virNetMessage *virNetServerClientDispatchRead(virNetServerClient *client)
while (filter) {
int ret = filter->func(client, msg, filter->opaque);
if (ret < 0) {
virNetMessageFree(msg);
msg = NULL;
g_clear_pointer(&msg, virNetMessageFree);
client->wantClose = true;
break;
}
@ -1375,8 +1371,7 @@ virNetServerClientDispatchWrite(virNetServerClient *client)
*/
if (client->sasl) {
virNetSocketSetSASLSession(client->sock, client->sasl);
virObjectUnref(client->sasl);
client->sasl = NULL;
g_clear_pointer(&client->sasl, virObjectUnref);
}
#endif

View File

@ -505,8 +505,7 @@ static gnutls_x509_crt_t virNetTLSContextLoadCertFromFile(const char *certFile,
cleanup:
if (ret != 0) {
gnutls_x509_crt_deinit(cert);
cert = NULL;
g_clear_pointer(&cert, gnutls_x509_crt_deinit);
}
VIR_FREE(buf);
return cert;

View File

@ -275,8 +275,7 @@ secretDefineXML(virConnectPtr conn,
def = g_steal_pointer(&objDef);
} else {
virSecretObjListRemove(driver->secrets, obj);
virObjectUnref(obj);
obj = NULL;
g_clear_pointer(&obj, virObjectUnref);
}
cleanup:
@ -434,8 +433,7 @@ secretUndefine(virSecretPtr secret)
virSecretObjDeleteData(obj);
virSecretObjListRemove(driver->secrets, obj);
virObjectUnref(obj);
obj = NULL;
g_clear_pointer(&obj, virObjectUnref);
ret = 0;

View File

@ -679,8 +679,7 @@ virSecurityManagerGenLabel(virSecurityManager *mgr,
if (!sec_managers[i]->drv->domainGenSecurityLabel) {
virReportUnsupportedError();
virSecurityLabelDefFree(seclabel);
seclabel = NULL;
g_clear_pointer(&seclabel, virSecurityLabelDefFree);
} else {
/* The seclabel must be added to @vm prior calling domainGenSecurityLabel
* which may require seclabel to be presented already */

View File

@ -687,8 +687,7 @@ virSecuritySELinuxLXCInitialize(virSecurityManager *mgr)
return 0;
error:
selabel_close(data->label_handle);
data->label_handle = NULL;
g_clear_pointer(&data->label_handle, selabel_close);
VIR_FREE(data->domain_context);
VIR_FREE(data->file_context);
VIR_FREE(data->content_context);
@ -758,8 +757,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManager *mgr)
return 0;
error:
selabel_close(data->label_handle);
data->label_handle = NULL;
g_clear_pointer(&data->label_handle, selabel_close);
VIR_FREE(data->domain_context);
VIR_FREE(data->alt_domain_context);
VIR_FREE(data->file_context);

View File

@ -272,8 +272,7 @@ virISCSIDirectGetVolumeCapacity(struct iscsi_context *iscsi,
if (inq->device_type == SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
struct scsi_readcapacity16 *rc16 = NULL;
scsi_free_scsi_task(task);
task = NULL;
g_clear_pointer(&task, scsi_free_scsi_task);
if (!(task = iscsi_readcapacity16_sync(iscsi, lun)) ||
task->status != SCSI_STATUS_GOOD) {

View File

@ -356,15 +356,13 @@ virStorageBackendRBDCloseRADOSConn(virStorageBackendRBDState *ptr)
{
if (ptr->ioctx != NULL) {
VIR_DEBUG("Closing RADOS IoCTX");
rados_ioctx_destroy(ptr->ioctx);
g_clear_pointer(&ptr->ioctx, rados_ioctx_destroy);
}
ptr->ioctx = NULL;
if (ptr->cluster != NULL) {
VIR_DEBUG("Closing RADOS connection");
rados_shutdown(ptr->cluster);
g_clear_pointer(&ptr->cluster, rados_shutdown);
}
ptr->cluster = NULL;
VIR_DEBUG("RADOS connection existed for %ld seconds",
time(0) - ptr->starttime);

View File

@ -3593,8 +3593,7 @@ virStorageBackendRefreshLocal(virStoragePoolObj *pool)
if (err == -2) {
/* Silently ignore non-regular files,
* eg 'lost+found', dangling symbolic link */
virStorageVolDefFree(vol);
vol = NULL;
g_clear_pointer(&vol, virStorageVolDefFree);
continue;
}
return -1;

View File

@ -969,8 +969,7 @@ virStorageFileProbeGetMetadata(virStorageSource *meta,
return -1;
}
virBitmapFree(meta->features);
meta->features = NULL;
g_clear_pointer(&meta->features, virBitmapFree);
if (fileTypeInfo[meta->format].getFeatures != NULL &&
fileTypeInfo[meta->format].getFeatures(&meta->features, meta->format, buf, len) < 0)
return -1;

View File

@ -420,8 +420,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
* also used in other places. For backing store detection the
* authentication data would be invalid anyways, so we clear it */
if (def->auth) {
virStorageAuthDefFree(def->auth);
def->auth = NULL;
g_clear_pointer(&def->auth, virStorageAuthDefFree);
}
}

View File

@ -1537,8 +1537,7 @@ testConnectOpen(virConnectPtr conn,
/* Fake authentication. */
if (testConnectAuthenticate(conn, auth) < 0) {
testDriverCloseInternal(conn->privateData);
conn->privateData = NULL;
g_clear_pointer(&conn->privateData, testDriverCloseInternal);
return VIR_DRV_OPEN_ERROR;
}
@ -1549,8 +1548,7 @@ testConnectOpen(virConnectPtr conn,
static int
testConnectClose(virConnectPtr conn)
{
testDriverCloseInternal(conn->privateData);
conn->privateData = NULL;
g_clear_pointer(&conn->privateData, testDriverCloseInternal);
return 0;
}

View File

@ -136,8 +136,7 @@ void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove)
if (toremove < *countptr) {
virReallocN(ptrptr, size, *countptr -= toremove);
} else {
g_free(*((void **)ptrptr));
*((void **)ptrptr) = NULL;
g_clear_pointer(((void **)ptrptr), g_free);
*countptr = 0;
}
}

View File

@ -919,8 +919,7 @@ int virConfGetValueStringList(virConf *conf,
if (!cval)
return 0;
g_strfreev(*values);
*values = NULL;
g_clear_pointer(values, g_strfreev);
switch (cval->type) {
case VIR_CONF_LIST:

View File

@ -445,8 +445,7 @@ virErrorRestore(virErrorPtr *savederr)
return;
virSetError(*savederr);
virFreeError(*savederr);
*savederr = NULL;
g_clear_pointer(savederr, virFreeError);
errno = saved_errno;
}

View File

@ -228,8 +228,7 @@ virEventGLibHandleUpdate(int watch,
VIR_DEBUG("Removed old handle source=%p", data->source);
g_source_destroy(data->source);
vir_g_source_unref(data->source, NULL);
data->source = NULL;
g_clear_pointer(&data->source, g_source_destroy);
data->events = 0;
}
@ -276,9 +275,8 @@ virEventGLibHandleRemove(int watch)
data, watch, data->fd);
if (data->source != NULL) {
g_source_destroy(data->source);
vir_g_source_unref(data->source, NULL);
data->source = NULL;
g_clear_pointer(&data->source, g_source_destroy);
data->events = 0;
}
@ -419,9 +417,8 @@ virEventGLibTimeoutUpdate(int timer,
if (data->source == NULL)
goto cleanup;
g_source_destroy(data->source);
vir_g_source_unref(data->source, NULL);
data->source = NULL;
g_clear_pointer(&data->source, g_source_destroy);
}
cleanup:
@ -468,9 +465,8 @@ virEventGLibTimeoutRemove(int timer)
data, timer);
if (data->source != NULL) {
g_source_destroy(data->source);
vir_g_source_unref(data->source, NULL);
data->source = NULL;
g_clear_pointer(&data->source, g_source_destroy);
}
/* since the actual timeout deletion is done asynchronously, a timeoutUpdate call may

View File

@ -3723,8 +3723,7 @@ virFileSetACLs(const char *file,
void
virFileFreeACLs(void **acl)
{
acl_free(*acl);
*acl = NULL;
g_clear_pointer(acl, acl_free);
}
#else /* !defined(WITH_LIBACL) */

View File

@ -209,8 +209,7 @@ virFileCacheNewData(virFileCache *cache,
return NULL;
if (virFileCacheSave(cache, name, data) < 0) {
virObjectUnref(data);
data = NULL;
g_clear_pointer(&data, virObjectUnref);
}
}
@ -273,8 +272,7 @@ virFileCacheValidate(virFileCache *cache,
if (*data) {
VIR_DEBUG("Caching data '%p' for '%s'", *data, name);
if (virHashAddEntry(cache->table, name, *data) < 0) {
virObjectUnref(*data);
*data = NULL;
g_clear_pointer(data, virObjectUnref);
}
}
}

View File

@ -174,8 +174,7 @@ virGDBusCloseSystemBus(void)
g_dbus_connection_flush_sync(systemBus, NULL, NULL);
g_dbus_connection_close_sync(systemBus, NULL, NULL);
g_object_unref(systemBus);
systemBus = NULL;
g_clear_pointer(&systemBus, g_object_unref);
}

View File

@ -282,8 +282,7 @@ virMediatedDeviceListDispose(void *obj)
size_t i;
for (i = 0; i < list->count; i++) {
virMediatedDeviceFree(list->devs[i]);
list->devs[i] = NULL;
g_clear_pointer(&list->devs[i], virMediatedDeviceFree);
}
list->count = 0;

View File

@ -2948,8 +2948,7 @@ int virNetDevGetRxFilter(const char *ifname,
ret = 0;
cleanup:
if (ret < 0) {
virNetDevRxFilterFree(fil);
fil = NULL;
g_clear_pointer(&fil, virNetDevRxFilterFree);
}
*filter = fil;

View File

@ -192,8 +192,7 @@ void
virNetlinkShutdown(void)
{
if (placeholder_nlhandle) {
virNetlinkFree(placeholder_nlhandle);
placeholder_nlhandle = NULL;
g_clear_pointer(&placeholder_nlhandle, virNetlinkFree);
}
}

View File

@ -1666,8 +1666,7 @@ virPCIDeviceListDispose(void *obj)
size_t i;
for (i = 0; i < list->count; i++) {
virPCIDeviceFree(list->devs[i]);
list->devs[i] = NULL;
g_clear_pointer(&list->devs[i], virPCIDeviceFree);
}
list->count = 0;

View File

@ -1705,8 +1705,7 @@ virResctrlAllocGetGroup(virResctrlInfo *resctrl,
error:
VIR_FREE(schemata);
virObjectUnref(*alloc);
*alloc = NULL;
g_clear_pointer(alloc, virObjectUnref);
return -1;
}

View File

@ -638,8 +638,7 @@ virStringSearch(const char *str,
cleanup:
if (ret < 0) {
g_strfreev(*matches);
*matches = NULL;
g_clear_pointer(matches, g_strfreev);
}
return ret;
}

View File

@ -254,8 +254,7 @@ virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDef **sysdef)
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
virSysinfoSystemDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
*sysdef = g_steal_pointer(&def);
@ -375,8 +374,7 @@ virSysinfoParseARMSystem(const char *base, virSysinfoSystemDef **sysdef)
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
virSysinfoSystemDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
*sysdef = g_steal_pointer(&def);
@ -509,8 +507,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDef **sysdef)
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
virSysinfoSystemDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
*sysdef = g_steal_pointer(&def);
@ -672,8 +669,7 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDef **bios)
if (!def->vendor && !def->version &&
!def->date && !def->release) {
virSysinfoBIOSDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoBIOSDefFree);
}
*bios = g_steal_pointer(&def);
@ -748,8 +744,7 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDef **sysdef)
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
virSysinfoSystemDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
*sysdef = g_steal_pointer(&def);
@ -889,8 +884,7 @@ virSysinfoParseX86Chassis(const char *base,
if (!def->manufacturer && !def->version &&
!def->serial && !def->asset && !def->sku) {
virSysinfoChassisDefFree(def);
def = NULL;
g_clear_pointer(&def, virSysinfoChassisDefFree);
}
*chassisdef = g_steal_pointer(&def);

View File

@ -330,8 +330,7 @@ virTPMEmulatorInit(bool quiet)
return -1;
}
swtpmBinaries[i].path = g_steal_pointer(&path);
virBitmapFree(swtpmBinaries[i].caps);
swtpmBinaries[i].caps = NULL;
g_clear_pointer(&swtpmBinaries[i].caps, virBitmapFree);
}
}

View File

@ -152,8 +152,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing,
cleanup:
if (hVBoxXPCOMC != NULL && result < 0) {
dlclose(hVBoxXPCOMC);
hVBoxXPCOMC = NULL;
g_clear_pointer(&hVBoxXPCOMC, dlclose);
}
VIR_FREE(name);

View File

@ -4953,8 +4953,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
tmp = virStringReplace(newSnapshotPtr->storageController,
searchResultTab[it],
uuidReplacing);
g_strfreev(searchResultTab);
searchResultTab = NULL;
g_clear_pointer(&searchResultTab, g_strfreev);
VIR_FREE(newSnapshotPtr->storageController);
if (!tmp)
goto cleanup;

View File

@ -104,8 +104,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlNodePtr diskNode,
VIR_FREE(location);
VIR_FREE(tmp);
if (result < 0) {
virVboxSnapshotConfHardDiskFree(hardDisk);
hardDisk = NULL;
g_clear_pointer(&hardDisk, virVboxSnapshotConfHardDiskFree);
}
return hardDisk;
}
@ -165,8 +164,7 @@ virVBoxSnapshotConfRetrieveMediaRegistry(xmlNodePtr mediaRegistryNode,
cleanup:
if (result < 0) {
virVBoxSnapshotConfMediaRegistryFree(mediaRegistry);
mediaRegistry = NULL;
g_clear_pointer(&mediaRegistry, virVBoxSnapshotConfMediaRegistryFree);
}
VIR_FREE(nodes);
return mediaRegistry;
@ -264,8 +262,7 @@ virVBoxSnapshotConfRetrieveSnapshot(xmlNodePtr snapshotNode,
cleanup:
if (result < 0) {
virVBoxSnapshotConfSnapshotFree(snapshot);
snapshot = NULL;
g_clear_pointer(&snapshot, virVBoxSnapshotConfSnapshotFree);
}
VIR_FREE(nodes);
VIR_FREE(uuid);
@ -348,8 +345,7 @@ virVBoxSnapshotConfCreateHardDiskNode(virVBoxSnapshotConfHardDisk *hardDisk)
cleanup:
if (result < 0) {
xmlUnlinkNode(ret);
xmlFreeNode(ret);
ret = NULL;
g_clear_pointer(&ret, xmlFreeNode);
}
VIR_FREE(uuid);
return ret;

View File

@ -1425,8 +1425,7 @@ virVMXParseConfig(virVMXContext *ctx,
if (encoding == NULL || STRCASEEQ(encoding, "UTF-8")) {
/* nothing */
} else {
virConfFree(conf);
conf = NULL;
g_clear_pointer(&conf, virConfFree);
utf8 = virVMXConvertToUTF8(encoding, vmx);
@ -2053,8 +2052,7 @@ virVMXParseVNC(virConf *conf, virDomainGraphicsDef **def)
failure:
VIR_FREE(listenAddr);
virDomainGraphicsDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainGraphicsDefFree);
return -1;
}
@ -2556,8 +2554,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOption *xmlopt, virConf *conf,
cleanup:
if (result < 0) {
virDomainDiskDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainDiskDefFree);
}
VIR_FREE(prefix);
@ -2569,8 +2566,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOption *xmlopt, virConf *conf,
return result;
ignore:
virDomainDiskDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainDiskDefFree);
result = 0;
@ -2653,8 +2649,7 @@ virVMXParseFileSystem(virConf *conf, int number, virDomainFSDef **def)
cleanup:
if (result < 0) {
virDomainFSDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainFSDefFree);
}
VIR_FREE(hostPath);
@ -2869,8 +2864,7 @@ virVMXParseEthernet(virConf *conf, int controller, virDomainNetDef **def)
cleanup:
if (result < 0) {
virDomainNetDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainNetDefFree);
}
VIR_FREE(networkName);
@ -3051,8 +3045,7 @@ virVMXParseSerial(virVMXContext *ctx, virConf *conf, int port,
cleanup:
if (result < 0) {
virDomainChrDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainChrDefFree);
}
VIR_FREE(fileType);
@ -3153,8 +3146,7 @@ virVMXParseParallel(virVMXContext *ctx, virConf *conf, int port,
cleanup:
if (result < 0) {
virDomainChrDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainChrDefFree);
}
VIR_FREE(fileType);
@ -3191,8 +3183,7 @@ virVMXParseSVGA(virConf *conf, virDomainVideoDef **def)
cleanup:
if (result < 0) {
virDomainVideoDefFree(*def);
*def = NULL;
g_clear_pointer(def, virDomainVideoDefFree);
}
return result;

View File

@ -4071,8 +4071,7 @@ static int
vzStateCleanup(void)
{
if (vz_driver_privileged) {
virObjectUnref(vz_driver);
vz_driver = NULL;
g_clear_pointer(&vz_driver, virObjectUnref);
if (vz_driver_lock_fd != -1)
virPidFileRelease(VZ_STATEDIR, "driver", vz_driver_lock_fd);
virMutexDestroy(&vz_driver_lock);

View File

@ -179,8 +179,7 @@ getJobResultHelper(PRL_HANDLE job, unsigned int timeout, PRL_HANDLE *result,
ret = PrlJob_GetResult(job, result);
if (PRL_FAILED(ret)) {
logPrlErrorHelper(ret, filename, funcname, linenr);
PrlHandle_Free(*result);
*result = NULL;
g_clear_pointer(result, PrlHandle_Free);
goto cleanup;
}

View File

@ -446,8 +446,7 @@ static int test13(const void *unused G_GNUC_UNUSED)
if (!outactual)
goto cleanup;
virCommandFree(cmd);
cmd = NULL;
g_clear_pointer(&cmd, virCommandFree);
if (STRNEQ(outactual, outexpect)) {
virTestDifference(stderr, outexpect, outactual);
@ -668,8 +667,7 @@ static int test18(const void *unused G_GNUC_UNUSED)
goto cleanup;
}
virCommandFree(cmd);
cmd = NULL;
g_clear_pointer(&cmd, virCommandFree);
if (kill(pid, 0) != 0) {
printf("daemon should still be running\n");
goto cleanup;

View File

@ -293,8 +293,7 @@ cpuTestBaseline(const void *arg)
if (baseline &&
(data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
virCPUExpandFeatures(data->arch, baseline) < 0) {
virCPUDefFree(baseline);
baseline = NULL;
g_clear_pointer(&baseline, virCPUDefFree);
}
if (data->result < 0) {

View File

@ -327,8 +327,7 @@ qemuMonitorTestIO(virNetSocket *sock,
if (err) {
virNetSocketRemoveIOCallback(sock);
virNetSocketClose(sock);
virObjectUnref(test->client);
test->client = NULL;
g_clear_pointer(&test->client, virObjectUnref);
} else {
events = VIR_EVENT_HANDLE_READABLE;

View File

@ -179,8 +179,7 @@ testCreateServer(const char *server_name, const char *host, int family)
return srv;
error:
virObjectUnref(srv);
srv = NULL;
g_clear_pointer(&srv, virObjectUnref);
goto cleanup;
}

View File

@ -272,8 +272,7 @@ testSocketAccept(const void *opaque)
goto join;
}
virObjectUnref(ssock);
ssock = NULL;
g_clear_pointer(&ssock, virObjectUnref);
ret = 0;

View File

@ -428,8 +428,7 @@ void testTLSDiscardCert(struct testTLSCertReq *req)
if (!req->crt)
return;
gnutls_x509_crt_deinit(req->crt);
req->crt = NULL;
g_clear_pointer(&req->crt, gnutls_x509_crt_deinit);
if (getenv("VIRT_TEST_DEBUG_CERTS") == NULL)
unlink(req->filename);

View File

@ -227,7 +227,7 @@ testPCIVPDResourceCustomCompareIndex(const void *data G_GNUC_UNUSED)
return -1;
/* Different index, same value pointers */
g_free(b->value);
g_clear_pointer(&b->value, g_free);
b->value = a->value;
if (virPCIVPDResourceCustomCompareIndex(b, a)) {
b->value = NULL;

View File

@ -171,8 +171,7 @@ testUSBList(const void *opaque G_GNUC_UNUSED)
dev = NULL;
}
virObjectUnref(devlist);
devlist = NULL;
g_clear_pointer(&devlist, virObjectUnref);
ndevs = virUSBDeviceListCount(list);
if (testCheckNdevs("After first loop", ndevs, EXPECTED_NDEVS_ONE) < 0)
@ -210,8 +209,7 @@ testUSBList(const void *opaque G_GNUC_UNUSED)
}
virUSBDeviceListDel(list, dev);
virUSBDeviceFree(dev);
dev = NULL;
g_clear_pointer(&dev, virUSBDeviceFree);
if (testCheckNdevs("After deleting one",
virUSBDeviceListCount(list),

View File

@ -1740,8 +1740,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int flags)
remove_entry:
/* the domain has to be removed as it failed one of the filters */
virshDomainFree(list->domains[i]);
list->domains[i] = NULL;
g_clear_pointer(&list->domains[i], virshDomainFree);
deleted++;
}
@ -1762,8 +1761,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int flags)
VIR_FREE(names[i]);
if (!success) {
virshDomainListFree(list);
list = NULL;
g_clear_pointer(&list, virshDomainListFree);
}
VIR_FREE(names);

View File

@ -12614,8 +12614,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
/* remove current source */
xmlUnlinkNode(source);
xmlFreeNode(source);
source = NULL;
g_clear_pointer(&source, xmlFreeNode);
}
/* set the correct disk type */

View File

@ -302,8 +302,7 @@ virshInterfaceListCollect(vshControl *ctl,
VIR_FREE(inactiveNames);
if (!success) {
virshInterfaceListFree(list);
list = NULL;
g_clear_pointer(&list, virshInterfaceListFree);
}
return list;

View File

@ -640,8 +640,7 @@ virshNetworkListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
virshNetworkListFree(list);
list = NULL;
g_clear_pointer(&list, virshNetworkListFree);
}
return list;
@ -1697,8 +1696,7 @@ virshNetworkPortListCollect(vshControl *ctl,
cleanup:
if (!success) {
virshNetworkPortListFree(list);
list = NULL;
g_clear_pointer(&list, virshNetworkPortListFree);
}
return list;

View File

@ -343,8 +343,7 @@ virshNodeDeviceListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
virshNodeDeviceListFree(list);
list = NULL;
g_clear_pointer(&list, virshNodeDeviceListFree);
}
return list;

View File

@ -329,8 +329,7 @@ virshNWFilterListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
virshNWFilterListFree(list);
list = NULL;
g_clear_pointer(&list, virshNWFilterListFree);
}
return list;
@ -692,8 +691,7 @@ virshNWFilterBindingListCollect(vshControl *ctl,
cleanup:
if (!success) {
virshNWFilterBindingListFree(list);
list = NULL;
g_clear_pointer(&list, virshNWFilterBindingListFree);
}
return list;

View File

@ -1012,8 +1012,7 @@ virshStoragePoolListCollect(vshControl *ctl,
VIR_FREE(names[i]);
if (!success) {
virshStoragePoolListFree(list);
list = NULL;
g_clear_pointer(&list, virshStoragePoolListFree);
}
VIR_FREE(names);

View File

@ -512,8 +512,7 @@ virshSecretListCollect(vshControl *ctl,
}
if (!success) {
virshSecretListFree(list);
list = NULL;
g_clear_pointer(&list, virshSecretListFree);
}
return list;

View File

@ -1213,8 +1213,8 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
STRNEQ_NULLABLE(fromname,
snaplist->snaps[i].parent)))) ||
(roots && snaplist->snaps[i].parent)) {
virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL;
g_clear_pointer(&snaplist->snaps[i].snap,
virshDomainSnapshotFree);
VIR_FREE(snaplist->snaps[i].parent);
deleted++;
}
@ -1241,8 +1241,8 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
for (i = 0; i < count; i++) {
if (i == start_index || !snaplist->snaps[i].parent) {
VIR_FREE(names[i]);
virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL;
g_clear_pointer(&snaplist->snaps[i].snap,
virshDomainSnapshotFree);
VIR_FREE(snaplist->snaps[i].parent);
deleted++;
} else if (STREQ(snaplist->snaps[i].parent, fromname)) {
@ -1279,8 +1279,8 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
if (!found_parent) {
changed = true;
VIR_FREE(names[i]);
virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL;
g_clear_pointer(&snaplist->snaps[i].snap,
virshDomainSnapshotFree);
VIR_FREE(snaplist->snaps[i].parent);
deleted++;
}
@ -1302,8 +1302,8 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
case 1:
break;
case 0:
virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL;
g_clear_pointer(&snaplist->snaps[i].snap,
virshDomainSnapshotFree);
VIR_FREE(snaplist->snaps[i].parent);
deleted++;
break;

View File

@ -1298,8 +1298,7 @@ virshStorageVolListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
virshStorageVolListFree(list);
list = NULL;
g_clear_pointer(&list, virshStorageVolListFree);
}
return list;

View File

@ -174,8 +174,7 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly)
vshError(ctl, "%s",
_("Cannot setup keepalive on connection "
"as requested, disconnecting"));
virConnectClose(c);
c = NULL;
g_clear_pointer(&c, virConnectClose);
goto cleanup;
}
vshDebug(ctl, VSH_ERR_INFO, "%s",

View File

@ -199,8 +199,7 @@ vshSaveLibvirtHelperError(void)
void
vshResetLibvirtError(void)
{
virFreeError(last_error);
last_error = NULL;
g_clear_pointer(&last_error, virFreeError);
virResetLastError();
}
@ -1377,8 +1376,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
const vshCmdDef *cmd = NULL;
if (!partial) {
vshCommandFree(ctl->cmd);
ctl->cmd = NULL;
g_clear_pointer(&ctl->cmd, vshCommandFree);
}
while (1) {
@ -1393,8 +1391,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
first = NULL;
if (partial) {
vshCommandFree(*partial);
*partial = NULL;
g_clear_pointer(partial, vshCommandFree);
}
while (1) {
@ -1605,8 +1602,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
*partial = tmp;
} else {
vshCommandFree(ctl->cmd);
ctl->cmd = NULL;
g_clear_pointer(&ctl->cmd, vshCommandFree);
vshCommandOptFree(first);
}
VIR_FREE(tkdata);
@ -2731,8 +2727,7 @@ vshReadlineParse(const char *text, int state)
const vshCmdOptDef *opt = NULL;
g_autofree char *line = g_strdup(rl_line_buffer);
g_strfreev(list);
list = NULL;
g_clear_pointer(&list, g_strfreev);
list_index = 0;
*(line + rl_point) = '\0';
@ -2798,8 +2793,7 @@ vshReadlineParse(const char *text, int state)
cleanup:
if (!ret) {
g_strfreev(list);
list = NULL;
g_clear_pointer(&list, g_strfreev);
list_index = 0;
}