You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash when importing an extension after Py_Initialize, Py_Finalize and Py_Initialize #53443
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/abalkin'closed_at=<Date2011-02-28.01:15:21.385>created_at=<Date2010-07-08.08:50:50.638>labels= ['OS-mac', 'type-crash']
title='Crash when importing an extension after Py_Initialize, Py_Finalize and Py_Initialize'updated_at=<Date2011-02-28.01:15:21.383>user='https://bugs.python.org/mpalluat'
I reproduce the problem on Linux (./configure --enable-shared), after I modified the source code a bit to directly use Python.h and to link with libpython3.2.so (no call to dlopen). In gdb the stack trace has exactly the same symbols as the attached crash log, so the issue is not specific to Mac frameworks.
The crash is inside _PyImport_LoadDynamicModule("_pickle"), when _PyImport_FixupExtension() calls Py_DECREF(def->m_base.m_copy), this certainly frees objects allocated in a previous incarnation of the interpreter, and segfaults in type_dealloc(): _PyObject_GC_UNTRACK(type).
Inimport.c::_PyImport_FixupExtension(), thePy_DECREFisprecededbyacomment: """ /* Somebody already imported the module, likely under a different name. XXX this should really not happen. */Py_DECREF(def->m_base.m_copy);
"""
Iremovedthisstatement, andtheprogramnowrunscorrectly. Idon't know about memory leaks though...
The cleanup of the interpreter state in Py_Finalize doesn't clean up all state when m_copy refers to a version from a previous instance of the interpreter.
Maybe the tp_dealloc of a module object clean up m_copy? I don't know enough of this code and its intended behavior to know if that would be a valid change.
changed the title [-]subprocess module causing crash[/-][+]Crash when importer an extension after Py_Initialize, Py_Finalize and Py_Initialize[/+]on Jul 24, 2010
changed the title [-]Crash when importer an extension after Py_Initialize, Py_Finalize and Py_Initialize[/-][+]Crash when importing an extension after Py_Initialize, Py_Finalize and Py_Initialize[/+]on Jan 31, 2011
Activity
mpalluat commentedon Jul 8, 2010
there is a crash log inside the archive
ronaldoussoren commentedon Jul 8, 2010
The title is somewhat misleading, this is a C program that uses dlopen to load the python framework.
I will look into this, but it is just as likely that code that loads or uses the python framework has a problem.
mpalluat commentedon Jul 8, 2010
Hi Ronald,
Thank you for looking into it, and sorry for the misleading title.
You will find a crash log and some instructions on how to reproduce the problem inside the archive.
Thanks,
Marc
On 8 Jul 2010, at 10:18, Ronald Oussoren wrote:
Ronald Oussoren <ronaldoussoren@mac.com<mailto:ronaldoussoren@mac.com>> added the comment:
The title is somewhat misleading, this is a C program that uses dlopen to load the python framework.
I will look into this, but it is just as likely that code that loads or uses the python framework has a problem.
----------
Python tracker <report@bugs.python.org<mailto:report@bugs.python.org>>
<http://bugs.python.org/issue9197\>
Marc Palluat de Besset
Mac Software Engineer
email : marc.palluatdebesset@sophos.com<mailto:marc.palluatdebesset@sophos.com>
tel : +44 1235 544056
loc : E2 floor 2
SOPHOS - simply secure
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 348 3873 20.
amauryfa commentedon Jul 8, 2010
I reproduce the problem on Linux (./configure --enable-shared), after I modified the source code a bit to directly use Python.h and to link with libpython3.2.so (no call to dlopen). In gdb the stack trace has exactly the same symbols as the attached crash log, so the issue is not specific to Mac frameworks.
The crash is inside _PyImport_LoadDynamicModule("_pickle"), when _PyImport_FixupExtension() calls Py_DECREF(def->m_base.m_copy), this certainly frees objects allocated in a previous incarnation of the interpreter, and segfaults in type_dealloc(): _PyObject_GC_UNTRACK(type).
ronaldoussoren commentedon Jul 8, 2010
Removing the call to Py_DECREF is fishy.
The cleanup of the interpreter state in Py_Finalize doesn't clean up all state when m_copy refers to a version from a previous instance of the interpreter.
Maybe the tp_dealloc of a module object clean up m_copy? I don't know enough of this code and its intended behavior to know if that would be a valid change.
amauryfa commentedon Jul 8, 2010
We definitely need unit tests about embedded python interpreter, I think there are none.
ronaldoussoren commentedon Jul 11, 2010
Unassigning, this is not mac-specific and I don't plan to work on this in the near future.
ronaldoussoren commentedon Jul 24, 2010
(changing subject to better tell what this issue is about)
[-]subprocess module causing crash[/-][+]Crash when importer an extension after Py_Initialize, Py_Finalize and Py_Initialize[/+]abalkin commentedon Jan 31, 2011
Amaury,
Can you post your Linux code reproducing the issue? I would like to take a look, but don't want to dig through an XCode project.
[-]Crash when importer an extension after Py_Initialize, Py_Finalize and Py_Initialize[/-][+]Crash when importing an extension after Py_Initialize, Py_Finalize and Py_Initialize[/+]amauryfa commentedon Jan 31, 2011
Here are the files I used to reproduce the crash.
See "build.sh" for the build command, there may be better ways...
amauryfa commentedon Feb 27, 2011
Does the patch for bpo-11321 fix this issue?
ncoghlan commentedon Feb 28, 2011
Merging this into bpo-11321 since that relates to the same underlying problem and includes a simpler test case.