weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee
Summary
When first
UNWRAP(x)succeeds but secondUNWRAP(y)fails (dead proxy),x's new reference is leaked. Affects ~20 binary operators (+, -, *, /, |, &, ^, etc.).Reproducer
import weakref, sys, gc class C: def __add__(self, other): return NotImplemented def __radd__(self, other): return NotImplemented obj = type('D', (), {})() dead = weakref.proxy(obj) del obj; gc.collect() live_obj = C() live = weakref.proxy(live_obj) before = sys.gettotalrefcount() for i in range(10000): try: live + dead except ReferenceError: pass after = sys.gettotalrefcount() print(f"Leaked {after - before} refs (~{(after-before)//10000}/call)")
Actually, ternary, or comparison operations have the same problem.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-153059
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in weakrefobject.c ed esegui il refcount reproducer fornito su una build main di CPython. Controlla i percorsi delle operazioni binarie, ternarie e di confronto descritti nel report; il lavoro è completato quando i casi di dead-proxy non perdono più riferimenti, incluso il loop ripetuto del reproducer.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100