From: Tao Ma Date: Mon, 11 Jul 2011 22:26:01 +0000 (-0400) Subject: ext4: fix a race which could leak memory in ext4_groupinfo_create_slab() X-Git-Tag: firefly_0821_release~3680^2~4782^2~38 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=823ba01fc07751200c43e45733925a98b73eac3a;p=firefly-linux-kernel-4.4.55.git ext4: fix a race which could leak memory in ext4_groupinfo_create_slab() 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 Signed-off-by: "Theodore Ts'o" --- diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 04a3d92aafb4..2b9a71b99b2b 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -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; }