Skip to contentSkip to conversation

kvm tools: Fix possible leak in disk_image

PATCH New Sasha Levin 1 participant 1 message Apr 19, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Fix possible leak in disk_image

Close leaking fd if ioctl fails.

---
 tools/kvm/disk-image.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
tools/kvm/disk-image.c +3 -1
index 252ff1c..0fb2083 100644
@@ -120,8 +120,10 @@ static struct disk_image *blkdev__probe(const char *filename, struct stat *st)
 	if (fd < 0)
 		return NULL;
 
-	if (ioctl(fd, BLKGETSIZE64, &size) < 0)
+	if (ioctl(fd, BLKGETSIZE64, &size) < 0) {
+		close(fd);
 		return NULL;
+	}
 
 	return disk_image__new_readonly(fd, size, &raw_image_ro_mmap_ops);
 }
Signature · 1 line
1.7.5.rc1