From: Prasad Joshi Date: Sun, 22 May 2011 16:24:07 +0000 (+0100) Subject: kvm tools: Release memory allocated during virtio block initialization X-Git-Tag: next-20110824~3^2~269 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=a8adaa363de7d212aa306494f58eb6809ee2855e;p=karo-tx-linux.git kvm tools: Release memory allocated during virtio block initialization 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 Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h index 72f649106605..8c4fb9199177 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 eacde818b70b..288e1fbe530a 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -617,6 +617,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 224e14c433b9..25ce61f8ef53 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->nr_disks; i++) virtio_blk__init(kvm, kvm->disks[i]); } + +void virtio_blk__delete_all(struct kvm *kvm) +{ + int i; + + for (i = 0; i < kvm->nr_disks; i++) + free(bdevs[i]); +}