Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

mingw64: Python pmapi on Windows - prevent crash when free()'ing resources #42

Merged
merged 1 commit into from Aug 21, 2015

Conversation

Projects
None yet
2 participants
Contributor

dgiagio commented Aug 20, 2015

When calling Python pmapi functions such as pmGetChildren, pmGetInDom, etc. these functions internally allocate resources using malloc. Unfortunately the current code on Windows crashes when free'ing these resources because the free function used doesn't always belong to the correct msvcrt.dll version.

AFAIK artifacts (.exe's, .dll's, etc) compiled using mingw64 are always linked with \Windows\System32\msvcrt.dll, but Python is not necessarily. E.g:

C:\>\Python27\python
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import CDLL
>>> from ctypes.util import find_library
>>> LIBC_OK = CDLL(find_library("msvcrt"))
>>> LIBC_ERR = CDLL(find_library("c"))
>>> LIBC_OK
<CDLL 'C:\Windows\system32\msvcrt.dll', handle cdc40000 at 1db5e80>
>>> LIBC_ERR
<CDLL 'msvcr90.dll', handle 65a70000 at 1e61d68>
>>>

That means that libpcp.dll (used by pmapi Python module) is using the malloc function from msvcrt.dll while Python is using the free function from msvcrt90.dll and thus it crashes.

This fix ensures that if we're on Windows platform, we always use msvcrt.dll. On other platforms it's unchanged and keeps using the platform's libc.

@natoscott natoscott merged commit b1b7f18 into performancecopilot:master Aug 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment