diff --git a/gc.c b/gc.c index cf2704c0..228889e8 100644 --- a/gc.c +++ b/gc.c @@ -1417,8 +1417,11 @@ void gc_collector() //sweep : for (heap_type = 0; heap_type < NUM_HEAP_TYPES; heap_type++) { - gc_sweep(gc_get_heap()->heap[heap_type], heap_type, &freed_tmp); - freed += freed_tmp; + gc_heap *h = gc_get_heap()->heap[heap_type]; + if (h) { + gc_sweep(h, heap_type, &freed_tmp); + freed += freed_tmp; + } } // TODO: this loop only includes smallest 2 heaps, is that sufficient?? diff --git a/runtime.c b/runtime.c index 78210cd1..6d2f7ddb 100644 --- a/runtime.c +++ b/runtime.c @@ -262,8 +262,8 @@ static bool set_insert(ck_hs_t * hs, const void *value) void gc_init_heap(long heap_size) { size_t initial_heap_size = INITIAL_HEAP_SIZE; - Cyc_heap = malloc(sizeof(gc_heap_root)); - Cyc_heap->heap = malloc(sizeof(gc_heap *) * NUM_HEAP_TYPES); + Cyc_heap = calloc(1, sizeof(gc_heap_root)); + Cyc_heap->heap = calloc(1, sizeof(gc_heap *) * NUM_HEAP_TYPES); Cyc_heap->heap[HEAP_REST] = gc_heap_create(HEAP_REST, initial_heap_size, 0, 0); Cyc_heap->heap[HEAP_SM] = gc_heap_create(HEAP_SM, initial_heap_size, 0, 0); Cyc_heap->heap[HEAP_64] = gc_heap_create(HEAP_64, initial_heap_size, 0, 0);