From: Wenwen Wang Date: Sun, 18 Aug 2019 15:52:49 +0000 (-0500) Subject: mtd: onenand_base: Fix a memory leak bug X-Git-Tag: v5.4-rc1~87^2~13^2~8 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=d83aef09aaa50bdafbb32981859128299abf32eb;p=linux.git mtd: onenand_base: Fix a memory leak bug In onenand_scan(), if CONFIG_MTD_ONENAND_VERIFY_WRITE is defined, 'this->verify_buf' is allocated through kzalloc(). However, it is not deallocated in the following execution, if the allocation for 'this->oob_buf' fails, leading to a memory leak bug. To fix this issue, free 'this->verify_buf' before returning the error. Signed-off-by: Wenwen Wang Signed-off-by: Miquel Raynal --- diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c index a1f8fe1abb10..dd9fced3a283 100644 --- a/drivers/mtd/nand/onenand/onenand_base.c +++ b/drivers/mtd/nand/onenand/onenand_base.c @@ -3879,6 +3879,9 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) if (!this->oob_buf) { if (this->options & ONENAND_PAGEBUF_ALLOC) { this->options &= ~ONENAND_PAGEBUF_ALLOC; +#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE + kfree(this->verify_buf); +#endif kfree(this->page_buf); } return -ENOMEM;