Skip to content

Commit

Permalink
slob: Check for NULL pointer before calling ctor()
Browse files Browse the repository at this point in the history
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;

        spin_lock_init(&sighand->siglock);
        init_waitqueue_head(&sighand->signalfd_wqh);
}

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

Acked-by: Christoph Lameter <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
  • Loading branch information
rostedt authored and penberg committed Jul 7, 2013
1 parent 345c905 commit c1e854e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/slob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
c->ctor(b);

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

0 comments on commit c1e854e

Please sign in to comment.