diff options
author | Sven Wegener <sven.wegener@stealer.net> | 2008-08-20 17:09:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-08-20 18:40:30 -0400 |
commit | f3944d61ddc65722539ffd7b6f5b7c7217c136cc (patch) | |
tree | dd48fb10e38df546535b1b3aa576aec79937e4ac /drivers/block/nbd.c | |
parent | 759f9a2df78d2156a2675edc7999fb4c919a3159 (diff) |
nbd: fix memory leak of nbd_dev array
We leak the memory allocated for the nbd_dev array at multiple places.
Fix them by either adding a kfree() or by rearranging code to return
before we allocate the memory.
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
Cc: Paul Clements <paul.clements@steeleye.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/nbd.c')
-rw-r--r-- | drivers/block/nbd.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index ad98dda6037d..1778e4a2c672 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c | |||
@@ -707,15 +707,15 @@ static int __init nbd_init(void) | |||
707 | 707 | ||
708 | BUILD_BUG_ON(sizeof(struct nbd_request) != 28); | 708 | BUILD_BUG_ON(sizeof(struct nbd_request) != 28); |
709 | 709 | ||
710 | nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL); | ||
711 | if (!nbd_dev) | ||
712 | return -ENOMEM; | ||
713 | |||
714 | if (max_part < 0) { | 710 | if (max_part < 0) { |
715 | printk(KERN_CRIT "nbd: max_part must be >= 0\n"); | 711 | printk(KERN_CRIT "nbd: max_part must be >= 0\n"); |
716 | return -EINVAL; | 712 | return -EINVAL; |
717 | } | 713 | } |
718 | 714 | ||
715 | nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL); | ||
716 | if (!nbd_dev) | ||
717 | return -ENOMEM; | ||
718 | |||
719 | part_shift = 0; | 719 | part_shift = 0; |
720 | if (max_part > 0) | 720 | if (max_part > 0) |
721 | part_shift = fls(max_part); | 721 | part_shift = fls(max_part); |
@@ -779,6 +779,7 @@ out: | |||
779 | blk_cleanup_queue(nbd_dev[i].disk->queue); | 779 | blk_cleanup_queue(nbd_dev[i].disk->queue); |
780 | put_disk(nbd_dev[i].disk); | 780 | put_disk(nbd_dev[i].disk); |
781 | } | 781 | } |
782 | kfree(nbd_dev); | ||
782 | return err; | 783 | return err; |
783 | } | 784 | } |
784 | 785 | ||
@@ -795,6 +796,7 @@ static void __exit nbd_cleanup(void) | |||
795 | } | 796 | } |
796 | } | 797 | } |
797 | unregister_blkdev(NBD_MAJOR, "nbd"); | 798 | unregister_blkdev(NBD_MAJOR, "nbd"); |
799 | kfree(nbd_dev); | ||
798 | printk(KERN_INFO "nbd: unregistered device at major %d\n", NBD_MAJOR); | 800 | printk(KERN_INFO "nbd: unregistered device at major %d\n", NBD_MAJOR); |
799 | } | 801 | } |
800 | 802 | ||