purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator
MIT License
506 stars 42 forks source link

error: Throwing a floating-point exception during the destruct phase. #121

Closed luoxiaojian closed 4 months ago

luoxiaojian commented 4 months ago

As the title states, a Floating Point Exception (FPE) was thrown in the mimalloc code during the destruction of objects before the program exit.

The call stack for the mimalloc code is:

#0  0x000056475630c8f5 in _mi_page_ptr_unalign (page=page@entry=0x20f2a000168, p=0x20f2a010060)
    at c_src/mimalloc/include/mimalloc/internal.h:508
#1  0x000056475631b7a6 in mi_free_generic_mt (page=0x20f2a000168, segment=0x20f2a000000, p=<optimized out>)
    at c_src/mimalloc/src/free.c:84
#2  0x00005647564250df in alloc::alloc::dealloc (ptr=0x20f2a000168 "", layout=...)

The specific location where the FPE was thrown is here

adjust = diff % mi_page_block_size(page);

The value of mi_page_block_size(page) is 0, yet according to the comments here, this value should not be possible to be zero.

Do you have any suggestions for resolving this issue?

luoxiaojian commented 4 months ago

The issue has been resolved. The need was for the local_dynamic_tls configuration, which I previously set by specifying the CARGO_FEATURE_LOCAL_DYNAMIC_TLS environment variable (according to this). By changing to adding the local_dynamic_tls feature directly at the point where the crate is included as a dependency, the original problem no longer occurs.