Skip to content

[3.15] gh-159739: Preserve ctypes base metadata when cloning fails (GH-160174) - #160293

Merged
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-7c87319-3.15
Oct 22, 2026
Merged

JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-7c87319-3.15

Conversation

@miss-islington

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

Copy link
Copy Markdown
Contributor

When creating a ctypes structure subclass, cloning its layout initially copied pointers to buffers owned by the base class. If a later allocation failed, cleaning up the subclass could free those buffers, leaving the base with invalid metadata and potentially causing a crash. Detach the owned pointers until their copies have been allocated. Backport to 3.15 and 3.14.
(cherry picked from commit 7c87319)

Co-authored-by: Jelle Zijlstra jelle@openai.com

…thonGH-160174)

When creating a ctypes structure subclass, cloning its layout initially copied pointers to buffers owned by the base class. If a later allocation failed, cleaning up the subclass could free those buffers, leaving the base with invalid metadata and potentially causing a crash. Detach the owned pointers until their copies have been allocated. Backport to 3.15 and 3.14.
(cherry picked from commit 7c87319)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
@JelleZijlstra
JelleZijlstra merged commit d4d2c53 into python:3.15 Oct 22, 2026
56 checks passed
@miss-islington
miss-islington deleted the backport-7c87319-3.15 branch October 22, 2026 22:21
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