From: Brendan Hansen Date: Mon, 10 Aug 2020 20:24:51 +0000 (-0500) Subject: used valgrind to find memory issues X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3e292bbd2e4926d5f19ede98271837ba33cfb982;p=onyx.git used valgrind to find memory issues --- diff --git a/include/bh.h b/include/bh.h index 5d498f84..b3085d29 100644 --- a/include/bh.h +++ b/include/bh.h @@ -1206,8 +1206,6 @@ char* bh_strdup(bh_allocator a, char* str) { char* t = buf; while (*t++ = *str++); - - *t = 0; return buf; } @@ -2096,7 +2094,7 @@ b32 bh_table_iter_next(bh_table_iterator* it) { step_to_next: // Step forward to find next valid - while (*it->tab == NULL && it->tab != it->endtab) { + while (it->tab != it->endtab && *it->tab == NULL) { it->tab++; } diff --git a/onyx b/onyx index 0304ad6c..0481c589 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyx.c b/src/onyx.c index 6be4e6f0..253b4eff 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -424,6 +424,7 @@ int main(int argc, char *argv[]) { compiler_state_free(&compile_state); + bh_scratch_free(&global_scratch); bh_managed_heap_free(&global_heap); return compiler_progress != ONYX_COMPILER_PROGRESS_SUCCESS; diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 8134b4be..bf8d2ce1 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -410,19 +410,10 @@ const char* type_get_name(Type* type) { u32 type_get_alignment_log2(Type* type) { i32 store_size = type_size_of(type); - i32 is_integer = (type->Basic.flags & Basic_Flag_Integer) - || (type->Basic.flags & Basic_Flag_Pointer); - - if (is_integer) { - if (store_size == 1) return 0; - else if (store_size == 2) return 1; - else if (store_size == 4) return 2; - else if (store_size == 8) return 3; - } else { - if (store_size == 4) return 2; - else if (store_size == 8) return 3; - } - + if (store_size == 1) return 0; + else if (store_size == 2) return 1; + else if (store_size == 4) return 2; + else if (store_size == 8) return 3; return 2; } diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 665cd82f..f3355734 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -424,11 +424,11 @@ COMPILE_FUNC(store_instruction, Type* type, u32 alignment, u32 offset) { type = &basic_types[Basic_Kind_U32]; } - i32 store_size = type_size_of(type); + i32 store_size = type_size_of(type); i32 is_basic = type->kind == Type_Kind_Basic || type->kind == Type_Kind_Pointer; i32 is_pointer = is_basic && (type->Basic.flags & Basic_Flag_Pointer); i32 is_integer = is_basic && (type->Basic.flags & Basic_Flag_Integer); - i32 is_float = is_basic && type->Basic.flags & Basic_Flag_Float; + i32 is_float = is_basic && (type->Basic.flags & Basic_Flag_Float); if (is_pointer) { WID(WI_I32_STORE, ((WasmInstructionData) { alignment, offset })); @@ -473,8 +473,8 @@ COMPILE_FUNC(load_instruction, Type* type, u32 offset) { i32 is_basic = type->kind == Type_Kind_Basic || type->kind == Type_Kind_Pointer; i32 is_pointer = is_basic && (type->Basic.flags & Basic_Flag_Pointer); i32 is_integer = is_basic && (type->Basic.flags & Basic_Flag_Integer); - i32 is_float = is_basic && type->Basic.flags & Basic_Flag_Float; - i32 is_unsigned = is_basic && type->Basic.flags & Basic_Flag_Unsigned; + i32 is_float = is_basic && (type->Basic.flags & Basic_Flag_Float); + i32 is_unsigned = is_basic && (type->Basic.flags & Basic_Flag_Unsigned); WasmInstructionType instr = WI_NOP; i32 alignment = type_get_alignment_log2(type); @@ -1697,7 +1697,7 @@ static void compile_memory_reservation(OnyxWasmModule* mod, AstMemRes* memres) { } if (memres->initial_value != NULL) { - u8* data = bh_alloc(mod->allocator, size); + u8* data = bh_alloc(global_heap_allocator, size); compile_raw_data(mod, data, memres->initial_value); WasmDatum datum = {