]> xenbits.xensource.com Git - libvirt.git/commitdiff
Coverity: Resolve a RESOURCE_LEAK
authorJohn Ferlan <jferlan@redhat.com>
Tue, 25 Mar 2014 17:09:05 +0000 (13:09 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 25 Mar 2014 21:19:49 +0000 (17:19 -0400)
On error the lofd would have been leaked.

src/lxc/lxc_controller.c

index 800a306cfd5af6878147156e6c5748d38717d963..3bc15cc5fe6a8fb837c1a70b2554a2905f8bbfda 100644 (file)
@@ -383,6 +383,7 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
     int lofd;
     char *loname = NULL;
     const char *src = virDomainDiskGetSource(disk);
+    int ret = -1;
 
     if ((lofd = virFileLoopDeviceAssociate(src, &loname)) < 0)
         return -1;
@@ -395,13 +396,18 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
      * the rest of container setup 'just works'
      */
     virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
-    if (virDomainDiskSetSource(disk, loname) < 0) {
-        VIR_FREE(loname);
-        return -1;
-    }
+    if (virDomainDiskSetSource(disk, loname) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
     VIR_FREE(loname);
+    if (ret < 0)
+         VIR_FORCE_CLOSE(lofd);
 
     return lofd;
+
 }