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

[libvirt] [PATCH 5/5] don't check for NULL before calling virHashFree



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_process.c |    4 +--
 3 files changed, 20 insertions(+), 41 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 351daf7..e7c3409 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -410,8 +410,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);
 }
 
 
@@ -8770,8 +8769,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 d870e5d..7cc37c1 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);
 
@@ -435,8 +419,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_process.c b/src/qemu/qemu_process.c
index 46da600..f0c1e9f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1010,9 +1010,7 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
         ret = qemuProcessFindCharDevicePTYsMonitor(vm, paths);
 
 cleanup:
-    if (paths) {
-        virHashFree(paths, qemuProcessFreePtyPath);
-    }
+    virHashFree(paths, qemuProcessFreePtyPath);
 
     if (kill(vm->pid, 0) == -1 && errno == ESRCH) {
         /* VM is dead, any other error raised in the interim is probably
-- 
1.7.4


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