[issue15578] Crash when modifying sys.modules during import

Eric Snow report at bugs.python.org
Sat Aug 18 07:59:46 CEST 2012


Eric Snow added the comment:

Here's the deal.  import_module_level() gets called for v1 from sa (where "globals" comes from). In that function it first calls get_parent(), which returns a borrowed reference to the sa module object. Then that parent object is passed to load_next() where the actual load of v1 will take place (and the segfault happens).

The problem is that get_parent() returns a borrowed reference.  When the sa module is replaced in sys.modules, the old sa module is decref'ed.  That's fine except load_next is using that same module as the parent.  Enter segfault, stage left.

Here's a quick patch that fixes the failure (along with a test).

----------
keywords: +patch
nosy: +brett.cannon, eric.snow
stage:  -> patch review
Added file: http://bugs.python.org/file26883/eric.snow_issue15578.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15578>
_______________________________________


More information about the Python-bugs-list mailing list