[PATCH] tools: Remove unnecessary condition check

Yi Li posted 1 patch 3 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200911022452.3035597-1-yili@winhong.com
tools/virsh-domain-monitor.c | 6 ++----
tools/virsh-domain.c         | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)
[PATCH] tools: Remove unnecessary condition check
Posted by Yi Li 3 years, 6 months ago
virshDomainFree correctly handle null pointer parameters.
There is no need to check if the parameter is null before
calling this function.

Signed-off-by: Yi Li <yili@winhong.com>
---
 tools/virsh-domain-monitor.c | 6 ++----
 tools/virsh-domain.c         | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 0111116885..4c0da3c695 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1610,10 +1610,8 @@ virshDomainListFree(virshDomainListPtr domlist)
     size_t i;
 
     if (domlist && domlist->domains) {
-        for (i = 0; i < domlist->ndomains; i++) {
-            if (domlist->domains[i])
-                virshDomainFree(domlist->domains[i]);
-        }
+        for (i = 0; i < domlist->ndomains; i++)
+            virshDomainFree(domlist->domains[i]);
         VIR_FREE(domlist->domains);
     }
     VIR_FREE(domlist);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d1d3f8e566..08496cc5bf 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5509,8 +5509,7 @@ doDump(void *opaque)
     pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
  out_sig:
 #endif /* !WIN32 */
-    if (dom)
-        virshDomainFree(dom);
+    virshDomainFree(dom);
     g_main_loop_quit(data->eventLoop);
 }
 
-- 
2.25.3




Re: [PATCH] tools: Remove unnecessary condition check
Posted by Erik Skultety 3 years, 6 months ago
On Fri, Sep 11, 2020 at 10:24:52AM +0800, Yi Li wrote:
> virshDomainFree correctly handle null pointer parameters.
> There is no need to check if the parameter is null before
> calling this function.
>
> Signed-off-by: Yi Li <yili@winhong.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>