[PATCH 21/23] Switch away from virHashFree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use 'g_clear_pointer(&ptr, g_hash_table_unref)' instead.

In few instances it allows us to also remove explicit clearing of
pointers.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_addr.c                 |  2 +-
 src/conf/domain_conf.c                 |  2 +-
 src/conf/nwfilter_conf.c               |  2 +-
 src/conf/nwfilter_ipaddrmap.c          |  3 +--
 src/conf/virchrdev.c                   |  2 +-
 src/conf/virdomainmomentobjlist.c      |  2 +-
 src/conf/virdomainobjlist.c            |  4 ++--
 src/conf/virinterfaceobj.c             |  2 +-
 src/conf/virnetworkobj.c               |  4 ++--
 src/conf/virnodedeviceobj.c            |  2 +-
 src/conf/virnwfilterbindingdef.c       |  2 +-
 src/conf/virnwfilterbindingobjlist.c   |  2 +-
 src/conf/virsecretobj.c                |  2 +-
 src/conf/virstorageobj.c               | 10 +++++-----
 src/hyperv/hyperv_wmi.c                |  2 +-
 src/hypervisor/virclosecallbacks.c     |  2 +-
 src/libxl/libxl_logger.c               |  2 +-
 src/locking/lock_daemon.c              |  2 +-
 src/nwfilter/nwfilter_dhcpsnoop.c      |  6 +++---
 src/nwfilter/nwfilter_gentech_driver.c |  2 +-
 src/nwfilter/nwfilter_learnipaddr.c    |  7 ++-----
 src/qemu/qemu_domain.c                 |  2 +-
 src/qemu/qemu_driver.c                 |  2 +-
 src/rpc/virnetdaemon.c                 |  2 +-
 src/security/security_selinux.c        |  6 +++---
 src/util/virfilecache.c                |  2 +-
 src/util/virhash.c                     |  2 +-
 src/util/virlockspace.c                |  2 +-
 src/util/virmacmap.c                   |  2 +-
 src/util/virsystemd.c                  |  2 +-
 tests/nwfilterxml2firewalltest.c       |  2 +-
 tests/qemusecuritymock.c               |  7 +++----
 32 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index a06721c35d..49745ba881 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1377,7 +1377,7 @@ void virDomainCCWAddressSetFree(virDomainCCWAddressSet *addrs)
     if (!addrs)
         return;

-    virHashFree(addrs->defined);
+    g_clear_pointer(&addrs->defined, g_hash_table_unref);
     g_free(addrs);
 }

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 25e504a99a..9be5a94680 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2640,7 +2640,7 @@ virDomainNetDefFree(virDomainNetDef *def)
     virDomainDeviceInfoClear(&def->info);

     g_free(def->filter);
-    virHashFree(def->filterparams);
+    g_clear_pointer(&def->filterparams, g_hash_table_unref);

     virNetDevBandwidthFree(def->bandwidth);
     virNetDevVlanClear(&def->vlan);
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index a3109962af..3fedfdde56 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -323,7 +323,7 @@ virNWFilterIncludeDefFree(virNWFilterIncludeDef *inc)
 {
     if (!inc)
         return;
-    virHashFree(inc->params);
+    g_clear_pointer(&inc->params, g_hash_table_unref);
     g_free(inc->filterref);
     g_free(inc);
 }
diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c
index bc21c80536..e2f123b9d9 100644
--- a/src/conf/nwfilter_ipaddrmap.c
+++ b/src/conf/nwfilter_ipaddrmap.c
@@ -156,6 +156,5 @@ virNWFilterIPAddrMapInit(void)
 void
 virNWFilterIPAddrMapShutdown(void)
 {
-    virHashFree(ipAddressMap);
-    ipAddressMap = NULL;
+    g_clear_pointer(&ipAddressMap, g_hash_table_unref);
 }
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 5d6de68427..b5477b03d5 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -295,7 +295,7 @@ void virChrdevFree(virChrdevs *devs)

     virMutexLock(&devs->lock);
     virHashForEachSafe(devs->hash, virChrdevFreeClearCallbacks, NULL);
-    virHashFree(devs->hash);
+    g_clear_pointer(&devs->hash, g_hash_table_unref);
     virMutexUnlock(&devs->lock);
     virMutexDestroy(&devs->lock);

diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
index 17b9c16ae7..60f7eec106 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -282,7 +282,7 @@ virDomainMomentObjListFree(virDomainMomentObjList *moments)
 {
     if (!moments)
         return;
-    virHashFree(moments->objs);
+    g_clear_pointer(&moments->objs, g_hash_table_unref);
     g_free(moments);
 }

diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 063c63cd30..9be1e7ad7d 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -85,8 +85,8 @@ static void virDomainObjListDispose(void *obj)
 {
     virDomainObjList *doms = obj;

-    virHashFree(doms->objs);
-    virHashFree(doms->objsName);
+    g_clear_pointer(&doms->objs, g_hash_table_unref);
+    g_clear_pointer(&doms->objsName, g_hash_table_unref);
 }


diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index daac74e88c..9d75be6425 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -345,7 +345,7 @@ virInterfaceObjListDispose(void *obj)
 {
     virInterfaceObjList *interfaces = obj;

-    virHashFree(interfaces->objsName);
+    g_clear_pointer(&interfaces->objsName, g_hash_table_unref);
 }


diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index f1baffc516..41c7dcba5c 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -464,7 +464,7 @@ virNetworkObjDispose(void *opaque)
 {
     virNetworkObj *obj = opaque;

-    virHashFree(obj->ports);
+    g_clear_pointer(&obj->ports, g_hash_table_unref);
     virNetworkDefFree(obj->def);
     virNetworkDefFree(obj->newDef);
     virBitmapFree(obj->classIdMap);
@@ -477,7 +477,7 @@ virNetworkObjListDispose(void *opaque)
 {
     virNetworkObjList *nets = opaque;

-    virHashFree(nets->objs);
+    g_clear_pointer(&nets->objs, g_hash_table_unref);
 }


diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 15898a6aa7..2e4ef2df3c 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -453,7 +453,7 @@ virNodeDeviceObjListDispose(void *obj)
 {
     virNodeDeviceObjList *devs = obj;

-    virHashFree(devs->objs);
+    g_clear_pointer(&devs->objs, g_hash_table_unref);
 }


diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c
index 488fdbceab..c55a5d28dc 100644
--- a/src/conf/virnwfilterbindingdef.c
+++ b/src/conf/virnwfilterbindingdef.c
@@ -40,7 +40,7 @@ virNWFilterBindingDefFree(virNWFilterBindingDef *def)
     g_free(def->portdevname);
     g_free(def->linkdevname);
     g_free(def->filter);
-    virHashFree(def->filterparams);
+    g_clear_pointer(&def->filterparams, g_hash_table_unref);

     g_free(def);
 }
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 212cca2265..03441c9c1b 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -77,7 +77,7 @@ virNWFilterBindingObjListDispose(void *obj)
 {
     virNWFilterBindingObjList *bindings = obj;

-    virHashFree(bindings->objs);
+    g_clear_pointer(&bindings->objs, g_hash_table_unref);
 }


diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 3fbee6f6ec..a88f28fdda 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -149,7 +149,7 @@ virSecretObjListDispose(void *obj)
 {
     virSecretObjList *secrets = obj;

-    virHashFree(secrets->objs);
+    g_clear_pointer(&secrets->objs, g_hash_table_unref);
 }


diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 2c29339b6a..02903ac487 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -183,9 +183,9 @@ virStorageVolObjListDispose(void *opaque)
 {
     virStorageVolObjList *vols = opaque;

-    virHashFree(vols->objsKey);
-    virHashFree(vols->objsName);
-    virHashFree(vols->objsPath);
+    g_clear_pointer(&vols->objsKey, g_hash_table_unref);
+    g_clear_pointer(&vols->objsName, g_hash_table_unref);
+    g_clear_pointer(&vols->objsPath, g_hash_table_unref);
 }


@@ -382,8 +382,8 @@ virStoragePoolObjListDispose(void *opaque)
 {
     virStoragePoolObjList *pools = opaque;

-    virHashFree(pools->objs);
-    virHashFree(pools->objsName);
+    g_clear_pointer(&pools->objs, g_hash_table_unref);
+    g_clear_pointer(&pools->objsName, g_hash_table_unref);
 }


diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index e211fd5d80..6712ef4835 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -357,7 +357,7 @@ hypervAddEmbeddedParam(hypervInvokeParamsList *params,
 void
 hypervFreeEmbeddedParam(GHashTable *p)
 {
-    virHashFree(p);
+    g_clear_pointer(&p, g_hash_table_unref);
 }


diff --git a/src/hypervisor/virclosecallbacks.c b/src/hypervisor/virclosecallbacks.c
index 2578a71f03..84a61b002a 100644
--- a/src/hypervisor/virclosecallbacks.c
+++ b/src/hypervisor/virclosecallbacks.c
@@ -78,7 +78,7 @@ virCloseCallbacksDispose(void *obj)
 {
     virCloseCallbacks *closeCallbacks = obj;

-    virHashFree(closeCallbacks->list);
+    g_clear_pointer(&closeCallbacks->list, g_hash_table_unref);
 }

 int
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index 4692578124..d176c2a7c2 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -166,7 +166,7 @@ libxlLoggerFree(libxlLogger *logger)
     xentoollog_logger *xtl_logger = (xentoollog_logger*)logger;
     if (logger->defaultLogFile)
         VIR_FORCE_FCLOSE(logger->defaultLogFile);
-    virHashFree(logger->files);
+    g_clear_pointer(&logger->files, g_hash_table_unref);
     xtl_logger_destroy(xtl_logger);
 }

diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index faca4a2485..cf33d9732b 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -89,7 +89,7 @@ virLockDaemonFree(virLockDaemon *lockd)

     g_mutex_clear(&lockd->lock);
     virObjectUnref(lockd->dmn);
-    virHashFree(lockd->lockspaces);
+    g_clear_pointer(&lockd->lockspaces, g_hash_table_unref);
     virLockSpaceFree(lockd->defaultLockspace);

     g_free(lockd);
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index b0297f0741..386e7640c2 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -2080,13 +2080,13 @@ virNWFilterDHCPSnoopShutdown(void)
     virNWFilterSnoopLock();

     virNWFilterSnoopLeaseFileClose();
-    virHashFree(virNWFilterSnoopState.ifnameToKey);
-    virHashFree(virNWFilterSnoopState.snoopReqs);
+    g_clear_pointer(&virNWFilterSnoopState.ifnameToKey, g_hash_table_unref);
+    g_clear_pointer(&virNWFilterSnoopState.snoopReqs, g_hash_table_unref);

     virNWFilterSnoopUnlock();

     virNWFilterSnoopActiveLock();
-    virHashFree(virNWFilterSnoopState.active);
+    g_clear_pointer(&virNWFilterSnoopState.active, g_hash_table_unref);
     virNWFilterSnoopActiveUnlock();
 }

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index ea1f4f4092..20ecd299bf 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -121,7 +121,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInst *inst)
     if (!inst)
         return;

-    virHashFree(inst->vars);
+    g_clear_pointer(&inst->vars, g_hash_table_unref);
     g_free(inst);
 }

diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 2177c5540b..fb552bd1e6 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -805,9 +805,6 @@ virNWFilterLearnShutdown(void)

     virNWFilterLearnThreadsTerminate(false);

-    virHashFree(pendingLearnReq);
-    pendingLearnReq = NULL;
-
-    virHashFree(ifaceLockMap);
-    ifaceLockMap = NULL;
+    g_clear_pointer(&pendingLearnReq, g_hash_table_unref);
+    g_clear_pointer(&ifaceLockMap, g_hash_table_unref);
 }
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3dfc79f61e..c79a7570de 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1701,7 +1701,7 @@ qemuDomainObjPrivateFree(void *data)
     g_clear_pointer(&priv->migSecinfo, qemuDomainSecretInfoFree);
     qemuDomainMasterKeyFree(priv);

-    virHashFree(priv->blockjobs);
+    g_clear_pointer(&priv->blockjobs, g_hash_table_unref);

     /* This should never be non-NULL if we get here, but just in case... */
     if (priv->eventThread) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4fcd6190d1..00a621d9f8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1084,7 +1084,7 @@ qemuStateCleanup(void)
     virPortAllocatorRangeFree(qemu_driver->migrationPorts);
     virPortAllocatorRangeFree(qemu_driver->webSocketPorts);
     virPortAllocatorRangeFree(qemu_driver->remotePorts);
-    virHashFree(qemu_driver->sharedDevices);
+    g_clear_pointer(&qemu_driver->sharedDevices, g_hash_table_unref);
     virObjectUnref(qemu_driver->hostdevMgr);
     virObjectUnref(qemu_driver->securityManager);
     virObjectUnref(qemu_driver->domainEventState);
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index 444fe3dbe7..c946e4a92a 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -110,7 +110,7 @@ virNetDaemonDispose(void *obj)
     VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd);
     g_free(dmn->stateStopThread);

-    virHashFree(dmn->servers);
+    g_clear_pointer(&dmn->servers, g_hash_table_unref);

     virJSONValueFree(dmn->srvObject);
 }
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 5682d2bb9d..0952431064 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -692,7 +692,7 @@ virSecuritySELinuxLXCInitialize(virSecurityManager *mgr)
     VIR_FREE(data->domain_context);
     VIR_FREE(data->file_context);
     VIR_FREE(data->content_context);
-    virHashFree(data->mcs);
+    g_clear_pointer(&data->mcs, g_hash_table_unref);
     return -1;
 }

@@ -764,7 +764,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManager *mgr)
     VIR_FREE(data->alt_domain_context);
     VIR_FREE(data->file_context);
     VIR_FREE(data->content_context);
-    virHashFree(data->mcs);
+    g_clear_pointer(&data->mcs, g_hash_table_unref);
     return -1;
 }

@@ -1030,7 +1030,7 @@ virSecuritySELinuxDriverClose(virSecurityManager *mgr)
     if (data->label_handle)
         selabel_close(data->label_handle);

-    virHashFree(data->mcs);
+    g_clear_pointer(&data->mcs, g_hash_table_unref);

     VIR_FREE(data->domain_context);
     VIR_FREE(data->alt_domain_context);
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index 64348dc1e6..c140f9d5ea 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -77,7 +77,7 @@ virFileCacheDispose(void *obj)
     g_free(cache->dir);
     g_free(cache->suffix);

-    virHashFree(cache->table);
+    g_clear_pointer(&cache->table, g_hash_table_unref);

     virFileCachePrivFree(cache);
 }
diff --git a/src/util/virhash.c b/src/util/virhash.c
index a9996c9fc0..cc6053f28d 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -112,7 +112,7 @@ virHashAtomicDispose(void *obj)
 {
     virHashAtomic *hash = obj;

-    virHashFree(hash->hash);
+    g_clear_pointer(&hash->hash, g_hash_table_unref);
 }


diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 46bd922f35..a7f1c2324f 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -477,7 +477,7 @@ void virLockSpaceFree(virLockSpace *lockspace)
     if (!lockspace)
         return;

-    virHashFree(lockspace->resources);
+    g_clear_pointer(&lockspace->resources, g_hash_table_unref);
     g_free(lockspace->dir);
     virMutexDestroy(&lockspace->lock);
     g_free(lockspace);
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index fb16062cd1..0b7b758c6d 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -62,7 +62,7 @@ virMacMapDispose(void *obj)
     while (g_hash_table_iter_next(&htitr, NULL, &value))
         g_slist_free_full(value, g_free);

-    virHashFree(mgr->macs);
+    g_clear_pointer(&mgr->macs, g_hash_table_unref);
 }


diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 99c92b6f52..a86d4c6bb9 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -1108,7 +1108,7 @@ virSystemdActivationFree(virSystemdActivation *act)
     if (!act)
         return;

-    virHashFree(act->fds);
+    g_clear_pointer(&act->fds, g_hash_table_unref);

     g_free(act);
 }
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index 315afddca0..857214dde5 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -166,7 +166,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInst *inst)
     if (!inst)
         return;

-    virHashFree(inst->vars);
+    g_clear_pointer(&inst->vars, g_hash_table_unref);
     g_free(inst);
 }

diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c
index f092383b62..778b0561ac 100644
--- a/tests/qemusecuritymock.c
+++ b/tests/qemusecuritymock.c
@@ -502,10 +502,9 @@ void freePaths(void)
     virMutexLock(&m);
     init_hash();

-    virHashFree(selinux_paths);
-    virHashFree(chown_paths);
-    virHashFree(xattr_paths);
-    selinux_paths = chown_paths = xattr_paths = NULL;
+    g_clear_pointer(&selinux_paths, g_hash_table_unref);
+    g_clear_pointer(&chown_paths, g_hash_table_unref);
+    g_clear_pointer(&xattr_paths, g_hash_table_unref);
     virMutexUnlock(&m);
 }

-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux