Skip to content

Incorrect assertion during memory release in thread (memory allocated in main thread) #363

@marekkokot

Description

@marekkokot

Hello,
Here is my main.cpp:

#include <thread>
using namespace std;

int main()
{    
    char* a = new char[1ull << 25];    
    thread th([&] {
        delete [] a;
    });
    th.join();    
}

compilation: g++ main.cpp -I mimalloc mimalloc/libmimalloc-debug.a -pthread -o main
run:

./main
mimalloc: assertion failed: at "mimalloc-2.0.0/src/init.c":268, _mi_heap_done
  assertion: "heap->tld->segments.count == 0 || heap->thread_id != _mi_thread_id()"
Aborted (core dumped)

It does not occur in 1.7.0 or in release.
When the alloc size is 1<<22 I get:

mimalloc: warning: mi_usable_size: pointer might not point to a valid heap region: 0x7f4ed4810000
(this may still be a valid very large allocation (over 64MiB))
mimalloc: warning: (yes, the previous pointer 0x7f4ed4810000 was valid after all)
mimalloc: warning: mi_usable_size: pointer might not point to a valid heap region: 0x7f4ed4810000
(this may still be a valid very large allocation (over 64MiB))
mimalloc: warning: (yes, the previous pointer 0x7f4ed4810000 was valid after all)
mimalloc: warning: mi_free: pointer might not point to a valid heap region: 0x7f4ed4810000
(this may still be a valid very large allocation (over 64MiB))
mimalloc: warning: (yes, the previous pointer 0x7f4ed4810000 was valid after all)
mimalloc: warning: mi_usable_size: pointer might not point to a valid heap region: 0x7f4ed4810000
(this may still be a valid very large allocation (over 64MiB))
mimalloc: warning: (yes, the previous pointer 0x7f4ed4810000 was valid after all)
mimalloc: assertion failed: at "/mnt/d/nauka/DEVELOPMENT/3rd-compress/2021-02-16/ONT-compress-dev/3rd-compress/mimalloc-2.0.0/src/init.c":268, _mi_heap_done
  assertion: "heap->tld->segments.count == 0 || heap->thread_id != _mi_thread_id()"
Aborted (core dumped)

For 1 << 21 everything seems to be fine.
Any ideas? Thanks!

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