nbd: fix possible memory leak
Subsystems (2)
PATCH 1/1 nbd: fix possible memory leak
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 <[email protected]>
---
Hi Paul,
after seeing your mail about maintainers, just started to see the code. this patch is one way, another way can be to bring the kcalloc part below these checks.
drivers/block/nbd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/block/nbd.c +9 -4
@@ -822,11 +822,15 @@ static int __init nbd_init(void) max_part = (1UL << part_shift) -1 ; } -if ((1UL << part_shift) >DISK_MAX_PARTS ) -return -EINVAL ; +if ((1UL << part_shift) >DISK_MAX_PARTS ) { + err = -EINVAL ; + goto out_free; + } -if (nbds_max >1UL << (MINORBITS - part_shift)) -return -EINVAL ; +if (nbds_max >1UL << (MINORBITS - part_shift)) { + err = -EINVAL ; + goto out_free; + }for (i =0 ; i < nbds_max; i++) {struct gendisk *disk =alloc_disk (1 << part_shift);
@@ -889,6 +893,7 @@ out:blk_cleanup_queue (nbd_dev[i].disk->queue);put_disk (nbd_dev[i].disk); } +out_free:kfree (nbd_dev);return err; }
Signature · 1 line
1.8.1.2
Sudip,
Quoted 9 lines · Sudip Mukherjee
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 <[email protected]>---
Hi Paul,
after seeing your mail about maintainers, just started to see the code. this patch is one way, another way can be to bring the kcalloc part below these checks.
Probably better to move the kcalloc below, rather than adding more branches, wouldn't you agree?
Thanks,
Paul