pcp
[Top] [All Lists]

[pcp] mingw64: Python pmapi on Windows - prevent crash when free()'ing r

To: performancecopilot/pcp <pcp@xxxxxxxxxxxxxxxxxx>
Subject: [pcp] mingw64: Python pmapi on Windows - prevent crash when free()'ing resources (#42)
From: Diego Giagio <notifications@xxxxxxxxxx>
Date: Thu, 20 Aug 2015 16:19:11 -0700
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha1; c=relaxed; d=github.com; h=from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:list-id:list-archive:list-post:list-unsubscribe; s=s20150108; bh=WtQ4yrkWIFOuQoJI2s3EHViRSIU=; b=IW52Tw9srHlbSwLz QdG0fLuLmHs2tjID5691huCGGTYeiThdNokwgERfweiTWTapTJ3xAQ4ODftJptN0 UH1epoWr6NijvjXlMen+uexEMb173v8kz9aXLMK0xg/a1U6MDrhUon0S+yaOb2Jt QHp93pYOXqWHhOaN/JEAP0NF4I0=
List-archive: https://github.com/performancecopilot/pcp
List-id: performancecopilot/pcp <pcp.performancecopilot.github.com>
List-post: <mailto:reply+00bd08b6ca49037a42606963139ad053320a2a4cbbc74e3d92cf0000000111ee226f92a169ce061859ee@reply.github.com>
List-unsubscribe: <mailto:unsub+00bd08b6ca49037a42606963139ad053320a2a4cbbc74e3d92cf0000000111ee226f92a169ce061859ee@reply.github.com>, <https://github.com/notifications/unsubscribe/AL0Ithrj2i_9FW2e3bNWi7FHzdW1pgWGks5oplfvgaJpZM4FviXa>
Reply-to: performancecopilot/pcp <reply+00bd08b6ca49037a42606963139ad053320a2a4cbbc74e3d92cf0000000111ee226f92a169ce061859ee@xxxxxxxxxxxxxxxx>

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.


You can view, comment on, or merge this pull request online at:

  https://github.com/performancecopilot/pcp/pull/42

Commit Summary

  • mingw64: Python pmapi on Windows - prevent crash when free'ing resources

File Changes

Patch Links:


Reply to this email directly or view it on GitHub.

<Prev in Thread] Current Thread [Next in Thread>