Skip to content

MemoryError freelist is not thread-safe in free threaded build #129668

Closed

Description

@colesbury

Bug report

The MemoryError freelist isn't thread-safe if the GIL is disabled:

cpython/Objects/exceptions.c

Lines 3850 to 3860 in 285c1c4

/* Fetch object from freelist and revive it */
self = state->memerrors_freelist;
self->args = PyTuple_New(0);
/* This shouldn't happen since the empty tuple is persistent */
if (self->args == NULL) {
return NULL;
}
state->memerrors_freelist = (PyBaseExceptionObject *) self->dict;
state->memerrors_numfree--;

Most of the freelists were made thread-safe by making them per-thread in the free threaded build (using pycore_freelist.h), but we don't want to do that for MemoryError because its freelist serves a different purpose (it's not really for performance). I think we should just use a lock for MemoryError's freelist.

Linked PRs

Activity

  1. added a commit that references this issue on Feb 4, 2025
  2. self-assigned this
    on Feb 5, 2025
  3. added 4 commits that reference this issue on Feb 5, 2025
  4. added 2 commits that reference this issue on Feb 6, 2025
  5. added a commit that references this issue on Feb 7, 2025
  6. added a commit that references this issue on Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixes3.14bugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions