Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/net/sal/socket/net_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
}

d = fd_get(fd);
if(d)
if (d)
{
#ifdef RT_USING_DFS_V2
d->fops = dfs_net_get_fops();
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions components/net/utest/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
37 changes: 37 additions & 0 deletions components/net/utest/tc_sal_socket_failure.c
Original file line number Diff line number Diff line change
@@ -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);