microsoft / mimalloc

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

Application using redirection to mimalloc crashes on Windows 11 when opening a file dialog #498

Open vlserov opened 2 years ago

vlserov commented 2 years ago

A minimal program was created to reproduce the issue (look code sniped below). The program opens a file dialog using GetOpenFileName. The crash occurs right after the file dialog displays.

On Windows 10, the program runs successfully both with and without the mimalloc. On Windows 11, the program crashes when the mimalloc allocator is used. Callstack is attached.

Windows 11 Home single language Version 21H2 OS Build 22000.348 Windows Feature Experience Pack 1000.22000.348.0

Shell32.dll ver. 10.0.22000.348 ucrtbase.dll ver. 10.0.22000.1 ucrtbased.dll ver. 10.0.19041.685

Visual Studio 2022 ver. 17.0.2 MSVC ver. 143 x86/x64 14.30.30705 Windows SDK 10.0.19041.0

#include <windows.h>
#include <Commdlg.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    OPENFILENAME ofn;
    char szFile[500];
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    ofn.lpstrFile = szFile;
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = sizeof(szFile);
    ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    GetOpenFileName(&ofn);

    MessageBox(NULL, ofn.lpstrFile, "File Name", MB_OK);
    return 0;
}
daanx commented 2 years ago

I have never tested on win11 yet but it seems we need to update the redirection. This will probably take a bit of time as I need to setup a win11 machine. Strange though, I see shell32 calls delete which invokes RtlFreeHeap which is probably wrong.

Can you run your program but with an environment variable MIMALLOC_VERBOSE=4 and send the output (it should give a long list of all redirected entry points)

vlserov commented 2 years ago

Output log with MIMALLOC_VERBOSE=4 is attached below. Seems like, issue is reproduced if OneDrive is syncing the Desktop. output.txt

mimalloc: process init: 0xa1f2403000
mimalloc: debug level : 3
mimalloc: secure level: 0
mimalloc: using 1 numa regions
mimalloc: option 'show_errors': 1
mimalloc: option 'show_stats': 1
mimalloc: option 'eager_commit': 1
mimalloc: option 'eager_region_commit': 0
mimalloc: option 'reset_decommits': 1
mimalloc: option 'large_os_pages': 0
mimalloc: option 'reserve_huge_os_pages': 0
mimalloc: option 'reserve_huge_os_pages_at': -1
mimalloc: option 'reserve_os_memory': 0
mimalloc: option 'segment_cache': 0
mimalloc: option 'page_reset': 1
mimalloc: option 'abandoned_page_reset': 0
mimalloc: option 'segment_reset': 0
mimalloc: option 'eager_commit_delay': 1
mimalloc: option 'reset_delay': 100
mimalloc: option 'use_numa_nodes': 0
mimalloc: option 'limit_os_alloc': 0
mimalloc: option 'os_tag': 100
mimalloc: option 'max_errors': 16
mimalloc: option 'max_warnings': 16
mimalloc: malloc is redirected.
heap stats:    peak      total      freed    current       unit      count
    normal:      0          0          0          0                            ok
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:      0          0          0          0                            ok
malloc req:      0          0          0          0                            ok

  reserved:      0          0          0          0                            ok
 committed:      0          0          0          0                            ok
     reset:      0          0          0          0                            ok
   touched:      0          0          0          0                            ok
  segments:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
 -extended:      0
 -noretire:      0
     mmaps:      0
   commits:      0
   threads:      0          0          0          0                            ok
  searches:     0.0 avg
numa nodes:       1
   elapsed:       0.167 s
   process: user: 0.000 s, system: 0.062 s, faults: 1798, rss: 6.7 MiB, commit: 5.7 MiB
heap stats:    peak      total      freed    current       unit      count
normal   1:    1.0 KiB    2.7 KiB    2.6 KiB     40 B        8 B      348      not all freed!
normal   4:    2.7 KiB    5.1 KiB    5.0 KiB     96 B       32 B      163      not all freed!
normal   6:    9.7 KiB   17.5 KiB    9.8 KiB    7.6 KiB     48 B      373      not all freed!
normal   8:    1.8 KiB    8.2 KiB    8.7 KiB   -448 B       64 B      132      ok
normal   9:    3.8 KiB   16.9 KiB   15.2 KiB    1.6 KiB     80 B      216      not all freed!
normal  10:    2.3 KiB   14.7 KiB   13.0 KiB    1.6 KiB     96 B      157      not all freed!
normal  11:    4.8 KiB   25.5 KiB   22.8 KiB    2.7 KiB    112 B      233      not all freed!
normal  12:    2.6 KiB   19.2 KiB   16.6 KiB    2.5 KiB    128 B      153      not all freed!
normal  13:   12.7 KiB   20.8 KiB   12.7 KiB    8.1 KiB    160 B      133      not all freed!
normal  14:    1.5 KiB    9.2 KiB    9.0 KiB    192 B      192 B       49      not all freed!
normal  15:    1.0 KiB    1.9 KiB   20.4 KiB  -18.4 KiB    224 B        9      ok
normal  16:    1.2 KiB    9.7 KiB    9.5 KiB    256 B      256 B       39      not all freed!
normal  17:   10.9 KiB   18.8 KiB   25.0 KiB   -6.2 KiB    320 B       60      ok
normal  18:    7.9 KiB   26.3 KiB   29.3 KiB   -3.0 KiB    384 B       70      ok
normal  19:    3.9 KiB  209.0 KiB  213.0 KiB   -3.9 KiB    448 B      476      ok
normal  20:    512 B     15.5 KiB   15.5 KiB      0        512 B       31      ok
normal  21:    5.6 KiB   23.8 KiB   24.4 KiB   -640 B      640 B       38      ok
normal  22:    768 B      4.5 KiB    4.5 KiB      0        768 B        6      ok
normal  24:    5.0 KiB   22.0 KiB   21.0 KiB    1.0 KiB    1.0 KiB     22      not all freed!
normal  25:    5.0 KiB   13.8 KiB   17.5 KiB   -3.7 KiB    1.2 KiB     11      ok
normal  28:   14.0 KiB   14.0 KiB   18.0 KiB   -4.0 KiB    2.0 KiB      7      ok
normal  29:   10.0 KiB   15.0 KiB   12.5 KiB    2.5 KiB    2.5 KiB      6      not all freed!
normal  30:    3.0 KiB    3.0 KiB    3.0 KiB      0        3.0 KiB      1      ok
normal  33:   10.0 KiB   20.0 KiB   15.0 KiB    5.0 KiB    5.0 KiB      4      not all freed!
normal  34:    6.0 KiB   12.0 KiB   12.0 KiB      0        6.0 KiB      2      ok
normal  37:   10.0 KiB   10.0 KiB      0       10.0 KiB   10.0 KiB      1      not all freed!

heap stats:    peak      total      freed    current       unit      count
    normal:  111.5 Ki   541.6 Ki   539.9 Ki     1.6 Ki     201 B      2.7 K    not all freed!
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:  111.5 KiB  541.6 KiB  539.9 KiB    1.6 KiB                        not all freed!
malloc req:   98.2 KiB  497.4 KiB  498.1 KiB   -685 B                          ok

  reserved:  128.5 KiB  144.5 KiB   24.0 KiB  120.4 KiB                        not all freed!
 committed:   11.6 MiB   11.6 MiB   24.0 KiB   11.6 MiB                        not all freed!
     reset:      0          0          0          0                            ok
   touched:  142.3 KiB  148.8 KiB   78.7 KiB   70.1 KiB                        not all freed!
  segments:      3          3          3          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:     13         15         14          1                            not all freed!
-abandoned:      0          0          0          0                            ok
 -extended:     37
 -noretire:    843
     mmaps:     18
   commits:    138
   threads:     16         18          3         15                            not all freed!
  searches:     0.5 avg
numa nodes:       1
   elapsed:      46.141 s
   process: user: 0.250 s, system: 0.734 s, faults: 15701, rss: 46.4 MiB, commit: 30.8 MiB
mimalloc: process done: 0xa1f2403000
Sedeniono commented 2 years ago

@daanx @vlserov To me this looks like a bug in shell32.dll since it uses HeapFree directly, and because it also occurs with oneTBB (i.e. it is not exclusive to mimalloc). More details here: https://github.com/oneapi-src/oneTBB/issues/665

daanx commented 2 years ago

Ah very interesting @Sedeniono ; the linked thread has some great debug info and it indeed looks like a shell32 bug (perhaps).

@vlserov : thanks for the output! Can you try:

Best, Daan

vlserov commented 2 years ago

@daanx, I've checked with MIMALLOC_PATCH_IMPORTS=1. Issue is still reproduced. Output log with MIMALLOC_VERBOSE=3 attached. output_debug_3.txt

mimalloc: process init: 0xa072d6b000
mimalloc: debug level : 3
mimalloc: secure level: 0
mimalloc: using 1 numa regions
mimalloc: option 'show_errors': 1
mimalloc: option 'show_stats': 1
mimalloc: option 'eager_commit': 1
mimalloc: option 'eager_region_commit': 0
mimalloc: option 'reset_decommits': 1
mimalloc: option 'large_os_pages': 0
mimalloc: option 'reserve_huge_os_pages': 0
mimalloc: option 'reserve_huge_os_pages_at': -1
mimalloc: option 'reserve_os_memory': 0
mimalloc: option 'segment_cache': 0
mimalloc: option 'page_reset': 1
mimalloc: option 'abandoned_page_reset': 0
mimalloc: option 'segment_reset': 0
mimalloc: option 'eager_commit_delay': 1
mimalloc: option 'reset_delay': 100
mimalloc: option 'use_numa_nodes': 0
mimalloc: option 'limit_os_alloc': 0
mimalloc: option 'os_tag': 100
mimalloc: option 'max_errors': 16
mimalloc: option 'max_warnings': 16
mimalloc: malloc is redirected.
mimalloc-redirect: trace: build: Nov 22 2019
mimalloc-redirect: trace: checking for target mimalloc.dll
mimalloc-redirect: trace: checking for target mimalloc-override.dll
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-override-test.exe"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\ntdll.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\KERNEL32.DLL"
mimalloc-redirect: trace: module "C:\Windows\System32\KERNELBASE.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\USER32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\win32u.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\GDI32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\gdi32full.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\msvcp_win.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\ucrtbase.dll"
mimalloc-redirect: trace: resolving "ucrtbase.dll"
mimalloc-redirect: trace: resolve "malloc" at ucrtbase.dll!0x00007FFFC7200060 to mimalloc!0x00007FFF16FAA749 (0)
mimalloc-redirect: trace: resolve "calloc" at ucrtbase.dll!0x00007FFFC7201E90 to mimalloc!0x00007FFF16FAA2D5 (0)
mimalloc-redirect: trace: resolve "realloc" at ucrtbase.dll!0x00007FFFC71FFFE0 to mimalloc!0x00007FFF16FAA339 (0)
mimalloc-redirect: trace: resolve "free" at ucrtbase.dll!0x00007FFFC7202150 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_expand" at ucrtbase.dll!0x00007FFFC72685B0 to mimalloc!0x00007FFF16FAA0D7 (0)
mimalloc-redirect: trace: resolve "_recalloc" at ucrtbase.dll!0x00007FFFC7216BB0 to mimalloc!0x00007FFF16FAA2BC (0)
mimalloc-redirect: trace: resolve "_msize" at ucrtbase.dll!0x00007FFFC720FE90 to mimalloc!0x00007FFF16FAA40B (0)
mimalloc-redirect: trace: resolve "_malloc_base" at ucrtbase.dll!0x00007FFFC7200070 to mimalloc!0x00007FFF16FAA749 (0)
mimalloc-redirect: trace: resolve "_calloc_base" at ucrtbase.dll!0x00007FFFC7201EA0 to mimalloc!0x00007FFF16FAA2D5 (0)
mimalloc-redirect: trace: resolve "_realloc_base" at ucrtbase.dll!0x00007FFFC71FFFF0 to mimalloc!0x00007FFF16FAA339 (0)
mimalloc-redirect: trace: resolve "_free_base" at ucrtbase.dll!0x00007FFFC7202170 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_expand_base" at ucrtbase.dll!0x00007FFFC72685BC to mimalloc!0x00007FFF19E04D80 (0)
mimalloc-redirect: trace: resolve "_recalloc_base" at ucrtbase.dll!0x00007FFFC71FF574 to mimalloc!0x00007FFF19E04DB0 (0)
mimalloc-redirect: trace: resolve "_msize_base" at ucrtbase.dll!0x00007FFFC720FEA0 to mimalloc!0x00007FFF19E04D60 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlSizeHeap" in ucrtbase.dll at 0x00007FFFC72B87C8 to 0x00007FFF19E054A0 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlFreeHeap" in ucrtbase.dll at 0x00007FFFC72B87C0 to 0x00007FFF19E05510 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlReAllocateHeap" in ucrtbase.dll at 0x00007FFFC72B87B8 to 0x00007FFF19E055A0 (0)
mimalloc-redirect: trace: resolve "_aligned_malloc" at ucrtbase.dll!0x00007FFFC71FFF50 to mimalloc!0x00007FFF16FAA4BF (0)
mimalloc-redirect: trace: resolve "_aligned_realloc" at ucrtbase.dll!0x00007FFFC7268150 to mimalloc!0x00007FFF16FAA5B9 (0)
mimalloc-redirect: trace: resolve "_aligned_free" at ucrtbase.dll!0x00007FFFC7201C60 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_aligned_recalloc" at ucrtbase.dll!0x00007FFFC7268330 to mimalloc!0x00007FFF16FAA6C7 (0)
mimalloc-redirect: trace: resolve "_aligned_msize" at ucrtbase.dll!0x00007FFFC7267B40 to mimalloc!0x00007FFF19E05190 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc" at ucrtbase.dll!0x00007FFFC7214A70 to mimalloc!0x00007FFF16FAA5BE (0)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc" at ucrtbase.dll!0x00007FFFC7267BB0 to mimalloc!0x00007FFF16FAA01E (0)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc" at ucrtbase.dll!0x00007FFFC7267E20 to mimalloc!0x00007FFF16FAA753 (0)
mimalloc-redirect: trace: module "C:\Windows\System32\COMDLG32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\combase.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\RPCRT4.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\shcore.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\SHLWAPI.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\msvcrt.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\SHELL32.dll"
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-override.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\ADVAPI32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\sechost.dll"
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-redirect.dll"
mimalloc-redirect: trace: module "C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.22000.1_none_271a8fad6a2d1b1e\COMCTL32.dll"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\VCRUNTIME140D.dll"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\ucrtbased.dll"
mimalloc-redirect: trace: resolving "ucrtbased.dll"
mimalloc-redirect: trace: resolve "malloc" at ucrtbased.dll!0x00007FFF167F5450 to mimalloc!0x00007FFF16FAA749 (1)
mimalloc-redirect: trace: resolve "calloc" at ucrtbased.dll!0x00007FFF167F0940 to mimalloc!0x00007FFF16FAA2D5 (1)
mimalloc-redirect: trace: resolve "realloc" at ucrtbased.dll!0x00007FFF167F5990 to mimalloc!0x00007FFF16FAA339 (1)
mimalloc-redirect: trace: resolve "free" at ucrtbased.dll!0x00007FFF167F50A0 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve "_expand" at ucrtbased.dll!0x00007FFF167F4ED0 to mimalloc!0x00007FFF16FAA0D7 (1)
mimalloc-redirect: trace: resolve "_recalloc" at ucrtbased.dll!0x00007FFF167F5A90 to mimalloc!0x00007FFF16FAA2BC (1)
mimalloc-redirect: trace: resolve "_msize" at ucrtbased.dll!0x00007FFF167F5530 to mimalloc!0x00007FFF16FAA40B (1)
mimalloc-redirect: trace: resolve "_malloc_base" at ucrtbased.dll!0x00007FFF167F5480 to mimalloc!0x00007FFF16FAA749 (1)
mimalloc-redirect: trace: resolve "_calloc_base" at ucrtbased.dll!0x00007FFF167F0980 to mimalloc!0x00007FFF16FAA2D5 (1)
mimalloc-redirect: trace: resolve "_realloc_base" at ucrtbased.dll!0x00007FFF167F59D0 to mimalloc!0x00007FFF16FAA339 (1)
mimalloc-redirect: trace: resolve "_free_base" at ucrtbased.dll!0x00007FFF167F5100 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlSizeHeap" in ucrtbased.dll at 0x00007FFF168FC438 to 0x00007FFF19E054A0 (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlFreeHeap" in ucrtbased.dll at 0x00007FFF168FC400 to 0x00007FFF19E05510 (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlReAllocateHeap" in ucrtbased.dll at 0x00007FFF168FC408 to 0x00007FFF19E055A0 (1)
mimalloc-redirect: trace: resolve "_aligned_malloc" at ucrtbased.dll!0x00007FFF167F0720 to mimalloc!0x00007FFF16FAA4BF (1)
mimalloc-redirect: trace: resolve "_aligned_realloc" at ucrtbased.dll!0x00007FFF167F0890 to mimalloc!0x00007FFF16FAA5B9 (1)
mimalloc-redirect: trace: resolve "_aligned_free" at ucrtbased.dll!0x00007FFF167F0700 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve "_aligned_recalloc" at ucrtbased.dll!0x00007FFF167F08E0 to mimalloc!0x00007FFF16FAA6C7 (1)
mimalloc-redirect: trace: resolve "_aligned_msize" at ucrtbased.dll!0x00007FFF167F0760 to mimalloc!0x00007FFF19E05190 (1)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc" at ucrtbased.dll!0x00007FFF167F07A0 to mimalloc!0x00007FFF16FAA5BE (1)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc" at ucrtbased.dll!0x00007FFF167F07E0 to mimalloc!0x00007FFF16FAA01E (1)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc" at ucrtbased.dll!0x00007FFF167F0830 to mimalloc!0x00007FFF16FAA753 (1)
mimalloc-redirect: trace: resolve "_malloc_dbg" at ucrtbased.dll!0x00007FFF167F49E0 to mimalloc!0x00007FFF19E04F50 (0)
mimalloc-redirect: trace: resolve "_realloc_dbg" at ucrtbased.dll!0x00007FFF167F4BC0 to mimalloc!0x00007FFF19E04FC0 (0)
mimalloc-redirect: trace: resolve "_calloc_dbg" at ucrtbased.dll!0x00007FFF167F4790 to mimalloc!0x00007FFF19E04F80 (0)
mimalloc-redirect: trace: resolve "_free_dbg" at ucrtbased.dll!0x00007FFF167F4970 to mimalloc!0x00007FFF19E05000 (0)
mimalloc-redirect: trace: resolve "_expand_dbg" at ucrtbased.dll!0x00007FFF167F4830 to mimalloc!0x00007FFF19E05070 (0)
mimalloc-redirect: trace: resolve "_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F4C40 to mimalloc!0x00007FFF19E05030 (0)
mimalloc-redirect: trace: resolve "_msize_dbg" at ucrtbased.dll!0x00007FFF167F4A20 to mimalloc!0x00007FFF19E050B0 (0)
mimalloc-redirect: trace: resolve "_aligned_malloc_dbg" at ucrtbased.dll!0x00007FFF167F3C00 to mimalloc!0x00007FFF19E051C0 (0)
mimalloc-redirect: trace: resolve "_aligned_realloc_dbg" at ucrtbased.dll!0x00007FFF167F46E0 to mimalloc!0x00007FFF19E05200 (0)
mimalloc-redirect: trace: resolve "_aligned_free_dbg" at ucrtbased.dll!0x00007FFF167F3B10 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_aligned_msize_dbg" at ucrtbased.dll!0x00007FFF167F3C50 to mimalloc!0x00007FFF19E05190 (0)
mimalloc-redirect: trace: resolve "_aligned_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F4730 to mimalloc!0x00007FFF19E05240 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc_dbg" at ucrtbased.dll!0x00007FFF167F3E20 to mimalloc!0x00007FFF19E05290 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc_dbg" at ucrtbased.dll!0x00007FFF167F4110 to mimalloc!0x00007FFF19E052D0 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F45C0 to mimalloc!0x00007FFF19E05320 (0)
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\bcrypt.dll"
mimalloc-redirect: trace: standard malloc is redirected
heap stats:    peak      total      freed    current       unit      count
    normal:      0          0          0          0                            ok
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:      0          0          0          0                            ok
malloc req:      0          0          0          0                            ok

  reserved:      0          0          0          0                            ok
 committed:      0          0          0          0                            ok
     reset:      0          0          0          0                            ok
   touched:      0          0          0          0                            ok
  segments:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
 -extended:      0
 -noretire:      0
     mmaps:      0
   commits:      0
   threads:      0          0          0          0                            ok
  searches:     0.0 avg
numa nodes:       1
   elapsed:       1.626 s
   process: user: 0.140 s, system: 0.281 s, faults: 1804, rss: 6.7 MiB, commit: 5.7 MiB
heap stats:    peak      total      freed    current       unit      count
normal   1:    1.0 KiB    2.7 KiB    2.6 KiB     40 B        8 B      348      not all freed!
normal   4:    2.7 KiB    5.1 KiB    5.0 KiB     96 B       32 B      163      not all freed!
normal   6:    9.7 KiB   17.5 KiB    9.8 KiB    7.6 KiB     48 B      373      not all freed!
normal   8:    1.8 KiB    8.2 KiB    8.7 KiB   -448 B       64 B      132      ok
normal   9:    3.8 KiB   16.9 KiB   15.2 KiB    1.6 KiB     80 B      216      not all freed!
normal  10:    2.3 KiB   14.7 KiB   13.0 KiB    1.6 KiB     96 B      157      not all freed!
normal  11:    5.1 KiB   25.9 KiB   23.1 KiB    2.7 KiB    112 B      236      not all freed!
normal  12:    2.6 KiB   19.2 KiB   16.6 KiB    2.5 KiB    128 B      153      not all freed!
normal  13:   12.7 KiB   20.8 KiB   12.7 KiB    8.1 KiB    160 B      133      not all freed!
normal  14:    1.5 KiB    9.2 KiB    9.0 KiB    192 B      192 B       49      not all freed!
normal  15:    1.0 KiB    1.9 KiB   20.4 KiB  -18.4 KiB    224 B        9      ok
normal  16:    1.2 KiB    9.7 KiB    9.5 KiB    256 B      256 B       39      not all freed!
normal  17:   10.9 KiB   18.8 KiB   25.0 KiB   -6.2 KiB    320 B       60      ok
normal  18:    8.2 KiB   26.7 KiB   29.7 KiB   -3.0 KiB    384 B       71      ok
normal  19:    3.9 KiB  217.8 KiB  221.8 KiB   -3.9 KiB    448 B      496      ok
normal  20:    512 B     15.5 KiB   15.5 KiB      0        512 B       31      ok
normal  21:    5.6 KiB   24.4 KiB   25.0 KiB   -640 B      640 B       39      ok
normal  22:    1.5 KiB    5.2 KiB    5.2 KiB      0        768 B        7      ok
normal  24:    5.0 KiB   22.0 KiB   21.0 KiB    1.0 KiB    1.0 KiB     22      not all freed!
normal  25:    5.0 KiB   13.8 KiB   17.5 KiB   -3.7 KiB    1.2 KiB     11      ok
normal  28:   14.0 KiB   16.0 KiB   20.0 KiB   -4.0 KiB    2.0 KiB      8      ok
normal  29:   10.0 KiB   15.0 KiB   12.5 KiB    2.5 KiB    2.5 KiB      6      not all freed!
normal  30:    3.0 KiB    3.0 KiB    3.0 KiB      0        3.0 KiB      1      ok
normal  33:   10.0 KiB   20.0 KiB   15.0 KiB    5.0 KiB    5.0 KiB      4      not all freed!
normal  34:    6.0 KiB   12.0 KiB   12.0 KiB      0        6.0 KiB      2      ok
normal  37:   10.0 KiB   10.0 KiB      0       10.0 KiB   10.0 KiB      1      not all freed!

heap stats:    peak      total      freed    current       unit      count
    normal:  111.5 Ki   554.2 Ki   552.6 Ki     1.6 Ki     204 B      2.7 K    not all freed!
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:  111.5 KiB  554.2 KiB  552.6 KiB    1.6 KiB                        not all freed!
malloc req:   98.2 KiB  509.5 KiB  510.2 KiB   -685 B                          ok

  reserved:  128.5 KiB  144.5 KiB   24.0 KiB  120.4 KiB                        not all freed!
 committed:   11.6 MiB   11.7 MiB   24.0 KiB   11.6 MiB                        not all freed!
     reset:      0          0          0          0                            ok
   touched:  142.3 KiB  148.8 KiB   78.7 KiB   70.1 KiB                        not all freed!
  segments:      3          3          3          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:     13         15         14          1                            not all freed!
-abandoned:      0          0          0          0                            ok
 -extended:     37
 -noretire:    1.0 Ki
     mmaps:     18
   commits:    139
   threads:     16         18          3         15                            not all freed!
  searches:     0.5 avg
numa nodes:       1
   elapsed:      57.439 s
   process: user: 0.375 s, system: 0.937 s, faults: 15712, rss: 46.7 MiB, commit: 31.0 MiB
mimalloc: process done: 0xa072d6b000

Update: replace with correct logs

daanx commented 2 years ago

Thanks @vlserov -- I see it patches RtlFreeHeap:

mimalloc-redirect: trace: resolve import "ntdll.dll!RtlFreeHeap" in ucrtbased.dll at 0x00007FFF168FC400 to 0x00007FFF19E05510 (1)

so that should resolve the issue with MIMALLOC_PATCH_IMPORTS=1. Can you check if you still get the same error in the stack trace (i.e. at RtlFreeHeap?). (I will try to contact the shell32 team to see what is going on but it may take a bit during the holidays.)

Sedeniono commented 2 years ago

@daanx I think the issue is not resolved with MIMALLOC_PATCH_IMPORTS=1 because mimalloc does not seem to redirect the ntdll!RtlFreeHeap import in the shell32.dll. mimalloc redirects the import only in ucrtbase.dll. I see this also in the debugger (imports patched in ucrtbase.dll but not in shell32.dll).

daanx commented 2 years ago

Ah that is right; hmm, I may be able to fix this from mimalloc's end .. I'll take a look. tbc.

daanx commented 2 years ago

Hi @Sedeniono , I made a version of the redirect dll that may solve the issue. Can you try it out? (I don't have a win11 system yet)

If it does not work, can you use MIMALLOC_VERBOSE=3 again and send me the output? Thanks!

vlserov commented 2 years ago

Hi @daanx, I've tested with attached redirect dll. It doesn't help, issue is still present. Logs have been attached. mimalloc_attached_redirect.txt

daanx commented 2 years ago

@vlserov , @Sedeniono : I updated the dll; can you try again? (the previous version tested against windows version 11 but I see that the version on win11 is still 10).

The previous link should still work (but now gets the new dll):

$ shasum mimalloc-redirect.dll
5540d0e3541546eb409c3ef57d689e5ba0490f37  mimalloc-redirect.dll
Sedeniono commented 2 years ago

@daanx I just tried it with the updated dll (5540d0e35...) and it no longer crashes. I can also see that the imports of shell32.dll now contain mimalloc-redirect.HeapFree and mimalloc-redirect.HeapReAlloc.

So, what is your current view on this? Is it a bug that shell32.dll calls HeapFree directly rather than through ucrtbase.dll? Or can it be considered a bug that mimalloc is not redirecting the imports in shell32.dll?

Btw, where is the output of MIMALLOC_VERBOSE=3 written to? Apparently neither stdout nor stderr for me (my small test application prints to them just fine, but mimalloc output does not appear).

daanx commented 2 years ago

Yahoo -- victory :-) That is good to hear and I will update the binaries in the dev/dev-slice branch soon (and release later this week). Can you see in the output what windows version mimalloc prints? Something like "windows version 10.0.xxx" -- I think I should only enable the extra patching on win11.

Just speaking for myself, it does seem like a bug in shell32 where mallocd (or newd) memory is directly deallocated using RtlFreeHeap (which goes wrong when the allocator is not using RtlAllocHeap). I will try to contact the relevant team especially since it affects other allocators as well that may not have an easy way to work around it.

(The MIMALLOC_VERBOSE=3 is a secret setting... but eventually it goes to the regular mimalloc output and can be caught using mi_register_output. It is actually tricky as this output is given even before the loader finishes initializing DLL's so it is actually buffered and emitted later. The default use _cputs on Windows (to avoid deadlock in fputs if the c runtime allocates itself) but you can use mi_register_output to change this. )

Sedeniono commented 2 years ago

@daanx Ah, ok, I had to register a custom output function via mi_register_output and print it manually. The windows version is 10.0.22000 (Microsoft did not increase the main version number in Windows 11 from 10 to 11, instead it is identified via the minor version 22000). Full output here: output_mimalloc.txt

Btw, I see that not all "Heap"-related imports are patched in shell32.dll with your new mimalloc-dll: HeapImports Is this ok? I mean there is, for example, shell32!operator new which still uses ntdll.dll!RtlAlllocateHeap: shell32_new If this operator is called, I think it bypasses mimalloc. But the corresponding operator delete might call mimalloc's HeapFree function now, possibly resulting in another crash because of a mismatching alloc and free? Although, with the toy example from above, I have not yet observed any problems. But similar to the OneDrive problem, probably just because the conditions happen to be not satisfied on my VM without "special" settings?

daanx commented 2 years ago

Ah, this is fine; on purpose mimalloc tries to only intercept needed functions to minimize any changes. The RtlHeapFree uses a check to see if the pointer comes from the mimalloc heap to reliably use either mi_free or the original RtlHeapFree.

I am hoping to update the mimalloc version/release next week that will contain the fix.

Sedeniono commented 2 years ago

@daanx Any news yet regarding the workaround/fix in mimalloc that you suggested? Did the shell32-Team get back to you? Or should we try to escalate the issue to Microsoft by other means (any suggestions?)?

scanta2 commented 2 years ago

@daanx Can you please share the Dropbox links again? The ones you posted on 12/19 are now expired.

daanx commented 2 years ago

Hi @scanta2: the binaries are already updated in the latest dev (v1.7.x) and dev-slice (v2.0.x) branches. These work with any mimalloc version. (I am about to do a fresh release in the next days though so you could wait for that.)

vlserov commented 2 years ago

Hi @daanx, is there any updates from shell32-Team? Do shell32-Team have plans to fix this issue?

daanx commented 2 years ago

Hi @vlserov; unfortunately I have no direct contact in that team and I have no insight what the status of this is; If you have any other channels to report this as a bug please do so as well. (and I will try again to see if I can directly connect with someone on that team.)

markocar commented 2 years ago

We tried this patch, and it worked on some PCs for file open dialog, but it created another problem, immediate crash on application startup on some other PCs running Win 11.

JJJoyZ commented 1 year ago

@daanx, I've checked with MIMALLOC_PATCH_IMPORTS=1. Issue is still reproduced. Output log with MIMALLOC_VERBOSE=3 attached. output_debug_3.txt

mimalloc: process init: 0xa072d6b000
mimalloc: debug level : 3
mimalloc: secure level: 0
mimalloc: using 1 numa regions
mimalloc: option 'show_errors': 1
mimalloc: option 'show_stats': 1
mimalloc: option 'eager_commit': 1
mimalloc: option 'eager_region_commit': 0
mimalloc: option 'reset_decommits': 1
mimalloc: option 'large_os_pages': 0
mimalloc: option 'reserve_huge_os_pages': 0
mimalloc: option 'reserve_huge_os_pages_at': -1
mimalloc: option 'reserve_os_memory': 0
mimalloc: option 'segment_cache': 0
mimalloc: option 'page_reset': 1
mimalloc: option 'abandoned_page_reset': 0
mimalloc: option 'segment_reset': 0
mimalloc: option 'eager_commit_delay': 1
mimalloc: option 'reset_delay': 100
mimalloc: option 'use_numa_nodes': 0
mimalloc: option 'limit_os_alloc': 0
mimalloc: option 'os_tag': 100
mimalloc: option 'max_errors': 16
mimalloc: option 'max_warnings': 16
mimalloc: malloc is redirected.
mimalloc-redirect: trace: build: Nov 22 2019
mimalloc-redirect: trace: checking for target mimalloc.dll
mimalloc-redirect: trace: checking for target mimalloc-override.dll
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-override-test.exe"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\ntdll.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\KERNEL32.DLL"
mimalloc-redirect: trace: module "C:\Windows\System32\KERNELBASE.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\USER32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\win32u.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\GDI32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\gdi32full.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\msvcp_win.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\ucrtbase.dll"
mimalloc-redirect: trace: resolving "ucrtbase.dll"
mimalloc-redirect: trace: resolve "malloc" at ucrtbase.dll!0x00007FFFC7200060 to mimalloc!0x00007FFF16FAA749 (0)
mimalloc-redirect: trace: resolve "calloc" at ucrtbase.dll!0x00007FFFC7201E90 to mimalloc!0x00007FFF16FAA2D5 (0)
mimalloc-redirect: trace: resolve "realloc" at ucrtbase.dll!0x00007FFFC71FFFE0 to mimalloc!0x00007FFF16FAA339 (0)
mimalloc-redirect: trace: resolve "free" at ucrtbase.dll!0x00007FFFC7202150 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_expand" at ucrtbase.dll!0x00007FFFC72685B0 to mimalloc!0x00007FFF16FAA0D7 (0)
mimalloc-redirect: trace: resolve "_recalloc" at ucrtbase.dll!0x00007FFFC7216BB0 to mimalloc!0x00007FFF16FAA2BC (0)
mimalloc-redirect: trace: resolve "_msize" at ucrtbase.dll!0x00007FFFC720FE90 to mimalloc!0x00007FFF16FAA40B (0)
mimalloc-redirect: trace: resolve "_malloc_base" at ucrtbase.dll!0x00007FFFC7200070 to mimalloc!0x00007FFF16FAA749 (0)
mimalloc-redirect: trace: resolve "_calloc_base" at ucrtbase.dll!0x00007FFFC7201EA0 to mimalloc!0x00007FFF16FAA2D5 (0)
mimalloc-redirect: trace: resolve "_realloc_base" at ucrtbase.dll!0x00007FFFC71FFFF0 to mimalloc!0x00007FFF16FAA339 (0)
mimalloc-redirect: trace: resolve "_free_base" at ucrtbase.dll!0x00007FFFC7202170 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_expand_base" at ucrtbase.dll!0x00007FFFC72685BC to mimalloc!0x00007FFF19E04D80 (0)
mimalloc-redirect: trace: resolve "_recalloc_base" at ucrtbase.dll!0x00007FFFC71FF574 to mimalloc!0x00007FFF19E04DB0 (0)
mimalloc-redirect: trace: resolve "_msize_base" at ucrtbase.dll!0x00007FFFC720FEA0 to mimalloc!0x00007FFF19E04D60 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlSizeHeap" in ucrtbase.dll at 0x00007FFFC72B87C8 to 0x00007FFF19E054A0 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlFreeHeap" in ucrtbase.dll at 0x00007FFFC72B87C0 to 0x00007FFF19E05510 (0)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlReAllocateHeap" in ucrtbase.dll at 0x00007FFFC72B87B8 to 0x00007FFF19E055A0 (0)
mimalloc-redirect: trace: resolve "_aligned_malloc" at ucrtbase.dll!0x00007FFFC71FFF50 to mimalloc!0x00007FFF16FAA4BF (0)
mimalloc-redirect: trace: resolve "_aligned_realloc" at ucrtbase.dll!0x00007FFFC7268150 to mimalloc!0x00007FFF16FAA5B9 (0)
mimalloc-redirect: trace: resolve "_aligned_free" at ucrtbase.dll!0x00007FFFC7201C60 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_aligned_recalloc" at ucrtbase.dll!0x00007FFFC7268330 to mimalloc!0x00007FFF16FAA6C7 (0)
mimalloc-redirect: trace: resolve "_aligned_msize" at ucrtbase.dll!0x00007FFFC7267B40 to mimalloc!0x00007FFF19E05190 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc" at ucrtbase.dll!0x00007FFFC7214A70 to mimalloc!0x00007FFF16FAA5BE (0)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc" at ucrtbase.dll!0x00007FFFC7267BB0 to mimalloc!0x00007FFF16FAA01E (0)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc" at ucrtbase.dll!0x00007FFFC7267E20 to mimalloc!0x00007FFF16FAA753 (0)
mimalloc-redirect: trace: module "C:\Windows\System32\COMDLG32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\combase.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\RPCRT4.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\shcore.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\SHLWAPI.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\msvcrt.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\SHELL32.dll"
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-override.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\ADVAPI32.dll"
mimalloc-redirect: trace: module "C:\Windows\System32\sechost.dll"
mimalloc-redirect: trace: module "D:\development\mimalloc\out\msvc-x64\Debug\mimalloc-redirect.dll"
mimalloc-redirect: trace: module "C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.22000.1_none_271a8fad6a2d1b1e\COMCTL32.dll"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\VCRUNTIME140D.dll"
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\ucrtbased.dll"
mimalloc-redirect: trace: resolving "ucrtbased.dll"
mimalloc-redirect: trace: resolve "malloc" at ucrtbased.dll!0x00007FFF167F5450 to mimalloc!0x00007FFF16FAA749 (1)
mimalloc-redirect: trace: resolve "calloc" at ucrtbased.dll!0x00007FFF167F0940 to mimalloc!0x00007FFF16FAA2D5 (1)
mimalloc-redirect: trace: resolve "realloc" at ucrtbased.dll!0x00007FFF167F5990 to mimalloc!0x00007FFF16FAA339 (1)
mimalloc-redirect: trace: resolve "free" at ucrtbased.dll!0x00007FFF167F50A0 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve "_expand" at ucrtbased.dll!0x00007FFF167F4ED0 to mimalloc!0x00007FFF16FAA0D7 (1)
mimalloc-redirect: trace: resolve "_recalloc" at ucrtbased.dll!0x00007FFF167F5A90 to mimalloc!0x00007FFF16FAA2BC (1)
mimalloc-redirect: trace: resolve "_msize" at ucrtbased.dll!0x00007FFF167F5530 to mimalloc!0x00007FFF16FAA40B (1)
mimalloc-redirect: trace: resolve "_malloc_base" at ucrtbased.dll!0x00007FFF167F5480 to mimalloc!0x00007FFF16FAA749 (1)
mimalloc-redirect: trace: resolve "_calloc_base" at ucrtbased.dll!0x00007FFF167F0980 to mimalloc!0x00007FFF16FAA2D5 (1)
mimalloc-redirect: trace: resolve "_realloc_base" at ucrtbased.dll!0x00007FFF167F59D0 to mimalloc!0x00007FFF16FAA339 (1)
mimalloc-redirect: trace: resolve "_free_base" at ucrtbased.dll!0x00007FFF167F5100 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlSizeHeap" in ucrtbased.dll at 0x00007FFF168FC438 to 0x00007FFF19E054A0 (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlFreeHeap" in ucrtbased.dll at 0x00007FFF168FC400 to 0x00007FFF19E05510 (1)
mimalloc-redirect: trace: resolve import "ntdll.dll!RtlReAllocateHeap" in ucrtbased.dll at 0x00007FFF168FC408 to 0x00007FFF19E055A0 (1)
mimalloc-redirect: trace: resolve "_aligned_malloc" at ucrtbased.dll!0x00007FFF167F0720 to mimalloc!0x00007FFF16FAA4BF (1)
mimalloc-redirect: trace: resolve "_aligned_realloc" at ucrtbased.dll!0x00007FFF167F0890 to mimalloc!0x00007FFF16FAA5B9 (1)
mimalloc-redirect: trace: resolve "_aligned_free" at ucrtbased.dll!0x00007FFF167F0700 to mimalloc!0x00007FFF16FAA5CD (1)
mimalloc-redirect: trace: resolve "_aligned_recalloc" at ucrtbased.dll!0x00007FFF167F08E0 to mimalloc!0x00007FFF16FAA6C7 (1)
mimalloc-redirect: trace: resolve "_aligned_msize" at ucrtbased.dll!0x00007FFF167F0760 to mimalloc!0x00007FFF19E05190 (1)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc" at ucrtbased.dll!0x00007FFF167F07A0 to mimalloc!0x00007FFF16FAA5BE (1)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc" at ucrtbased.dll!0x00007FFF167F07E0 to mimalloc!0x00007FFF16FAA01E (1)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc" at ucrtbased.dll!0x00007FFF167F0830 to mimalloc!0x00007FFF16FAA753 (1)
mimalloc-redirect: trace: resolve "_malloc_dbg" at ucrtbased.dll!0x00007FFF167F49E0 to mimalloc!0x00007FFF19E04F50 (0)
mimalloc-redirect: trace: resolve "_realloc_dbg" at ucrtbased.dll!0x00007FFF167F4BC0 to mimalloc!0x00007FFF19E04FC0 (0)
mimalloc-redirect: trace: resolve "_calloc_dbg" at ucrtbased.dll!0x00007FFF167F4790 to mimalloc!0x00007FFF19E04F80 (0)
mimalloc-redirect: trace: resolve "_free_dbg" at ucrtbased.dll!0x00007FFF167F4970 to mimalloc!0x00007FFF19E05000 (0)
mimalloc-redirect: trace: resolve "_expand_dbg" at ucrtbased.dll!0x00007FFF167F4830 to mimalloc!0x00007FFF19E05070 (0)
mimalloc-redirect: trace: resolve "_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F4C40 to mimalloc!0x00007FFF19E05030 (0)
mimalloc-redirect: trace: resolve "_msize_dbg" at ucrtbased.dll!0x00007FFF167F4A20 to mimalloc!0x00007FFF19E050B0 (0)
mimalloc-redirect: trace: resolve "_aligned_malloc_dbg" at ucrtbased.dll!0x00007FFF167F3C00 to mimalloc!0x00007FFF19E051C0 (0)
mimalloc-redirect: trace: resolve "_aligned_realloc_dbg" at ucrtbased.dll!0x00007FFF167F46E0 to mimalloc!0x00007FFF19E05200 (0)
mimalloc-redirect: trace: resolve "_aligned_free_dbg" at ucrtbased.dll!0x00007FFF167F3B10 to mimalloc!0x00007FFF16FAA5CD (0)
mimalloc-redirect: trace: resolve "_aligned_msize_dbg" at ucrtbased.dll!0x00007FFF167F3C50 to mimalloc!0x00007FFF19E05190 (0)
mimalloc-redirect: trace: resolve "_aligned_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F4730 to mimalloc!0x00007FFF19E05240 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_malloc_dbg" at ucrtbased.dll!0x00007FFF167F3E20 to mimalloc!0x00007FFF19E05290 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_realloc_dbg" at ucrtbased.dll!0x00007FFF167F4110 to mimalloc!0x00007FFF19E052D0 (0)
mimalloc-redirect: trace: resolve "_aligned_offset_recalloc_dbg" at ucrtbased.dll!0x00007FFF167F45C0 to mimalloc!0x00007FFF19E05320 (0)
mimalloc-redirect: trace: module "C:\Windows\SYSTEM32\bcrypt.dll"
mimalloc-redirect: trace: standard malloc is redirected
heap stats:    peak      total      freed    current       unit      count
    normal:      0          0          0          0                            ok
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:      0          0          0          0                            ok
malloc req:      0          0          0          0                            ok

  reserved:      0          0          0          0                            ok
 committed:      0          0          0          0                            ok
     reset:      0          0          0          0                            ok
   touched:      0          0          0          0                            ok
  segments:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:      0          0          0          0                            ok
-abandoned:      0          0          0          0                            ok
 -extended:      0
 -noretire:      0
     mmaps:      0
   commits:      0
   threads:      0          0          0          0                            ok
  searches:     0.0 avg
numa nodes:       1
   elapsed:       1.626 s
   process: user: 0.140 s, system: 0.281 s, faults: 1804, rss: 6.7 MiB, commit: 5.7 MiB
heap stats:    peak      total      freed    current       unit      count
normal   1:    1.0 KiB    2.7 KiB    2.6 KiB     40 B        8 B      348      not all freed!
normal   4:    2.7 KiB    5.1 KiB    5.0 KiB     96 B       32 B      163      not all freed!
normal   6:    9.7 KiB   17.5 KiB    9.8 KiB    7.6 KiB     48 B      373      not all freed!
normal   8:    1.8 KiB    8.2 KiB    8.7 KiB   -448 B       64 B      132      ok
normal   9:    3.8 KiB   16.9 KiB   15.2 KiB    1.6 KiB     80 B      216      not all freed!
normal  10:    2.3 KiB   14.7 KiB   13.0 KiB    1.6 KiB     96 B      157      not all freed!
normal  11:    5.1 KiB   25.9 KiB   23.1 KiB    2.7 KiB    112 B      236      not all freed!
normal  12:    2.6 KiB   19.2 KiB   16.6 KiB    2.5 KiB    128 B      153      not all freed!
normal  13:   12.7 KiB   20.8 KiB   12.7 KiB    8.1 KiB    160 B      133      not all freed!
normal  14:    1.5 KiB    9.2 KiB    9.0 KiB    192 B      192 B       49      not all freed!
normal  15:    1.0 KiB    1.9 KiB   20.4 KiB  -18.4 KiB    224 B        9      ok
normal  16:    1.2 KiB    9.7 KiB    9.5 KiB    256 B      256 B       39      not all freed!
normal  17:   10.9 KiB   18.8 KiB   25.0 KiB   -6.2 KiB    320 B       60      ok
normal  18:    8.2 KiB   26.7 KiB   29.7 KiB   -3.0 KiB    384 B       71      ok
normal  19:    3.9 KiB  217.8 KiB  221.8 KiB   -3.9 KiB    448 B      496      ok
normal  20:    512 B     15.5 KiB   15.5 KiB      0        512 B       31      ok
normal  21:    5.6 KiB   24.4 KiB   25.0 KiB   -640 B      640 B       39      ok
normal  22:    1.5 KiB    5.2 KiB    5.2 KiB      0        768 B        7      ok
normal  24:    5.0 KiB   22.0 KiB   21.0 KiB    1.0 KiB    1.0 KiB     22      not all freed!
normal  25:    5.0 KiB   13.8 KiB   17.5 KiB   -3.7 KiB    1.2 KiB     11      ok
normal  28:   14.0 KiB   16.0 KiB   20.0 KiB   -4.0 KiB    2.0 KiB      8      ok
normal  29:   10.0 KiB   15.0 KiB   12.5 KiB    2.5 KiB    2.5 KiB      6      not all freed!
normal  30:    3.0 KiB    3.0 KiB    3.0 KiB      0        3.0 KiB      1      ok
normal  33:   10.0 KiB   20.0 KiB   15.0 KiB    5.0 KiB    5.0 KiB      4      not all freed!
normal  34:    6.0 KiB   12.0 KiB   12.0 KiB      0        6.0 KiB      2      ok
normal  37:   10.0 KiB   10.0 KiB      0       10.0 KiB   10.0 KiB      1      not all freed!

heap stats:    peak      total      freed    current       unit      count
    normal:  111.5 Ki   554.2 Ki   552.6 Ki     1.6 Ki     204 B      2.7 K    not all freed!
      huge:      0          0          0          0                            ok
     giant:      0          0          0          0                            ok
     total:  111.5 KiB  554.2 KiB  552.6 KiB    1.6 KiB                        not all freed!
malloc req:   98.2 KiB  509.5 KiB  510.2 KiB   -685 B                          ok

  reserved:  128.5 KiB  144.5 KiB   24.0 KiB  120.4 KiB                        not all freed!
 committed:   11.6 MiB   11.7 MiB   24.0 KiB   11.6 MiB                        not all freed!
     reset:      0          0          0          0                            ok
   touched:  142.3 KiB  148.8 KiB   78.7 KiB   70.1 KiB                        not all freed!
  segments:      3          3          3          0                            ok
-abandoned:      0          0          0          0                            ok
   -cached:      0          0          0          0                            ok
     pages:     13         15         14          1                            not all freed!
-abandoned:      0          0          0          0                            ok
 -extended:     37
 -noretire:    1.0 Ki
     mmaps:     18
   commits:    139
   threads:     16         18          3         15                            not all freed!
  searches:     0.5 avg
numa nodes:       1
   elapsed:      57.439 s
   process: user: 0.375 s, system: 0.937 s, faults: 15712, rss: 46.7 MiB, commit: 31.0 MiB
mimalloc: process done: 0xa072d6b000

Update: replace with correct logs

Hi @vlserov , how can you get the mimalloc-redirect trace log? Just set 'MIMALLOC_PATCH_IMPORTS=1'? Thanks! :)

pavelkumbrasev commented 1 year ago

Hi @daanx do you have any updates regarding this problem? Is there any updates from shell32 team?

daanx commented 1 year ago

Yes! I was able to contact the right people and they fixed the bugs (already quite a while ago). I am not sure if the fixes are already in some Windows update -- have you tried if it works yet?

pavelkumbrasev commented 1 year ago

It is still reproducing so we either need to update the Windows version or it fix is not released yet.