[net][sal] Free DFS v2 vnode when socket creation fails

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 #11710

Assisted-by: OpenAI Codex:GPT-5
This commit is contained in:
wyf-777
2026-09-01 09:05:36 +08:00
committed by Rbb666
parent 21e6f363a4
commit cfba23f4d1
3 changed files with 44 additions and 0 deletions
+4
View File
@@ -670,6 +670,10 @@ int socket(int domain, int type, int protocol)
}
else
{
#ifdef RT_USING_DFS_V2
dfs_vnode_destroy(d->vnode);
d->vnode = RT_NULL;
#endif
/* release fd */
fd_release(fd);
rt_set_errno(-ENOMEM);
+3
View File
@@ -17,6 +17,9 @@ if GetDepend('RT_UTEST_TC_USING_SAL'):
# Add sal test source if enabled
src += ['tc_sal_socket.c']
if GetDepend(['RT_USING_DFS_V2', 'SAL_USING_POSIX']):
src += ['tc_sal_socket_failure.c']
# Define the test group with proper dependencies
group = DefineGroup('utestcases', src, depend = [''], CPPPATH = CPPPATH)
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <rtthread.h>
#include <sys/socket.h>
#include "utest.h"
static void TC_sal_socket_failure_cleanup(void)
{
rt_size_t used_before;
rt_size_t used_after;
int i;
/* Warm up the descriptor and SAL tables before measuring the heap. */
uassert_int_equal(socket(-1, SOCK_STREAM, 0), -1);
rt_memory_info(RT_NULL, &used_before, RT_NULL);
for (i = 0; i < 32; i++)
{
uassert_int_equal(socket(-1, SOCK_STREAM, 0), -1);
}
rt_memory_info(RT_NULL, &used_after, RT_NULL);
LOG_I("heap used before: %lu, after: %lu",
(unsigned long)used_before, (unsigned long)used_after);
uassert_int_equal(used_after, used_before);
}
static void utest_do_tc(void)
{
UTEST_UNIT_RUN(TC_sal_socket_failure_cleanup);
}
UTEST_TC_EXPORT(utest_do_tc, "components.net.sal.socket_failure_cleanup", RT_NULL, RT_NULL, 5);