Skip to content

Commit

Permalink
ext4: fix a race which could leak memory in ext4_groupinfo_create_slab()
Browse files Browse the repository at this point in the history
In ext4_groupinfo_create_slab, we create ext4_groupinfo_caches within
ext4_grpinfo_slab_create_mutex, but set it outside the lock, and there
does exist some case that we may create it twice and causes a memory
leak.  So set it before we call mutex_unlock.

Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Tao Ma authored and Theodore Ts'o committed Jul 11, 2011
1 parent 598dbdf commit 823ba01
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2404,14 +2404,14 @@ static int ext4_groupinfo_create_slab(size_t size)
slab_size, 0, SLAB_RECLAIM_ACCOUNT,
NULL);

ext4_groupinfo_caches[cache_index] = cachep;

mutex_unlock(&ext4_grpinfo_slab_create_mutex);
if (!cachep) {
printk(KERN_EMERG "EXT4: no memory for groupinfo slab cache\n");
return -ENOMEM;
}

ext4_groupinfo_caches[cache_index] = cachep;

return 0;
}

Expand Down

0 comments on commit 823ba01

Please sign in to comment.