Skip to content

Conversation

@phsilva
Copy link
Contributor

@phsilva phsilva commented Apr 1, 2020

Changes on 7dd549e made _functools compatible with
PEP-489 and we could have multiple modules instances loaded.

But, right now there is no way to make kwd_mark global into
a per module instance variable. kwd_mark is used on lru_cache_new
which does not have a reference to a PyModule*, necessary to use
PyModule_GetState.

PEP-573 will solve this problem and will allow us to move the global
state to per-module data and properly clear the state when unloading
a module instance.

This change temporarily disable cleaning of kwd_mark to avoid NULL
pointer dereference if we clear kwd_mark and other module instances
still alive use it.

https://bugs.python.org/issue40071

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is not correct. The bug is not "double free": Py_CLEAR(NULL) does NULL, that's fine. The problem is if one module instance is deallocated, kwd_mark is cleared to NULL. Other instances will use NULL and so crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased the comment and updated commit message. Thanks for getting it.

Changes on 7dd549e made _functools compatible with
PEP-489 and we could have multiple modules instances loaded.

But, right now there is no way to make `kwd_mark` global into
a per module instance variable. kwd_mark is used on lru_cache_new
which does not have a reference to a PyModule*, necessary to use
PyModule_GetState.

PEP-573 will solve this problem and will allow us to move the global
state to per-module data and properly clear the state when unloading
a module instance.

This change temporarily disable cleaning of kwd_mark to avoid NULL
pointer dereference if we clear kwd_mark and other module instances
still alive use it.

wip
@phsilva phsilva force-pushed the bpo-40071-fix-crash branch from a6ab03d to eb807ad Compare April 1, 2020 14:44
@vstinner vstinner merged commit eacc074 into python:master Apr 1, 2020
@phsilva phsilva deleted the bpo-40071-fix-crash branch April 3, 2020 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants