Author htgoebel
Recipients htgoebel
Date 2017-09-20.14:38:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
When using


near the beginning of a program, Py_SetPath crashes with memory corruption if run on a systems with glibc's MALLOC_CHECK enabled.

The reason is: Py_GetPath and Py_SetPath use different memory interfaces.

* Py_GetPath() calls calculate_path(), which uses PyMem_New() to allocate the memory (see, assigned to `buf` first)

* But Py_SetPath() uses PyMem_RawFree() to free the memory (see

This error DOES NOT occur on Windows, since for win32 there is a separate implementation, which uses PyMem_RawMalloc (see

This error also DOES NOT occur in Python <= 3.5, since PYMEM_FUNCS have been the same as PYRAW_FUNCS (see This was changed in v3.6.0: PYMEM_FUNCS now is PYOBJ_FUNCS, see

This error only occurs when running on a system with glibc's MALLOC_CHECK enabled, which seems to be the default st least on CentOS, Fedora and ArchLinux.

Example code and relevant source see below.

Example stack trace

*** glibc detected *** ./dist/jcollect3: double free or corruption (out): 0x00007fde271ab030 ***
======= Backtrace: =========
======= Memory map: ========

How to reproduce

An example for this problem is the bootloader of PyInstaller (as of 2017-08-01).

* Make sure you are running on a Linux distribution having glibc's MALLOC_CHECK enabled.

* Set up a virtual environment (just too keep your system clean)

pip install
echo 'print("Hello")' >
dist/test/test  # run the frozen script

The relevant source of PyInstaller's bootloader is at <>
Date User Action Args
2017-09-20 14:38:42htgoebelsetrecipients: + htgoebel
2017-09-20 14:38:42htgoebelsetmessageid: <>
2017-09-20 14:38:42htgoebellinkissue31532 messages
2017-09-20 14:38:42htgoebelcreate