Skip to content

Segfault with 1 arena through mi_manage_os_memory_ex and multiple per-thread heaps through mi_heap_new_in_arena #1313

Description

@MIvanchev

I get the following stacktrace when using a single arena like that

    mi_option_enable(mi_option_verbose);
    mi_option_enable(mi_option_show_errors);

    if(_not(mi_manage_os_memory_ex(
                 mem,
                 MEM_ARENA_SIZE,
                 true, // commited
                 false,
                 true, // zero
                 -1,
                 true,
                 &arena
             ))) {
        print_err("Failed to initialize mimalloc (a memory allocator).");
        exit(1);
    }

   // Per thread

   static __thread mi_heap_t *g_threadHeap;
   g_threadHeap = mi_heap_new_in_arena(arena);

   // Alloc

   ret = mi_heap_realloc(g_threadHeap, ptr, newSize);
0xf7f5058f ???
	???:0
0x820b128 mi_segment_os_alloc
	src/3rdparty/mimalloc-main/src/segment.c:863
0x820b128 mi_segment_alloc
	src/3rdparty/mimalloc-main/src/segment.c:925
0x820d5a5 mi_segment_reclaim_or_alloc
	src/3rdparty/mimalloc-main/src/segment.c:1541
0x820d5a5 mi_segments_page_alloc
	src/3rdparty/mimalloc-main/src/segment.c:1560
0x820da5f _mi_segment_page_alloc
	src/3rdparty/mimalloc-main/src/segment.c:1671
0x820db35 mi_page_fresh_alloc
	src/3rdparty/mimalloc-main/src/page.c:309
0x820e2d1 mi_page_fresh
	src/3rdparty/mimalloc-main/src/page.c:333
0x820e2d1 mi_page_queue_find_free_ex
	src/3rdparty/mimalloc-main/src/page.c:868
0x820e959 _mi_malloc_generic
	src/3rdparty/mimalloc-main/src/page.c:1051
0x820fbc9 mi_heap_malloc_small_zero
	src/3rdparty/mimalloc-main/src/alloc.c:147
0x820fbc9 _mi_heap_malloc_zero_ex
	src/3rdparty/mimalloc-main/src/alloc.c:176
0x821338b mi_heap_umalloc
	src/3rdparty/mimalloc-main/src/alloc.c:241
0x821338b _mi_heap_realloc_zero
	src/3rdparty/mimalloc-main/src/alloc.c:308
0x8213569 mi_heap_realloc
	src/3rdparty/mimalloc-main/src/alloc.c:329

Can someone tell me what I am doing wrong or if this is a bug? The program WORKS with the debug flags (no optimizations etc.). I am using the latest main revision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions