Skip to content

Commit

Permalink
nbd: fix possible memory leak
Browse files Browse the repository at this point in the history
we have already allocated memory for nbd_dev, but we were not
releasing that memory and just returning the error value.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Acked-by: Paul Clements <Paul.Clements@SteelEye.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
  • Loading branch information
Sudip Mukherjee authored and Markus Pargmann committed Mar 5, 2015
1 parent c517d83 commit ff6b809
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,6 @@ static int __init nbd_init(void)
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);
Expand All @@ -828,6 +824,10 @@ static int __init nbd_init(void)
if (nbds_max > 1UL << (MINORBITS - part_shift))
return -EINVAL;

nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
if (!nbd_dev)
return -ENOMEM;

for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1 << part_shift);
if (!disk)
Expand Down

0 comments on commit ff6b809

Please sign in to comment.