diff mbox

kvm tools: Fix possible leak in disk_image

Message ID 1303198336-4540-1-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin April 19, 2011, 7:32 a.m. UTC
Close leaking fd if ioctl fails.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/disk-image.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c
index 252ff1c..0fb2083 100644
--- a/tools/kvm/disk-image.c
+++ b/tools/kvm/disk-image.c
@@ -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);
 }