Repository navigation
[dfs][ptyfs] 注销 pts 时释放文件对象 - #12055
cms19859230182-lang wants to merge 1 commit into
Conversation
Fix RT-Thread#12023 In ptyfs_unregister_pts(), when a pts file is removed from the root directory list and its ptsno is returned to the bitmap pool, the allocated struct ptyfs_file was not freed, resulting in a kernel memory leak on every ptmx close. Free pts_file via rt_free() after safely detaching it from the superblock root list and returning the ptsno.
|
在 中补齐了对 的 ,避免反复注销 pts 时泄漏内核内存。 |
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-14 19:04 CST)
📝 Review Instructions
|
|
Rbb666
left a comment
There was a problem hiding this comment.
审查基于当前提交 8a1186a2。
该问题已由 #12029 修复,并于 2026-11-16 合入 master,建议将 #12055 作为重复 PR 关闭。
#12029 除了释放 struct ptyfs_file,还增加了查找结果的引用计数、目录遍历的锁保护,并修复了 PTS 分配失败时的清理路径。
本 PR 仅在 ptyfs_unregister_pts() 中增加 rt_free(pts_file),仍有并发 use-after-free 风险:ptyfile_lookup() 返回前已经释放 sb->lock,而 ptyfs_ops_setattr() 随后仍会访问该对象;若另一线程此时关闭 master 并触发注销,就可能访问已释放的内存。getdents 的无锁遍历也存在同类风险。#12029 已包含所需的生命周期保护,无需再合入此单行修复。
Reviewed commit: 8a1186a2.
This issue was fixed by #12029, merged into master on 2026-11-16. Please close #12055 as a duplicate.
In addition to freeing struct ptyfs_file, #12029 adds references for lookup results, protects directory iteration with a lock, and fixes cleanup on PTS allocation failures.
The standalone rt_free(pts_file) in this PR introduces a concurrent use-after-free risk: ptyfile_lookup() releases sb->lock before returning, while ptyfs_ops_setattr() subsequently accesses the object. A concurrent master close can unregister and free it in between. Unlocked getdents iteration has the same lifetime problem. The required protection is already included in #12029.
|
哦哦已经修了啊,那我好像白忙活了哈哈哈 |
注销 pts 的时候会把以前的文件对象释放掉,反复开关会漏内存
现在直接改成关掉就释放的版本
修 #12023