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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -687,8 +687,7 @@ virSecuritySELinuxLXCInitialize(virSecurityManager *mgr)
return 0; return 0;
error: error:
selabel_close(data->label_handle); g_clear_pointer(&data->label_handle, selabel_close);
data->label_handle = NULL;
VIR_FREE(data->domain_context); VIR_FREE(data->domain_context);
VIR_FREE(data->file_context); VIR_FREE(data->file_context);
VIR_FREE(data->content_context); VIR_FREE(data->content_context);
@ -758,8 +757,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManager *mgr)
return 0; return 0;
error: error:
selabel_close(data->label_handle); g_clear_pointer(&data->label_handle, selabel_close);
data->label_handle = NULL;
VIR_FREE(data->domain_context); VIR_FREE(data->domain_context);
VIR_FREE(data->alt_domain_context); VIR_FREE(data->alt_domain_context);
VIR_FREE(data->file_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) { if (inq->device_type == SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
struct scsi_readcapacity16 *rc16 = NULL; struct scsi_readcapacity16 *rc16 = NULL;
scsi_free_scsi_task(task); g_clear_pointer(&task, scsi_free_scsi_task);
task = NULL;
if (!(task = iscsi_readcapacity16_sync(iscsi, lun)) || if (!(task = iscsi_readcapacity16_sync(iscsi, lun)) ||
task->status != SCSI_STATUS_GOOD) { task->status != SCSI_STATUS_GOOD) {

View File

@ -356,15 +356,13 @@ virStorageBackendRBDCloseRADOSConn(virStorageBackendRBDState *ptr)
{ {
if (ptr->ioctx != NULL) { if (ptr->ioctx != NULL) {
VIR_DEBUG("Closing RADOS IoCTX"); 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) { if (ptr->cluster != NULL) {
VIR_DEBUG("Closing RADOS connection"); 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", VIR_DEBUG("RADOS connection existed for %ld seconds",
time(0) - ptr->starttime); time(0) - ptr->starttime);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4071,8 +4071,7 @@ static int
vzStateCleanup(void) vzStateCleanup(void)
{ {
if (vz_driver_privileged) { if (vz_driver_privileged) {
virObjectUnref(vz_driver); g_clear_pointer(&vz_driver, virObjectUnref);
vz_driver = NULL;
if (vz_driver_lock_fd != -1) if (vz_driver_lock_fd != -1)
virPidFileRelease(VZ_STATEDIR, "driver", vz_driver_lock_fd); virPidFileRelease(VZ_STATEDIR, "driver", vz_driver_lock_fd);
virMutexDestroy(&vz_driver_lock); 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); ret = PrlJob_GetResult(job, result);
if (PRL_FAILED(ret)) { if (PRL_FAILED(ret)) {
logPrlErrorHelper(ret, filename, funcname, linenr); logPrlErrorHelper(ret, filename, funcname, linenr);
PrlHandle_Free(*result); g_clear_pointer(result, PrlHandle_Free);
*result = NULL;
goto cleanup; goto cleanup;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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