scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 559919ef823a756d936be6d7ef5f8ebd6c7beee9
parent faca4ac263be5a3146f7f799f4a8a032df129962
Author: sin <sin@2f30.org>
Date:   Tue, 30 Jul 2013 14:25:03 +0100

Add free_chunk() and make mmap_pages() static

Diffstat:
Mrandom/alloc.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/random/alloc.c b/random/alloc.c @@ -25,7 +25,7 @@ struct chunk { enum chunk_state state; } chunks[NALLOC]; -void * +static void * mmap_pages(size_t nbytes) { void *addr; @@ -71,6 +71,15 @@ malloc(size_t nbytes) return NULL; } +static inline void +free_chunk(struct chunk *c) +{ + munmap(c->base, c->size + PAGESIZE); + c->base = NULL; + c->size = 0; + c->state = FREE; +} + void * realloc(void *oldp, size_t nbytes) { @@ -89,8 +98,7 @@ realloc(void *oldp, size_t nbytes) if (chunks[i].base == oldp) { n = chunks[i].size < nbytes ? chunks[i].size : nbytes; memcpy(p, chunks[i].base, n); - chunks[i].state = FREE; - munmap(chunks[i].base, chunks[i].size + PAGESIZE); + free_chunk(&chunks[i]); return p; } } @@ -118,8 +126,7 @@ free(void *p) return; for (i = 0; i < NALLOC; i++) { if (chunks[i].base == p) { - chunks[i].state = FREE; - munmap(chunks[i].base, chunks[i].size + PAGESIZE); + free_chunk(&chunks[i]); break; } }