[PATCH 7/8] don't check for NULL before calling virHashFree

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

 



virHashFree follows the convention described in HACKING that
XXXFree() functions can be called with a NULL argument.
---
 src/conf/domain_conf.c |    6 +---
 src/datatypes.c        |   51 ++++++++++++++++--------------------------------
 src/qemu/qemu_driver.c |    4 +--
 3 files changed, 20 insertions(+), 41 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b780c74..8129829 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -405,8 +405,7 @@ static void virDomainObjListDeallocator(void *payload, const char *name ATTRIBUT
 
 void virDomainObjListDeinit(virDomainObjListPtr doms)
 {
-    if (doms->objs)
-        virHashFree(doms->objs, virDomainObjListDeallocator);
+    virHashFree(doms->objs, virDomainObjListDeallocator);
 }
 
 
@@ -8738,8 +8737,7 @@ static void virDomainSnapshotObjListDeallocator(void *payload,
 
 static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr snapshots)
 {
-    if (snapshots->objs)
-        virHashFree(snapshots->objs, virDomainSnapshotObjListDeallocator);
+    virHashFree(snapshots->objs, virDomainSnapshotObjListDeallocator);
 }
 
 struct virDomainSnapshotNameData {
diff --git a/src/datatypes.c b/src/datatypes.c
index e26e332..4f7373c 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -209,22 +209,14 @@ virGetConnect(void) {
 
 failed:
     if (ret != NULL) {
-        if (ret->domains != NULL)
-            virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
-        if (ret->networks != NULL)
-            virHashFree(ret->networks, (virHashDeallocator) virNetworkFreeName);
-        if (ret->interfaces != NULL)
-           virHashFree(ret->interfaces, (virHashDeallocator) virInterfaceFreeName);
-        if (ret->storagePools != NULL)
-            virHashFree(ret->storagePools, (virHashDeallocator) virStoragePoolFreeName);
-        if (ret->storageVols != NULL)
-            virHashFree(ret->storageVols, (virHashDeallocator) virStorageVolFreeName);
-        if (ret->nodeDevices != NULL)
-            virHashFree(ret->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
-        if (ret->secrets != NULL)
-            virHashFree(ret->secrets, (virHashDeallocator) virSecretFreeName);
-        if (ret->nwfilters != NULL)
-            virHashFree(ret->nwfilters, (virHashDeallocator) virNWFilterFreeName);
+        virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
+        virHashFree(ret->networks, (virHashDeallocator) virNetworkFreeName);
+        virHashFree(ret->interfaces, (virHashDeallocator) virInterfaceFreeName);
+        virHashFree(ret->storagePools, (virHashDeallocator) virStoragePoolFreeName);
+        virHashFree(ret->storageVols, (virHashDeallocator) virStorageVolFreeName);
+        virHashFree(ret->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
+        virHashFree(ret->secrets, (virHashDeallocator) virSecretFreeName);
+        virHashFree(ret->nwfilters, (virHashDeallocator) virNWFilterFreeName);
 
         virMutexDestroy(&ret->lock);
         VIR_FREE(ret);
@@ -267,22 +259,14 @@ virReleaseConnect(virConnectPtr conn) {
 
     virMutexLock(&conn->lock);
 
-    if (conn->domains != NULL)
-        virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
-    if (conn->networks != NULL)
-        virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
-    if (conn->interfaces != NULL)
-        virHashFree(conn->interfaces, (virHashDeallocator) virInterfaceFreeName);
-    if (conn->storagePools != NULL)
-        virHashFree(conn->storagePools, (virHashDeallocator) virStoragePoolFreeName);
-    if (conn->storageVols != NULL)
-        virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
-    if (conn->nodeDevices != NULL)
-        virHashFree(conn->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
-    if (conn->secrets != NULL)
-        virHashFree(conn->secrets, (virHashDeallocator) virSecretFreeName);
-    if (conn->nwfilters != NULL)
-        virHashFree(conn->nwfilters, (virHashDeallocator) virNWFilterFreeName);
+    virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
+    virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
+    virHashFree(conn->interfaces, (virHashDeallocator) virInterfaceFreeName);
+    virHashFree(conn->storagePools, (virHashDeallocator) virStoragePoolFreeName);
+    virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
+    virHashFree(conn->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
+    virHashFree(conn->secrets, (virHashDeallocator) virSecretFreeName);
+    virHashFree(conn->nwfilters, (virHashDeallocator) virNWFilterFreeName);
 
     virResetError(&conn->err);
 
@@ -429,8 +413,7 @@ virReleaseDomain(virDomainPtr domain) {
     domain->magic = -1;
     domain->id = -1;
     VIR_FREE(domain->name);
-    if (domain->snapshots != NULL)
-        virHashFree(domain->snapshots, (virHashDeallocator) virDomainSnapshotFreeName);
+    virHashFree(domain->snapshots, (virHashDeallocator) virDomainSnapshotFreeName);
     VIR_FREE(domain);
 
     if (conn) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fa462f9..495ad05 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1870,9 +1870,7 @@ qemudWaitForMonitor(struct qemud_driver* driver,
     }
 
 cleanup:
-    if (paths) {
-        virHashFree(paths, qemudFreePtyPath);
-    }
+    virHashFree(paths, qemudFreePtyPath);
 
     if (kill(vm->pid, 0) == -1 && errno == ESRCH) {
         /* VM is dead, any other error raised in the interim is probably
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]