Skip to content

gh-115649: Fix double free for intern strings dict #120290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

aisk
Copy link
Contributor

@aisk aisk commented Jun 9, 2024

After #107272, all the sub-interpreters shares the same interned string dict from the main interpreter, but the unicode module's desctructor function for every interpreter will try to free the interned string dict, and this leads to the process crash. Still working on this.

PyDict_Clear(interned);
Py_DECREF(interned);
_Py_INTERP_CACHED_OBJECT(interp, interned_strings) = NULL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand the crash report correctly, the problem is that the interned dict is cleared for sub-interpreters when it is also shared between the main interpreter and sub-interpreters. This change means that PyDict_Clear() is never called, not even for the main interpreter. That seems like it will just leak everything in the dict.

I imagine, rather, that you'd put this code inside the block below that is guarded by the _Py_IsMainInterpreter() checl.

Copy link
Contributor Author

@aisk aisk Jun 9, 2024

Choose a reason for hiding this comment

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

Thanks for the review! Sorry, I put this PR too earlier, after some research I found that I was wrong, and the crash is caused by other place.

For now I can ensure that this line

PyUnicode_InternInPlace(&filename);
caused the crash. It will intern the file name for the _tkinter.so, and after the interned dict finalization, call free on this object will crash.

I guess maybe this unicode object is created in another interpreter, and intern it in the main interpreter will cause the error. But I'm not familiar with these code, and still working on it.

@aisk
Copy link
Contributor Author

aisk commented Jun 10, 2024

Closed by #120315

@aisk aisk closed this Jun 10, 2024
@aisk aisk deleted the double-free-intern-strings branch June 17, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants