Skip to content

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

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

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

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 enabled auto-merge (squash) October 22, 2026 22:21
@JelleZijlstra
JelleZijlstra merged commit 7d3d213 into python:3.14 Oct 22, 2026
51 checks passed
@miss-islington
miss-islington deleted the backport-7c87319-3.14 branch October 22, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants