]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: fix attaching net device of type hostdev
authorJim Fehlig <jfehlig@suse.com>
Wed, 30 Mar 2016 20:57:29 +0000 (14:57 -0600)
committerJim Fehlig <jfehlig@suse.com>
Thu, 31 Mar 2016 16:17:28 +0000 (10:17 -0600)
Chunyan sent a correct patch to fix a resource leak on error in
libxlDomainAttachNetDevice

https://www.redhat.com/archives/libvir-list/2016-March/msg00924.html

I made what was thought to be an improvement and pushed the patch as
commit e6336442. As it turns out, my change broke adding net devices
that are actually hostdevs to the list of nets in virDomainDef. This
patch changes e6336442 to resemble Chunyan's original, correct
patch.

src/libxl/libxl_driver.c

index 510349595fb31839d67b55a75a9a191f287b48a5..9955cc7bbbee7fe5acbbd65a7ff449c1a73d233d 100644 (file)
@@ -3174,12 +3174,13 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
         goto cleanup;
     }
 
-    vm->def->nets[vm->def->nnets++] = net;
     ret = 0;
 
  cleanup:
     libxl_device_nic_dispose(&nic);
-    if (ret) {
+    if (!ret) {
+        vm->def->nets[vm->def->nnets++] = net;
+    } else {
         virDomainNetRemoveHostdev(vm->def, net);
         networkReleaseActualDevice(vm->def, net);
     }