GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115649: Fix double free for intern strings dict by aisk · Pull Request #120290 · python/cpython

Conversation

@aisk

@aisk aisk commented Jun 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Legacy-mode subinterpreters in Python 3.12: import _tkinter leads to shutdown crash  #115649

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aisk
Only clear interned dict for main interpreter
54917cd
@bedevere-app bedevere-app Bot mentioned this pull request Jun 9, 2024
Legacy-mode subinterpreters in Python 3.12: import _tkinter leads to shutdown crash #115649
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jun 9, 2024
@aisk aisk added skip news needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Jun 9, 2024
@aisk
aisk marked this pull request as draft June 9, 2024 13:52
@bedevere-app bedevere-app Bot removed the awaiting review label Jun 9, 2024
jeremyhylton
jeremyhylton reviewed Jun 9, 2024
View reviewed changes
Comment thread Objects/unicodeobject.c
PyDict_Clear(interned);
Py_DECREF(interned);
_Py_INTERP_CACHED_OBJECT(interp, interned_strings) = NULL;
}

@jeremyhylton jeremyhylton Jun 9, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@aisk aisk Jun 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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

cpython/Python/import.c

Line 1973 in 34f5ae6

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aisk

aisk commented Jun 10, 2024

Copy link
Copy Markdown
Member Author

Closed by #120315

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

@jeremyhylton jeremyhylton jeremyhylton left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@aisk @jeremyhylton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.