weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy
未关闭
还没有人认领这个 Issue。
extension-modules
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 weakrefobject.c 开始,并在 CPython main 构建上运行提供的 refcount reproducer。检查报告中描述的二元、三元和比较操作路径;当 dead-proxy 情况不再泄漏引用(包括重复运行 reproducer 的循环)时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100