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