mtd: onenand_base: Fix a memory leak bug
authorWenwen Wang <wenwen@cs.uga.edu>
Sun, 18 Aug 2019 15:52:49 +0000 (10:52 -0500)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Sat, 24 Aug 2019 11:13:39 +0000 (13:13 +0200)
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 <wenwen@cs.uga.edu>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/onenand/onenand_base.c

index a1f8fe1..dd9fced 100644 (file)
@@ -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;