RT-Thread / RT-Thread/rt-thread
[Bug] SDIO 驱动注销失败与节点内存泄漏风险
Open
@Huoyanlifusu is already working on this.
Since Sep 15, 2026.
bug
Component
component: drivers
in progress
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
RT-Thread Version
master e538ad76e475ba6026e563a9c605b58a1f2f9cc0
Affected area
Device drivers
Hardware/BSP vendor
Not applicable / Other
Architecture
Not applicable / Other
Board and hardware details
无特定版型要求
Develop Toolchain
GCC
Describe the bug
尽管多数 sdio 设备(比如 mmc/sd卡)不会热插拔,出于代码稳定角度考虑,建议进行这几处优化。
- 系统加载多个 sdio 驱动,在卸载驱动时,链表未及时退出,
sd可能会被下一轮循环覆盖为NULL
for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
{
sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
if (sd->drv != driver)
{
sd = RT_NULL;
}
}
- 目前释放
sd指针动作在软件找到卡后才进行,有内存泄漏风险,这个指针的申请动作不依赖 SDIO 卡,因此释放也不需要依赖 SDIO 卡匹配到与否。
if (card != RT_NULL)
{
driver->remove(card);
rt_list_remove(&sd->list);
rt_free(sd);
}
- 可选优化:使用 rt_list_for_each_entry 替代 rt_list_entry + for 的写法
Other additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.