[lkml]   [2013]   [Jan]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subjectslob: Check for NULL pointer before calling ctor()
While doing some code inspection, I noticed that the slob constructor
method can be called with a NULL pointer. If memory is tight and slob
fails to allocate with slob_alloc() or slob_new_pages() it still calls
the ctor() method with a NULL pointer. Looking at the first ctor()
method I found, I noticed that it can not handle a NULL pointer (I'm
sure others probably can't either):

static void sighand_ctor(void *data)
struct sighand_struct *sighand = data;


The solution is to only call the ctor() method if allocation succeeded.

Signed-off-by: Steven Rostedt <>

diff --git a/mm/slob.c b/mm/slob.c
index a99fdf7..48fcb90 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -554,7 +554,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
flags, node);

- if (c->ctor)
+ if (b && c->ctor)

kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);

 \ /
  Last update: 2013-01-17 18:43    [W:0.023 / U:1.904 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site