virsh: Resolve Coverity DEADCODE

Since 0766783abb

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@redhat.com>
This commit is contained in:
John Ferlan
2014-09-11 08:03:37 -04:00
parent f832aa3222
commit daf27d4d82
7 changed files with 0 additions and 29 deletions
-9
View File
@@ -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@redhat.com>
*/
@@ -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