lightnvm: fix possible memory leak in pblk_bb_discovery()
authorWei Yongjun <weiyongjun1@huawei.com>
Tue, 25 Apr 2017 16:15:30 +0000 (16:15 +0000)
committerJens Axboe <axboe@fb.com>
Tue, 25 Apr 2017 16:44:29 +0000 (10:44 -0600)
'blks' is malloced in pblk_bb_discovery() and should be freed
before leaving from the nvm_get_tgt_bb_tbl() error handling cases,
otherwise it will cause memory leak. Also skip assign blks to
rlun->bb_list when error.

Fixes: a4bd217b4326 ("lightnvm: physical block device (pblk) target")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/pblk-init.c

index 15b2787c3ddc84c050df2355e47c4f7abed93199..ae8cd6d5af8b2998ec34fafe9a51d358ab6db552 100644 (file)
@@ -399,13 +399,15 @@ static int pblk_bb_discovery(struct nvm_tgt_dev *dev, struct pblk_lun *rlun)
 
        nr_blks = nvm_bb_tbl_fold(dev->parent, blks, nr_blks);
        if (nr_blks < 0) {
-               kfree(blks);
                ret = nr_blks;
+               goto out;
        }
 
        rlun->bb_list = blks;
 
+       return 0;
 out:
+       kfree(blks);
        return ret;
 }