microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.44k stars 842 forks source link

mi_usable_size: invalid (unaligned) pointer on MacOS Ventura. #638

Open EugeneGribovich opened 1 year ago

EugeneGribovich commented 1 year ago

Good day.

Have problems on MacOS Ventura with mimalloc: "(unaligned) pointer" warning in Debug and segfault in Release. It seems that mi_usable_size gets pointer not allocated by mimalloc.

Sample code:

app.m

#include <Cocoa/Cocoa.h>

@interface MyApplication : NSApplication
@end

@implementation MyApplication
@end

void
Cocoa_RegisterApp(void)
{
    @autoreleasepool
    {
        if (NSApp == nil)
        {
            [MyApplication sharedApplication];
            {
            }
        }
    }
}

int main()
{
    Cocoa_RegisterApp();
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(test_package)
find_package(mimalloc)

add_executable(test_package app.m)
target_link_libraries(test_package PRIVATE mimalloc::mimalloc)

find_library(COCOA_LIBRARY Cocoa ONLY)
target_link_libraries(test_package PRIVATE ${COCOA_LIBRARY})

Debug output: mimalloc: error: mi_usable_size: invalid (unaligned) pointer: 0x97f86e598e2153a3 mimalloc: error: mi_usable_size: invalid (unaligned) pointer: 0xa0cfe8d603a959b3 mimalloc: warning: mi_usable_size: pointer might not point to a valid heap region: 0x20d54b5b0 (this may still be a valid very large allocation (over 64MiB)) mimalloc: error: mi_usable_size: pointer does not point to a valid heap space: 0x20d54b5b0

daanx commented 1 year ago

I think this is fixed now in the latest dev/dev-slice branches. Let me know how it goes

EugeneGribovich commented 1 year ago

I've checked dev-slice on my project and haven't got problems now. Thank you