[PATCH 07/26] virsh: Resolve Coverity DEADCODE

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

 



Since 0766783abbe8bbc9ea686c2c3149f4c0ac139e19

Coverity complains that the EDIT_FREE definition results in DEADCODE.

As it turns out with the change to use the EDIT_FREE macro the call to
vir*Free() wouldn't be necessary nor would it happen...

Prior code to above commitid would :

  vir*Ptr foo = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  vir*Free(foo);
  foo = vir*DefineXML()
  ...

And thus the free was needed.  With the change to use EDIT_FREE the
same code changed to:

  vir*Ptr foo = NULL;
  vir*Ptr foo_edited = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  if (foo_edited)
      vir*Free(foo_edited);
  foo_edited = vir*DefineXML()
  ...

However, foo_edited could never be set in the code path - even with
all the goto's since the only way for it to be set is if vir*DefineXML()
succeeds in which case the code to allow a retry (and thus all the goto's)
never leaves foo_edited set

All error paths lead to "cleanup:" which causes both foo and foo_edited
to call the respective vir*Free() routines if set.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 tools/virsh-domain.c    | 5 -----
 tools/virsh-edit.c      | 9 ---------
 tools/virsh-interface.c | 3 ---
 tools/virsh-network.c   | 3 ---
 tools/virsh-nwfilter.c  | 3 ---
 tools/virsh-pool.c      | 3 ---
 tools/virsh-snapshot.c  | 3 ---
 7 files changed, 29 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 68d49d6..1cdb596 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4032,7 +4032,6 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (virDomainSaveImageDefineXML(ctl->conn, file, doc_edited, define_flags) == 0)
-#define EDIT_FREE /* */
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("State file %s edited.\n"), file);
@@ -7162,7 +7161,6 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
 #define EDIT_DEFINE                                                         \
         (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited, \
                               key, uri, flags) == 0)
-#define EDIT_FREE /* nothing */
 #include "virsh-edit.c"
 
         vshPrint("%s\n", _("Metadata modified"));
@@ -10656,9 +10654,6 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (dom_edited = virDomainDefineXML(ctl->conn, doc_edited))
-#define EDIT_FREE \
-    if (dom_edited) \
-        virDomainFree(dom_edited);
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c
index 5d35c55..10298f6 100644
--- a/tools/virsh-edit.c
+++ b/tools/virsh-edit.c
@@ -40,9 +40,6 @@
  *      For example:
  *      #define EDIT_DEFINE (dom_edited = virDomainDefineXML(ctl->conn, doc_edited))
  *
- * EDIT_FREE - statement which vir*Free()-s object defined by EDIT_DEFINE, e.g:
- *      #define EDIT_FREE if (dom_edited) virDomainFree(dom_edited);
- *
  * Michal Privoznik <mprivozn@xxxxxxxxxx>
  */
 
@@ -58,10 +55,6 @@
 # error Missing EDIT_DEFINE definition
 #endif
 
-#ifndef EDIT_FREE
-# error Missing EDIT_FREE definition
-#endif
-
 do {
     char *tmp = NULL;
     char *doc = NULL;
@@ -116,7 +109,6 @@ do {
     }
 
     /* Everything checks out, so redefine the object. */
-    EDIT_FREE;
     if (!msg && !(EDIT_DEFINE)) {
         msg = _("Failed.");
     }
@@ -162,4 +154,3 @@ do {
 #undef EDIT_GET_XML
 #undef EDIT_NOT_CHANGED
 #undef EDIT_DEFINE
-#undef EDIT_FREE
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index d4ec854..6cacaf1 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -128,9 +128,6 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (iface_edited = virInterfaceDefineXML(ctl->conn, doc_edited, 0))
-#define EDIT_FREE \
-    if (iface_edited)   \
-        virInterfaceFree(iface_edited);
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("Interface %s XML configuration edited.\n"),
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 9497472..5fe4b32 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -1111,9 +1111,6 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (network_edited = virNetworkDefineXML(ctl->conn, doc_edited))
-#define EDIT_FREE \
-    if (network_edited) \
-        virNetworkFree(network_edited);
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("Network %s XML configuration edited.\n"),
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 6e6e21b..ca54c9d 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -428,9 +428,6 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (nwfilter_edited = virNWFilterDefineXML(ctl->conn, doc_edited))
-#define EDIT_FREE \
-    if (nwfilter_edited)    \
-        virNWFilterFree(nwfilter);
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 80313b1..0b8dba5 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1767,9 +1767,6 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true; goto edit_cleanup;
 #define EDIT_DEFINE \
     (pool_edited = virStoragePoolDefineXML(ctl->conn, doc_edited, 0))
-#define EDIT_FREE \
-    if (pool_edited)    \
-        virStoragePoolFree(pool_edited);
 #include "virsh-edit.c"
 
     vshPrint(ctl, _("Pool %s XML configuration edited.\n"),
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 3ecb3de..885ad22 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -589,9 +589,6 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
     (strstr(doc, "<state>disk-snapshot</state>") ? \
     define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0), \
     edited = virDomainSnapshotCreateXML(dom, doc_edited, define_flags)
-#define EDIT_FREE \
-    if (edited) \
-        virDomainSnapshotFree(edited);
 #include "virsh-edit.c"
 
     edited_name = virDomainSnapshotGetName(edited);
-- 
1.9.3

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