diff --git a/malloc.c b/malloc.c index 71f77a1..6f2f66d 100644 --- a/malloc.c +++ b/malloc.c @@ -790,10 +790,15 @@ static int alloc_aligned(void **memptr, size_t alignment, size_t size, size_t mi if (p == NULL) { return ENOMEM; } + + pthread_mutex_lock(®ions_lock); if (regions_insert(p, size)) { + pthread_mutex_unlock(®ions_lock); deallocate_pages(p, size, PAGE_SIZE); return ENOMEM; } + pthread_mutex_unlock(®ions_lock); + *memptr = p; return 0; }