[libvirt] [RFC PATCH 1/1] src: remove NULL check before VIR_FREE()

Daniel Henrique Barboza danielhb413 at gmail.com
Tue Jan 7 17:12:05 UTC 2020


Functions virDomainSoundCodecDefFree(), virCapabilitiesFreeStoragePool()
and virStorageSourceNVMeDefFree() are doing 'if (ptr)' NULL
checks right before a 'VIR_FREE(ptr)' call.

VIR_FREE() is a wrapper for g_free(). g_free(mem) documentation [1]
states:

'If mem is NULL it simply returns, so there is no need to check mem
against NULL before calling this function.'

This patch removes these needless NULL checks. The
virDomainSoundCodecDefFree() instance was found by accident
via code inspection, the other 2 instances were found using
Coccinelle.

[1] https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-free

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---

Sending this one as RFC because I am unsure about its utility.

 src/conf/capabilities.c   | 3 ---
 src/conf/domain_conf.c    | 3 ---
 src/util/virstoragefile.c | 3 ---
 3 files changed, 9 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 9a39858280..4414b61fb2 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -174,9 +174,6 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest)
 static void
 virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr pool)
 {
-    if (!pool)
-        return;
-
     VIR_FREE(pool);
 }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6b05d06481..08e669daa9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2732,9 +2732,6 @@ void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def)
 
 void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def)
 {
-    if (!def)
-        return;
-
     VIR_FREE(def);
 }
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index e46ac99219..e9e74ef124 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2121,9 +2121,6 @@ virStorageSourceNVMeDefIsEqual(const virStorageSourceNVMeDef *a,
 void
 virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def)
 {
-    if (!def)
-        return;
-
     VIR_FREE(def);
 }
 
-- 
2.24.1





More information about the libvir-list mailing list