Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753698Ab0KRCyu (ORCPT ); Wed, 17 Nov 2010 21:54:50 -0500 Received: from tx2ehsobe004.messaging.microsoft.com ([65.55.88.14]:42933 "EHLO TX2EHSOBE009.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750850Ab0KRCyt (ORCPT ); Wed, 17 Nov 2010 21:54:49 -0500 X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h67dh685h62h) X-Spam-TCS-SCL: 1:0 X-Forefront-Antispam-Report: KIP:(null);UIP:(null);IPVD:NLI;H:az33egw02.freescale.net;RD:az33egw02.freescale.net;EFVD:NLI From: To: CC: , , , , , Zeng Zhaoming Subject: [PATCH] slub: operate cache name memory same to slab and slob Date: Thu, 18 Nov 2010 11:00:59 +0800 Message-ID: <1290049259-20108-1-git-send-email-b32542@freescale.com> X-Mailer: git-send-email 1.6.3.3 MIME-Version: 1.0 Content-Type: text/plain X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2917 Lines: 102 From: Zeng Zhaoming Get a memory leak complaint about ext4: comm "mount", pid 1159, jiffies 4294904647 (age 6077.804s) hex dump (first 32 bytes): 65 78 74 34 5f 67 72 6f 75 70 69 6e 66 6f 5f 31 ext4_groupinfo_1 30 00 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 0.kkkkkkkkkkkkk. backtrace: [] kmemleak_alloc+0x93/0xd0 [] __kmalloc_track_caller+0x30c/0x380 [] kstrdup+0x33/0x60 [] ext4_mb_init+0x4e0/0x550 [] ext4_fill_super+0x1e6e/0x2f60 [] mount_bdev+0x1c0/0x1f0 [] ext4_mount+0x1f/0x30 [] vfs_kern_mount+0x78/0x250 [] do_kern_mount+0x3e/0x100 [] do_mount+0x2e2/0x780 [] sys_mount+0xa4/0xd0 [] sysenter_do_call+0x12/0x38 [] 0xffffffff It is cause by slub manage the cache name different from slab and slob. In slab and slob, only reference to name, alloc and reclaim the memory is the duty of the code that invoked kmem_cache_create(). In slub, cache name duplicated when create. This ambiguity will cause some memory leaks and double free if kmem_cache_create() pass a dynamic malloc cache name. Signed-off-by: Zeng Zhaoming --- mm/slub.c | 11 +---------- 1 files changed, 1 insertions(+), 10 deletions(-) mode change 100644 => 100755 mm/slub.c diff --git a/mm/slub.c b/mm/slub.c old mode 100644 new mode 100755 index 981fb73..a223e08 --- a/mm/slub.c +++ b/mm/slub.c @@ -209,7 +209,6 @@ static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p) { return 0; } static inline void sysfs_slab_remove(struct kmem_cache *s) { - kfree(s->name); kfree(s); } @@ -3228,7 +3227,6 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align, unsigned long flags, void (*ctor)(void *)) { struct kmem_cache *s; - char *n; if (WARN_ON(!name)) return NULL; @@ -3252,25 +3250,19 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, return s; } - n = kstrdup(name, GFP_KERNEL); - if (!n) - goto err; - s = kmalloc(kmem_size, GFP_KERNEL); if (s) { - if (kmem_cache_open(s, n, + if (kmem_cache_open(s, name, size, align, flags, ctor)) { list_add(&s->list, &slab_caches); if (sysfs_slab_add(s)) { list_del(&s->list); - kfree(n); kfree(s); goto err; } up_write(&slub_lock); return s; } - kfree(n); kfree(s); } err: @@ -4421,7 +4413,6 @@ static void kmem_cache_release(struct kobject *kobj) { struct kmem_cache *s = to_slab(kobj); - kfree(s->name); kfree(s); } -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/