Skip to content

Commit

Permalink
mtd: onenand_base: Fix a memory leak bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Miquel Raynal <[email protected]>
  • Loading branch information
wenwenwang1 authored and miquelraynal committed Aug 24, 2019
1 parent 80107e7 commit d83aef0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/mtd/nand/onenand/onenand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d83aef0

Please sign in to comment.