Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Closed
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Crash report
What happened?
fromtypingimportUnionclassBaseNode: next: Union["BaseNode", None] =None@staticmethoddefadd(node: "BaseNode") ->None: ifBaseNode.nextisNone: BaseNode.next=nodereturncurrent=BaseNode.nextwhilecurrent.nextisnotNone: current=current.nextcurrent.next=node@staticmethoddefremove(node: "BaseNode") ->None: ifBaseNode.nextisNone: returncurrent=BaseNode.nextprev=BaseNodewhileTrue: ifcurrentisNone: returnifcurrent==node: ifcurrent.nextisnotNone: prev.next=current.nextelse: prev.next=Nonereturnprev=currentcurrent=current.nextclassNode(BaseNode): def__init__(self) ->None: self.next=NoneBaseNode.add(self) def__del__(self) ->None: BaseNode.remove(self) defmain() ->None: Node() Node() if__name__=="__main__": main()(Edited by @ZeroIntensity) Shortened repro:
classBaseNode: next=NoneclassNode(BaseNode): def__init__(self) ->None: ifBaseNode.nextisNone: BaseNode.next=selfreturnBaseNode.next.next=selfdef__del__(self) ->None: BaseNode.next=BaseNode.next.nextNode() Node()(Edited by @fxeqxmulfx) Use after free example:
classBaseNode: def__del__(self): print("next", BaseNode.next) print("del", self) BaseNode.next=BaseNode() BaseNode.next.next=BaseNode()next <__main__.BaseNode object at 0x717fb2d23a10> del <__main__.BaseNode object at 0x717fb2d23a10> next <__main__.BaseNode object at 0x717fb2d23a10> use after free del <__main__.BaseNode object at 0x717fb2d23a50> CPython versions tested on:
3.14
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0b2 (main, Jun 12 2025, 12:41:01) [Clang 20.1.4 ]
Linked PRs
- gh-135552: Clear weakrefs to types in GC after garbage finalization not before #135728
- gh-135552: Skip clearing of tp_subclasses weakrefs in GC #136147
- gh-135552: Don't clear weakref if wr_object is a type. #136151
- gh-135552: Make the GC clear weakrefs later #136189
- gh-135552: Add tests that check if weakref for tp_subclasses cleared after finalization #136304
efimov-mikhail, jelebruh and jayofdoom
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump