[PATCH 02/10] xen_common: Resolve Coverity USE_AFTER_FREE

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

 



There were two warnings in this module

  If the VIR_ALLOC_N(def->serials, 1) fails, then a virDomainChrDefFree(chr)
  is called and we jump to cleanup which makes the same call. Just remove
  the one after VIR_ALLOC_N()

  In the label "skipnic:" a virDomainNetDefFree(net) is made; however, if
  in going back to the top of the loop we jump back down to skipnic for any
  reason, the call will attempt to free an already freed structure since
  "net" was not passed by reference to virDomainNetDefFree().  Just set
  net = NULL in skipnic: to resolve the issue.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/xenconfig/xen_common.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 2f53c63..9beaf6c 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -776,10 +776,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def)
                 !(chr = xenParseSxprChar(str, NULL)))
                 goto cleanup;
             if (chr) {
-                if (VIR_ALLOC_N(def->serials, 1) < 0) {
-                    virDomainChrDefFree(chr);
+                if (VIR_ALLOC_N(def->serials, 1) < 0)
                     goto cleanup;
-                }
                 chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
                 chr->target.port = 0;
                 def->serials[0] = chr;
@@ -953,6 +951,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def)
         skipnic:
             list = list->next;
             virDomainNetDefFree(net);
+            net = NULL;
             VIR_FREE(script);
         }
     }
-- 
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]