Skip to contentSkip to conversation

lightnvm: fix possible memory leak in pblk_bb_discovery()

PATCH In review Wei Yongjun 3 participants 3 messages Apr 25, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lightnvm: fix possible memory leak in pblk_bb_discovery()

From: Wei Yongjun <[email protected]>

'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")
---
 drivers/lightnvm/pblk-init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/lightnvm/pblk-init.c +3 -1
index 3996e4b..5c8f404 100644
@@ -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;
 }
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

'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")

---

Thanks Wei. Looks good.

maintainer
#2 lore raw
In reply to Wei Yongjun
Quoted 6 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

'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.

Added for 4.12, thanks.

Signature · 1 line
Jens Axboe