Small bug / performance fix
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 May 2020 19:50:26 +0000 (14:50 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 May 2020 19:50:26 +0000 (14:50 -0500)
bh.h
onyx

diff --git a/bh.h b/bh.h
index 1febb5f12806b425ddd1069d79853e725fdf7caf..78e91d5e1d7d5e29792c2df6ff984cb3c6c8ea02 100644 (file)
--- a/bh.h
+++ b/bh.h
@@ -658,17 +658,18 @@ BH_ALLOCATOR_PROC(bh_alloc_nofree_allocator_proc) {
 
        switch (action) {
        case bh_allocator_action_alloc: {
-               size = bh__align(size, alignment);
-
                retval = alloc_nf->next_allocation;
 
+               size = bh__align(size, alignment);
                alloc_nf->next_allocation = bh_pointer_add(alloc_nf->next_allocation, size);
-               alloc_nf->size += size;
-               if (alloc_nf->size > alloc_nf->total_size) {
+               
+               if (alloc_nf->size + size >= alloc_nf->total_size) {
                        // Out of memory
                        fprintf(stderr, "NoFree allocator out of memory\n");
                        return NULL;
                }
+
+               alloc_nf->size += size;
        } break;
 
        case bh_allocator_action_resize: {
diff --git a/onyx b/onyx
index 7191babc8a9c7e41196ef1c6f726eaaa76abdca1..b8911011cf089071f0bbd84ada557389a703a101 100755 (executable)
Binary files a/onyx and b/onyx differ