[PATCH] kvm tools:Fix memory leakage in open all disks

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

 



Fix memory leakage in disk/core disk_image__open_all when malloc disk failed,
should free the disks that already malloced.

Signed-off-by: Lei Xiang <leixiang@xxxxxxxxxx>
Suggested-by: Xie Ming <xieming@xxxxxxxxxx>
---
 disk/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/disk/core.c b/disk/core.c
index dd2f258..affeece 100644
--- a/disk/core.c
+++ b/disk/core.c
@@ -195,8 +195,10 @@ static struct disk_image **disk_image__open_all(struct kvm *kvm)
 
 		if (wwpn) {
 			disks[i] = malloc(sizeof(struct disk_image));
-			if (!disks[i])
-				return ERR_PTR(-ENOMEM);
+			if (!disks[i]) {
+				err = ERR_PTR(-ENOMEM);
+				goto error;
+			}
 			disks[i]->wwpn = wwpn;
 			disks[i]->tpgt = tpgt;
 			continue;
-- 
2.34.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux