omfs: Fix a memory leak bug
diff mbox series

Message ID 1566282180-10485-1-git-send-email-wenwen@cs.uga.edu
State New
Headers show
Series
  • omfs: Fix a memory leak bug
Related show

Commit Message

Wenwen Wang Aug. 20, 2019, 6:22 a.m. UTC
In omfs_get_imap(), 'sbi->s_imap' is allocated through kcalloc(). However,
it is not deallocated in the following execution if 'block' is not less
than 'sbi->s_num_blocks', leading to a memory leak bug. To fix this issue,
go to the 'nomem_free' label to free 'sbi->s_imap'.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 fs/omfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bob Copeland Aug. 20, 2019, 2:16 p.m. UTC | #1
On Tue, Aug 20, 2019 at 01:22:59AM -0500, Wenwen Wang wrote:
> In omfs_get_imap(), 'sbi->s_imap' is allocated through kcalloc(). However,
> it is not deallocated in the following execution if 'block' is not less
> than 'sbi->s_num_blocks', leading to a memory leak bug. To fix this issue,
> go to the 'nomem_free' label to free 'sbi->s_imap'.

Nice catch, thanks.

Acked-by: Bob Copeland <me@bobcopeland.com>

Patch
diff mbox series

diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c
index 08226a8..e4d89a6 100644
--- a/fs/omfs/inode.c
+++ b/fs/omfs/inode.c
@@ -356,7 +356,7 @@  static int omfs_get_imap(struct super_block *sb)
 
 	block = clus_to_blk(sbi, sbi->s_bitmap_ino);
 	if (block >= sbi->s_num_blocks)
-		goto nomem;
+		goto nomem_free;
 
 	ptr = sbi->s_imap;
 	for (count = bitmap_size; count > 0; count -= sb->s_blocksize) {