[libvirt] [PATCH 3/3] Coverity: Resolve a RESOURCE_LEAK
John Ferlan
jferlan at redhat.com
Tue Mar 25 18:00:10 UTC 2014
On error the lofd would have been leaked.
Signed-off-by: John Ferlan <jferlan at redhat.com>
---
src/lxc/lxc_controller.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 800a306..928a43d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -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 == -1)
+ VIR_FORCE_CLOSE(lofd);
return lofd;
+
}
--
1.8.5.3
More information about the libvir-list
mailing list