From 490a37a599e221aded3b1630ca024563483210c0 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Mon, 26 Jun 2017 23:15:30 -0400 Subject: [PATCH] number of allocated units must be an even number --- kalloc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kalloc.c b/kalloc.c index b8d91ca..9356d40 100644 --- a/kalloc.c +++ b/kalloc.c @@ -154,6 +154,7 @@ void *kmalloc(void *_km, size_t n_bytes) /* "n_units" means the number of units. The size of one unit equals to sizeof(kheader_t). * "1" is the kheader_t of a block, which is always required. */ n_units = 1 + (n_bytes + sizeof(size_t) - 1) / sizeof(size_t); + if (n_units&1) ++n_units; /* make n_units an even number, or it will segfault if only one unit remains */ if (!(q = km->loop_head)) { /* the first time when kmalloc() is called, intialization */ km->base[1] = (size_t)(km->loop_head = q = km->base); *q = 0;