summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Wegener <sven.wegener@stealer.net>2008-08-20 14:09:07 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2008-08-20 15:40:30 -0700
commitf3944d61ddc65722539ffd7b6f5b7c7217c136cc (patch)
treedd48fb10e38df546535b1b3aa576aec79937e4ac
parent759f9a2df78d2156a2675edc7999fb4c919a3159 (diff)
downloadlinux-3.10-f3944d61ddc65722539ffd7b6f5b7c7217c136cc.tar.gz
linux-3.10-f3944d61ddc65722539ffd7b6f5b7c7217c136cc.tar.bz2
linux-3.10-f3944d61ddc65722539ffd7b6f5b7c7217c136cc.zip
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>
-rw-r--r--drivers/block/nbd.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ad98dda6037..1778e4a2c67 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -707,15 +707,15 @@ static int __init nbd_init(void)
BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
- nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
- if (!nbd_dev)
- return -ENOMEM;
-
if (max_part < 0) {
printk(KERN_CRIT "nbd: max_part must be >= 0\n");
return -EINVAL;
}
+ nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
+ if (!nbd_dev)
+ return -ENOMEM;
+
part_shift = 0;
if (max_part > 0)
part_shift = fls(max_part);
@@ -779,6 +779,7 @@ out:
blk_cleanup_queue(nbd_dev[i].disk->queue);
put_disk(nbd_dev[i].disk);
}
+ kfree(nbd_dev);
return err;
}
@@ -795,6 +796,7 @@ static void __exit nbd_cleanup(void)
}
}
unregister_blkdev(NBD_MAJOR, "nbd");
+ kfree(nbd_dev);
printk(KERN_INFO "nbd: unregistered device at major %d\n", NBD_MAJOR);
}