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

leixiang
2024-06-18T07:53:09Z

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