parlib: slab: Fix ancient ctor off-by-one The original purpose for that list was to build the chain of small slab objects. But we only ran the ctor on the first n - 1 of them. This bug is ancient - it's from the kernel's original slab implementation. We hadn't really used slab ctors a lot. Same goes for userspace, until my recent epoll changes. Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/user/parlib/slab.c b/user/parlib/slab.c index f65c263..f094c11 100644 --- a/user/parlib/slab.c +++ b/user/parlib/slab.c
@@ -274,6 +274,9 @@ *(uintptr_t**)(buf + cp->obj_size) = buf + a_slab->obj_size; buf += a_slab->obj_size; } + /* Initialize the final object (note the -1 in the for loop). */ + if (cp->ctor) + cp->ctor(buf, cp->obj_size); *((uintptr_t**)(buf + cp->obj_size)) = NULL; } else { a_slab = kmem_cache_alloc(kmem_slab_cache, 0);