Skip to content

Commit

Permalink
lightnvm: fix possible memory leak in pblk_bb_discovery()
Browse files Browse the repository at this point in the history
'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: a4bd217 ("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>
  • Loading branch information
Wei Yongjun authored and Jens Axboe committed Apr 25, 2017
1 parent 543b334 commit 5136a4f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/lightnvm/pblk-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5136a4f

Please sign in to comment.