[net][sal] Free DFS v2 vnode when socket creation fails - #11760
Conversation
When sal_socket() rejects a request, DFS v2 descriptor cleanup destroys the dfs_file but leaves its separately allocated vnode behind. Destroy the vnode before releasing the failed descriptor and add a regression test that verifies repeated failures do not consume heap. Fixes RT-Thread#11710 Assisted-by: OpenAI Codex:GPT-5
|
👋 感谢您对 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-08-27 16:48 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Pull request overview
Fixes a DFS v2 vnode leak when SAL socket creation fails.
修复 SAL 套接字创建失败时 DFS v2 的 vnode 泄漏。
Changes:
- Explicitly destroys and clears the failed socket’s vnode.
- Adds a focused heap-leak regression test.
- Enables the test for DFS v2 POSIX SAL builds.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
components/net/sal/socket/net_sockets.c |
Cleans up vnode on failure. |
components/net/utest/tc_sal_socket_failure.c |
Tests repeated failure cleanup. |
components/net/utest/SConscript |
Registers the regression test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
With DFS v2,
socket()allocates adfs_fileand a separatedfs_vnodebefore callingsal_socket(). Ifsal_socket()fails,fd_release()destroys only thedfs_file, so every failed call leaks one vnode.On the simulator, 32 repeated invalid-domain calls increased heap use from 2568 to 7944 bytes before this change, a 5376-byte leak.
Fixes #11710.
你的解决方案是什么 (what is your solution)
Destroy the initialized vnode with
dfs_vnode_destroy()before releasing the failed descriptor, and cleard->vnodeto avoid leaving a stale pointer. The cleanup is guarded byRT_USING_DFS_V2, so DFS v1 keeps its existing descriptor-owned cleanup path.Add a focused Utest case that warms up the descriptor/SAL tables, repeats the failure 32 times, and verifies that heap use does not increase. After the fix, heap use remained 2400 bytes before and after the loop.
AI assistance: OpenAI Codex:GPT-5 assisted with issue research, implementation, and test preparation. The submitted diff and test results were reviewed locally.
请提供验证的bsp和config (provide the config and bsp)
BSP:
bsp/simulator.config:
CONFIG_RT_USING_DFS_V2=yCONFIG_SAL_USING_POSIX=yCONFIG_RT_USING_UTEST=yCONFIG_RT_USING_UTESTCASES=yCONFIG_RT_UTEST_TC_USING_SAL=yTests:
python -m SCons -j4— passed.components.net.sal.socket_failure_cleanup— failed before the fix (2568 -> 7944bytes), passed after the fix (2400 -> 2400bytes).python -m SCons -j1 build\kernel\components\net\sal\socket\net_sockets.obj— passed.python tools/ci/clang_format_check.py --repo https://github.com/RT-Thread/rt-thread --branch master --clang-format-executable clang-format— passed.git diff upstream/master..HEAD --check— passed.Environment note: the repository's full default MSVC simulator build stops in unchanged
drivers/board.c:87because of an existing command-export macro error; the affected DFS v1 object compiles successfully when targeted directly.action: N/A — no workflow run was created on the fork branch; local build and test results are listed above.
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up