Skip to content

Instantly share code, notes, and snippets.

@devdanzin
Created March 18, 2026 10:06
Show Gist options
  • Select an option

  • Save devdanzin/432d9af1a8833bef53bc9ae342310622 to your computer and use it in GitHub Desktop.

Select an option

Save devdanzin/432d9af1a8833bef53bc9ae342310622 to your computer and use it in GitHub Desktop.
import.c: Wrong interpreter on return + double lock release

import.c: Wrong interpreter on return + double lock release

Summary

Two critical bugs in the import system:

  1. import_run_extension (line 2189): After switching to main interpreter, _PyUnicode_Copy failure does return NULL instead of goto main_finally. Code resumes on wrong interpreter → crashes/corruption.
  2. _PyImport_LoadLazyImportTstate (line 3931): _PyImport_ReleaseLock called before goto error, then error path releases again → Py_FatalError("unlocking a recursive mutex not owned by current thread").

Fix

  1. Change return NULL at line 2189 to rc = -1; goto main_finally;.
  2. Remove _PyImport_ReleaseLock(interp) at line 3931.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment