rt-thread icon indicating copy to clipboard operation
rt-thread copied to clipboard

[Bug] dfs_v2打开pagecache,运行elf后会存在memleak

Open wycwyhwyq opened this issue 11 months ago • 5 comments

RT-Thread Version

53bd56ccf9cb77dd1cec3c3c9e1fde24b0a95267

Hardware Type/Architectures

risc-v/K230

Develop Toolchain

GCC

Describe the bug

  1. dfs_v2打开pagecache,运行任意elf后,通过free对比运行前后发现存在memleak

Other additional context

定位到具体位置有两处:

  1. 加载elf文件时对应的struct dfs_file *file结构未释放,原因为elf map时会增加file->ref_count,导致执行close->fd_release->fdt_fd_releasefile->ref_count不等于1,未能正常释放
  2. 用户程序退出时会执行lwp_exit->_clear_child_tid->sys_futex,此处是个share futex,不会被删除

对于share futex,还有一个疑问,对于没有进程使用的futex似乎没有删除操作?

wycwyhwyq avatar Jan 09 '25 11:01 wycwyhwyq

share futex 设计时有 lazy 任务定期清理。不过由于 libc 的设计算法,整个系统生命周期中它的 footpirnt 基本上和 tick 形成 O(1) 增长关系。所以这个研发任务定为”必要不紧急“。因为重要任务很多,所以搁置了。如果题主有兴趣可以 PR 补充。

polarvid avatar Jan 10 '25 01:01 polarvid

share futex 设计时有 lazy 任务定期清理。不过由于 libc 的设计算法,整个系统生命周期中它的 footpirnt 基本上和 tick 形成 O(1) 增长关系。所以这个研发任务定为”必要不紧急“。因为重要任务很多,所以搁置了。如果题主有兴趣可以 PR 补充。

是否可以简单展开说明下?

BernardXiong avatar Jan 12 '25 08:01 BernardXiong

确实存在内存泄漏

  1. 打印执行文件时创建的file指针 image

  2. 打印rt_free的指针 image

  3. 在程序退出时输出的日志中查找file指针,只有一条 image

heyuanjie87 avatar Jan 14 '25 09:01 heyuanjie87

关联:https://github.com/RT-Thread/rt-thread/pull/9917

Rbb666 avatar Jan 17 '25 02:01 Rbb666

@wycwyhwyq https://github.com/RT-Thread/rt-thread/pull/9917 已合并,可以再测试下

Rbb666 avatar Feb 09 '25 07:02 Rbb666