Skip to content

[3.15] gh-159285: Fix crash when copying an empty dict fails with MemoryError (GH-159286) - #159287

Merged
methane merged 2 commits into
python:3.15from
miss-islington:backport-f9132f1-3.15
Oct 13, 2026
Merged

methane merged 2 commits into
python:3.15from
miss-islington:backport-f9132f1-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

copy_lock_held_untracked() asserted that the new empty dict was not
tracked by the GC without checking whether its allocation had failed,
so a debug build dereferenced NULL instead of raising MemoryError. This
affected dict.copy(), PyDict_Copy() and _PyDict_CopyAsDict(), which
type() uses for the class namespace.
(cherry picked from commit f9132f1)

Co-authored-by: Christian Aurich Zanettini Martins christian.aurichzm@gmail.com

…ryError (pythonGH-159286)

copy_lock_held_untracked() asserted that the new empty dict was not
tracked by the GC without checking whether its allocation had failed,
so a debug build dereferenced NULL instead of raising MemoryError. This
affected dict.copy(), PyDict_Copy() and _PyDict_CopyAsDict(), which
type() uses for the class namespace.
(cherry picked from commit f9132f1)

Co-authored-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Comment thread Lib/test/test_dict.py Outdated
@methane
methane merged commit cc00fe4 into python:3.15 Oct 13, 2026
54 checks passed
@miss-islington
miss-islington deleted the backport-f9132f1-3.15 branch October 13, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants