]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
xenapi: Resolve Coverity REVERSE_INULL
authorJohn Ferlan <jferlan@redhat.com>
Tue, 10 Mar 2015 23:10:34 +0000 (19:10 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 11 Mar 2015 18:38:45 +0000 (14:38 -0400)
Coverity complains that "net_set" is compared to NULL before calling
xen_network_set_free, but used rather liberally before that.  While
I was looking at the code I also noted that if the virAsprintfQuiet
fails, then we leak our structures - so I added those too.

src/xenapi/xenapi_utils.c

index ce09dfeeb31ea97ddf9c89ba684f818b2f98565d..21511e84f4bc9ce783b3b08d296ad94c5755f4e5 100644 (file)
@@ -399,14 +399,16 @@ createVifNetwork(virConnectPtr conn, xen_vm vm, int device,
     xen_network_set *net_set = NULL;
     xen_network_record *net_rec = NULL;
     int cnt = 0;
-    if (xen_network_get_all(session, &net_set)) {
-        for (cnt = 0; cnt < net_set->size; cnt++) {
-            if (xen_network_get_record(session, &net_rec, net_set->contents[cnt])) {
-                if (STREQ(net_rec->bridge, bridge)) {
-                    break;
-                } else {
-                    xen_network_record_free(net_rec);
-                }
+    if (!xen_network_get_all(session, &net_set)) {
+        xen_vm_record_opt_free(vm_opt);
+        return -1;
+    }
+    for (cnt = 0; cnt < net_set->size; cnt++) {
+        if (xen_network_get_record(session, &net_rec, net_set->contents[cnt])) {
+            if (STREQ(net_rec->bridge, bridge)) {
+                break;
+            } else {
+                xen_network_record_free(net_rec);
             }
         }
     }
@@ -425,8 +427,12 @@ createVifNetwork(virConnectPtr conn, xen_vm vm, int device,
         vif_record->other_config = xen_string_string_map_alloc(0);
         vif_record->runtime_properties = xen_string_string_map_alloc(0);
         vif_record->qos_algorithm_params = xen_string_string_map_alloc(0);
-        if (virAsprintfQuiet(&vif_record->device, "%d", device) < 0)
+        if (virAsprintfQuiet(&vif_record->device, "%d", device) < 0) {
+            xen_vif_record_free(vif_record);
+            xen_network_record_free(net_rec);
+            xen_network_set_free(net_set);
             return -1;
+        }
         xen_vif_create(session, &vif, vif_record);
         if (!vif) {
             xen_vif_free(vif);
@@ -438,7 +444,7 @@ createVifNetwork(virConnectPtr conn, xen_vm vm, int device,
         xen_vif_record_free(vif_record);
         xen_network_record_free(net_rec);
     }
-    if (net_set != NULL) xen_network_set_free(net_set);
+    xen_network_set_free(net_set);
     return -1;
 }