diff mbox

[v2,4/4] kvm tools: Release memory allocated during virtio block initialization

Message ID 1305903760-7804-4-git-send-email-prasadjoshi124@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Prasad Joshi May 20, 2011, 3:02 p.m. UTC
Add a new function virtio_blk__delete() goes through array of block
devices and releases memory allocated for block device.

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
---
 tools/kvm/include/kvm/virtio-blk.h |    1 +
 tools/kvm/kvm-run.c                |    2 ++
 tools/kvm/virtio/blk.c             |    8 ++++++++
 3 files changed, 11 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h
index 72f6491..8c4fb91 100644
--- a/tools/kvm/include/kvm/virtio-blk.h
+++ b/tools/kvm/include/kvm/virtio-blk.h
@@ -7,5 +7,6 @@  struct kvm;
 
 void virtio_blk__init(struct kvm *kvm, struct disk_image *disk);
 void virtio_blk__init_all(struct kvm *kvm);
+void virtio_blk__delete_all(struct kvm *kvm);
 
 #endif /* KVM__BLK_VIRTIO_H */
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 6b0c1fd..1acfa36 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -615,6 +615,8 @@  int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code = 1;
 	}
 
+	virtio_blk__delete_all(kvm);
+
 	disk_image__close_all(kvm->disks, image_count);
 	kvm__delete(kvm);
 
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 2ee5854..3981cb4 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -328,3 +328,11 @@  void virtio_blk__init_all(struct kvm *kvm)
 	for (i = 0; i < kvm->ndisks; i++)
 		virtio_blk__init(kvm, kvm->disks[i]);
 }
+
+void virtio_blk__delete_all(struct kvm *kvm)
+{
+	int i;
+
+	for (i = 0; i < kvm->ndisks; i++)
+		free(bdevs[i]);
+}