microsoft / microsoft/mimalloc

Crash when loading Python library into process that is redirecting to mimalloc

Open
#1,128 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

Hey, I have a host process that is using mimalloc without issue. As part of it's functionality, it loads python311.dll (Python 3.11) directly into it and uses the CPython API directly to interact with Python. I can see that python311.dll is correctly using mi_malloc() calls for it's allocations as well, so the redirects are working there too.

However, there is one Python module 'open3d' (https://www.open3d.org/) that causes a crash when it's loaded into the process (via Pythons import mechanism). The crash stack is:

        ntdll.dll!RtlReportCriticalFailure()	Unknown
 	ntdll.dll!RtlpHeapHandleError()	Unknown
 	ntdll.dll!RtlpHpHeapHandleError()	Unknown
 	ntdll.dll!RtlpLogHeapFailure()	Unknown
 	ntdll.dll!RtlFreeHeap()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbffd8deb8()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd0eeb62()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd0f6f89()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd0f460a()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd0e25df()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd0eb344()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd426265()	Unknown
 	pybind.cp311-win_amd64.pyd!00007ffbfd4260a6()	Unknown
 	python311.dll!00007ffc9ec37c7c()	Unknown
 	python311.dll!00007ffc9ec37e89()	Unknown

It seems to me that pybind.cp311-win_amd64.pyd is linked against the static CRT. Could this cause issues? If so, is there any best solution for loading binaries that use the static CRT while mimalloc is redirecting mallocs in the host process? In theory if the binaries are only allocating/freeing memory that they own I assume that should work, but I guess this isn't the case for Python.

Or alternatively, what is the best way to only use mimalloc for my own binaries and not any 3rd party ones? I guess I'd have to call mi_malloc directly in all my code?

I notice that Python 3.13 is compiled using mimalloc, but there is no open3d release for Python 3.13 yet, so I can't test how things are working in that case.

This crash occurs with both mimalloc 2.1.4 and 3.0.8. If set MIMALLOC_DISABLE_REDIRECT=1, then crash goes away. I've spent a fair amount of time trying the various debug techniques but no luck so far.

You can get a copy of the package from here;
https://files.pythonhosted.org/packages/a3/3c/358f1cc5b034dc6a785408b7aa7643e503229d890bcbc830cda9fce778b1/open3d-0.19.0-cp311-cp311-win_amd64.whl
just rename .whl to .zip to open it. The .pyd in question is in the open3d\cpu directory in the .zip

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the linked open3d-0.19.0 wheel and Python 3.11, comparing normal redirection with MIMALLOC_DISABLE_REDIRECT=1. Examine the pybind.cp311-win_amd64.pyd crash path and the CRT/allocator ownership involved; done means identifying the incompatibility or documenting a supported configuration for third-party binaries.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.