Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: sm_ftl: Fix memory leak in sm_init_zone() error path

In sm_init_zone(), 'zone->lba_to_phys_table' is allocated through
kmalloc_array() and 'zone->free_sectors' is allocated in kfifo_alloc()
respectively. However, they are not deallocated in the following execution
if sm_read_sector() fails, leading to memory leaks. To fix this issue, free
them before returning -EIO.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Wenwen Wang and committed by
Richard Weinberger
137e92fd a3f12a35

+4 -1
+4 -1
drivers/mtd/sm_ftl.c
··· 774 774 continue; 775 775 776 776 /* Read the oob of first sector */ 777 - if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob)) 777 + if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob)) { 778 + kfifo_free(&zone->free_sectors); 779 + kfree(zone->lba_to_phys_table); 778 780 return -EIO; 781 + } 779 782 780 783 /* Test to see if block is erased. It is enough to test 781 784 first sector, because erase happens in one shot */